~2011
master of ffmpeg?
With increasing frequency I find myself reverting to ffmpeg to do video and audio conversion. So for my own reminder a few recipes I collected from my mind and the web:
Updated ffmpeg
newer versions of ffmpeg have different switches, ie:
old | new |
---|---|
-b | -b:v |
-ba | -b:a |
-vcodec | -c:v |
examples
#Convert video to PNG's
#don't forget the 0 in %05d otherwise you won't get leading zero's
ffmpeg -i video.mov video-%05d.png
#better quality jpegs
ffmpeg -i video.avi -f image2 -sameq -qscale 1 -qmax 1 -qmin 1 video-%05d.jpg
#Convert png's to mjpeg
ffmpeg -i stills-%5d.png -vcodec mjpeg -b 10000k -qscale 4 video.avi
#Convert png's to mjpeg + resize
ffmpeg -i stills-%5d.png -vcodec mjpeg -s 960x540 -b 10000k -qscale 4 video.avi
#Convert flac to mp3
ffmpeg -i audio.flac -ab 196k audio.mp3
#Ipod:
ffmpeg -i source_video.avi input -acodec aac -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320x180 -title X final_video.mp4
Explanations :
* Source : source_video.avi
* Audio codec : aac
* Audio bitrate : 128kb/s
* Video codec : mpeg4
* Video bitrate : 1200kb/s
* Video size : 320px by 180px
* Generated video : final_video.mp4
#extract sound from video:
ffmpeg -i source_video.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 sound.mp3
#convert to gif
ffmpeg -i video_origine.avi gif_anime.gif
#convert to flah video
ffmpeg -i video_origine.avi -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv video_finale.flv
#Convert to DV video
ffmpeg -i video_origine.avi -s pal -r pal -aspect 4:3 -ar 48000 -ac 2 video_finale.dv
#or:
ffmpeg -i video_origine.avi -target pal-dv video_finale.dv
#multipass encoding
ffmpeg -i fichierentree -pass 2 -passlogfile ffmpeg2pass fichiersortie-2
#Convert MTS to ????
ffmpeg -i /tmp/00094.MTS -sameq -acodec copy test.mp4
#High quality!!! if your editor supports it
fmpeg -i /tmp/00094.MTS --vcodec ffv1 -sameq -acodec copy test.avi
#Convert TOD to AVI
ffmpeg -i file.TOD -vcodec copy -acodec copy file.avi
#specify start time in seconds or hh:mm:ss[.xxx] this example starts after 2000 seconds
#and encodes for 10 seconds
ffmpeg -ss 2000 -t 10 -i file.avi outputfile.mp4
#specify -ss after -i decodes the movie first. This can be handy for when the source
#has keyframes instead of full frames
#2pass mp4 encoding
ffmpeg -i bilderraus_hd_audio_ffv1.avi -pass 1 -vcodec libx264 -vpre fastfirstpass -fs 503316480 -threads 8 -f rawvideo -an -y /dev/null &&
ffmpeg -i bilderraus_hd_audio_ffv1.avi -pass 2 -vcodec libx264 -vpre fastfirstpass -fs 503316480 -b:v 1M -bt 4M -acodec libmp3lame -b:a 192k -ac 2 -threads 8 test.mp4
#cropping or removing letterbox
ffmpeg -i watervoorbij-audiofix.mp4 -croptop 84 -cropbottom 84 -s 720x414 -aspect 16:9 -vcodec mpeg4 -sameq -acodec copy watervoorbij-audiofix2.mp4
#Concatenate MOV files from a Canon camera
ffmpeg -i MVI_3044.MOV -f mpegts -vcodec copy -vbsf h264_mp4toannexb file-01.mpeg.ts
ffmpeg -i MVI_3045.MOV -f mpegts -vcodec copy -vbsf h264_mp4toannexb file-02.mpeg.ts
ffmpeg -isync -i "concat:file-01.mpeg.ts|file-02.mpeg.ts" -vcodec copy test.mov