paskvilwiki

up: video & PDF

ffmpeg

last updated 2019-09

ffmpeg is probably the most versatile encoder/transcoder for video and audio. it supports every format there is, and some of those that do not exist ;-)

rip DVD into FLV (or anything else)

this is trivial, just a few parameters need tweaking, and if you wanna use mp3 for your FLV, you either wanna compile ffmpeg by hand, or - in Ubuntu - install extras for libavcodec - libavcodec-extra-53 in 11.10, and libavcodec-extra-52 in 11.04

of course, you may use any vcodec and acodec you want

then, all you have to do is:

cat /media/mydisk/VIDEO_TS/VTS_01_[1234].VOB | \
    ffmpeg -i - -s 640x480 -vf yadif -vcodec flv -acodec libmp3lame -vb 1500k -ab 128k -ar 44100 ~/output.flv

still image with audio

to upload a sound track to YouTube, you need to provide a video file, not just audio

with ffmpeg it's simple to create a video with a still image and an audio track:

ffmpeg -loop 1 -i still-image.jpg -i audio-track.mp3 -vcodec libxvid -acodec libmp3lame -ab 128k -shortest video.avi

the important switch in the above command is -shortest, that tells ffmpeg to stop encoding when the "shorter" track ends, in this case the audio track - since the input image is loop'ed, the encoding would go on forever otherwise

concatenate videos

same size and all…

this is, fortunately, trivial

if all files on the input are the same resolution, frame rate, etc., e.g. segments of a captured stream, create a file segments.txt with the list of filenames:

file 'segment1.mp4'
file 'segment2.mp4'
# ...
file 'segment73.mp4'

this list is then fed to the concat filter:

ffmpeg -f concat -safe 0 -i segments.txt -c copy output.mp4

requiring re-encoding

gets a bit more messy, but not too messy :)

you need to instruct ffmpeg to map each file's stream, and then map those together into the output file

example with 2 files:

ffmpeg -i input1.mp4 -i input2.webm \
    -filter_complex "[0:v:0][0:a:0][1:v:0][1:a:0]concat=n=2:v=1:a=1[outv][outa]" \
    -map "[outv]" -map "[outa]" output.mp4

general syntax with N files:

ffmpeg -i file1.ext ... -i fileN.ext \
    -filter_complex "[0:v:0][0:a:0]...[N:v:0][N:a:0]concat=n=N:v=1:a=1[outv][outa]" \
    -map "[outv]" -map "[outa]" output.ext

of course, you can add all additional parameters to each input and output file (skip/trim, resolution, …)

see much more at ffmpeg docs

one-liners

process all files, may include spaces in file name:

ls *.avi | while read f; do ffmpeg -i "$f" ...params... "$f.mkv"; done

if you're having problems with the input format, passing video through mpeg typically helps:

ffmpeg -i file.mkv -q:v 2 -f mpeg - | ffmpeg -i - ...params... file.avi

downmix 5.1 dolby to normal stereo:

ffmpeg -i file.mkv ...params... -acodec libmp3lame -ar 44100 -ac 2 file.avi

add an overlay image to the video:

ffmpeg -i input.mp4 -i image.png -filter_complex "[0:v][1:v] overlay=x:y:enable='between(t,0,20)'" -pix_fmt yuv420p -c:a copy output.mp4

this will add image.png as an overlay at position x, y over the input.mp4 video, for the first 20 seconds

fade in and out, first and last 25 frames of a 1000 frame video:

ffmpeg -i input.mp4 -vf "fade=in:0:25,fade=out:975:25" -acodec copy out.mp4

convert an album contained in an APE or similar file with CUE into separate MP3 tracks:

ffmpeg -i cd.ape -ab 256k cd.mp3
mp3splt -a -c cd.cue cd.mp3