Short Notes on ffmpeg

From PaskvilWiki
Jump to: navigation, search

The 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 few parameters need tweaking, and is you wanna use mp3 for your FLV, you either wanna compile ffmpeg by hand, or - in Ubuntu - install extras for libavcodec - libavcoded-extra-53 in 11.10, and libavcoded-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 -deinterlace -vcodec flv -acodec libmp3lame -vb 1500k -ab 128k -ar 44100 ~/output.flv

Still Image with Audio

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

With ffmpeg it's simple to create video with still image and 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 the -shortest, that tells ffmpeg to stop encoding when "shorter" track ends, in this case the audio track; since 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 same resolution, frame rate, etc., e.g. segments of 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 needs 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