19 ffmpeg commands for all needs
Posted by Jean-Baptiste Jung on Sep 22, 2008 | 80 commentsffmpeg is a multiplatform, open-source library for video and audio files. I have compiled 19 useful and amazing commands covering almost all needs: video conversion, sound extraction, encoding file for iPod or PSP, and more.
Getting infos from a video file
ffmpeg -i video.avi
Turn X images to a video sequence
ffmpeg -f image2 -i image%d.jpg video.mpg
This command will transform all the images from the current directory (named image1.jpg, image2.jpg, etc...) to a video file named video.mpg.
Turn a video to X images
ffmpeg -i video.mpg image%d.jpg
This command will generate the files named image1.jpg, image2.jpg, ...
The following image formats are also availables : PGM, PPM, PAM, PGMYUV, JPEG, GIF, PNG, TIFF, SGI.
Encode a video sequence for the iPpod/iPhone
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 par 180px
- Generated video : final_video.mp4
Encode video for the PSP
ffmpeg -i source_video.avi -b 300 -s 320x240 -vcodec xvid -ab 32 -ar 24000 -acodec aac final_video.mp4
Explanations :
- Source : source_video.avi
- Audio codec : aac
- Audio bitrate : 32kb/s
- Video codec : xvid
- Video bitrate : 1200kb/s
- Video size : 320px par 180px
- Generated video : final_video.mp4
Extracting sound from a video, and save it as Mp3
ffmpeg -i source_video.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 sound.mp3
Explanations :
- Source video : source_video.avi
- Audio bitrate : 192kb/s
- output format : mp3
- Generated sound : sound.mp3
Convert a wav file to Mp3
ffmpeg -i son_origine.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 son_final.mp3
Convert .avi video to .mpg
ffmpeg -i video_origine.avi video_finale.mpg
Convert .mpg to .avi
ffmpeg -i video_origine.mpg video_finale.avi
Convert .avi to animated gif(uncompressed)
ffmpeg -i video_origine.avi gif_anime.gif
Mix a video with a sound file
ffmpeg -i son.wav -i video_origine.avi video_finale.mpg
Convert .avi to .flv
ffmpeg -i video_origine.avi -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv video_finale.flv
Convert .avi to dv
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
Convert .avi to mpeg for dvd players
ffmpeg -i source_video.avi -target pal-dvd -ps 2000000000 -aspect 16:9 finale_video.mpeg
Explanations :
- target pal-dvd : Output format
- ps 2000000000 maximum size for the output file, in bits (here, 2 Gb)
- aspect 16:9 : Widescreen
Compress .avi to divx
ffmpeg -i video_origine.avi -s 320x240 -vcodec msmpeg4v2 video_finale.avi
Compress Ogg Theora to Mpeg dvd
ffmpeg -i film_sortie_cinelerra.ogm -s 720x576 -vcodec mpeg2video -acodec mp3 film_terminée.mpg
Compress .avi to SVCD mpeg2
NTSC format:
ffmpeg -i video_origine.avi -target ntsc-svcd video_finale.mpg
PAL format:
ffmpeg -i video_origine.avi -target pal-svcd video_finale.mpg
Compress .avi to VCD mpeg2
NTSC format:
ffmpeg -i video_origine.avi -target ntsc-vcd video_finale.mpg
PAL format:
ffmpeg -i video_origine.avi -target pal-vcd video_finale.mpg
Multi-pass encoding with ffmpeg
ffmpeg -i fichierentree -pass 2 -passlogfile ffmpeg2pass fichiersortie-2
Find a webhost with ffmpeg enabled
Cirtex Hosting got web hosting plans starting at $2.99.
- CirtexHosting - FFMpeg Hosting (Exclusive ClipBucket/PHPMotion/Vidiscript Auto-installer Free!)
- HostV - FFMpeg / Red5 Hosting (Exclusive ClipBucket/PHPMotion/Vidiscript Auto-installer Free!)
This article is an English adaptation of Jean Cartier ffmpeg exemples.







Click here for demo and more info
Thanks for the cheat sheet, submitted this to stumble…
Thanks, Stephen!
Great article! Submitted to digg.
Regards,
Cecil
Thanks, cesman!
You’re welcome.
Some of my favorite ffmpeg commands. I use mencoder for the rest.
How about DVD to avi?
Pretty cool! In converting images to a video, how do you start in a different #… like say i want to do image50 to image100.jpg?
I guess it didn’t take my comment. I was wondering if there was a way to turn images into video, but, by specifying a range of images… i.e. image50 - image500 . only converting those images?
I only use ffmpeg with xine. I thought it was a library but it seems it is also a command line tool. And a very powerful at that.
Thanks a lot.
@damien: I don’t know why but Akismet flagged your comment as spam…Btw, I never tried to start of at image50.jpg, but I’m pretty sure that it will work if you define a integer shell variable named d which have 50 as a value.
@Olivier: You can use ffmpeg both as a command line tool, or as a library. I’m pretty sure that Youtube uses it to convert mpeg and avi videos submitted by its users to the flv files they displays on the site.
How would you define that in a command line? How about doing btws? Between image50 and image500? I know this is a lot to ask, but thanx for replying and your help!
iPhone question (yeah, yeah, I know). From looking online it appears that the iPhone can play XVID/DIVX files, since they’re basically MPEG4. Does anyone know a way to do a fast transcode? Leave the data the same, just change the bare minimum (headers/container) so that iTunes will import and sync it to the iPod? It’d take up more space, but it would take minute or so to do an entire (for sake of argument, mind you) TV show that you found on the intertubes.
(And thanks for the reminder on FFMPEG - I needed something like that last night)
@ jbj
I have images in sequence that look like this:
image00001.jpg
all the way to image05000.jpg
I tried doing the code up there but nothing. I get an error. Here’s what i tried:
ffmpeg -f image2 -i image%d.jpg video.mpg
I get this error:
image%d.jpg: I/O error occurred
Usually that means that input file is truncated and/or corrupted.
What’s interesting is if i change the file name to 001.jpg and so on, it works. I really don’t have control of what the jpg name is going to be so how do i get it to work with that naming convention? Thanx again!
Thanks for the recipe, but can’t encode tv show to mp4 ipod. I get “Unable to find a suitable output format for ‘input’” error. Tried on Ubuntu and FreeBSD, video is:
Input #0, avi, from ‘Eureka.avi’:
Duration: 00:41:56.8, start: 0.000000, bitrate: 1157 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 624×352, 23.98 fps(r)
Stream #0.1: Audio: mp3, 48000 Hz, stereo, 128 kb/s
Maybe, I need to install something else? I updated ffmpeg to the latest. Is there an option for dynamic scaling, or the tool can calculate it?
@15 - v3g: “input” is a typo - just delete it. The OP is using the command line from the ffmpeg documentation, which uses “input” as a placeholder for the name of the input file.
Also, if you get an error about not having the aac codec, use libfaac instead.
http://ffmpeg.mplayerhq.hu/faq.html#SEC25
Thanks, now its working, but the quality is awfull:
ffmpeg -i xxxxx.avi -acodec libfaac -ab 128kb -vcodec libx264 -b 1157kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 312×176 -title X xxxxx.mp4
Input #0, avi, from ‘xxxxx.avi’:
Duration: 00:41:56.8, start: 0.000000, bitrate: 1157 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 624×352, 23.98 fps(r)
Stream #0.1: Audio: mp3, 48000 Hz, stereo, 128 kb/s
File ‘eureka.mp4′ already exists. Overwrite ? [y/N] y
Output #0, mp4, to ‘xxxxx.mp4′:
Stream #0.0: Video: libx264 (hq), yuv420p, 312×176, q=2-31, 1157 kb/s, 23.98 fps(c)
Stream #0.1: Audio: libfaac, 48000 Hz, stereo, 128 kb/s
And that worked on FreeBSD, not Ubuntu. For vcodec mpeg4, I couldn’t change the width and height, but only with libx264. And still doesn’t work with Ubuntu.
How do you change the quality, something like ‘q=2′ or ‘q=9′?
@v3g : When you change the video codec, you have to use the correct parameters. I have a few examples listed here for h.264:
http://onlydarksets.wordpress.com/2008/09/19/convert-sage-recordings-to-iphone/#more-408
TOUT SIMPLEMENT
BRAVISIMO
Thanks Dude , You Are the GNU
@damien
might find some help here:
http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html#SEC3
@M Kenyon II
Handbrake-DVD to AVI (multiplatform, open source)
http://www.applemacvideo.com/articles/rip-dvd-on-mac-using-handbrake.html#126
arrived through stumble… excellent info.
anyone has a code that will convert wmv to 3gp???
Thank for the efforts!
to encode an avi to to an nokia e71 recognized mp4 format:
ffmpeg -y -i inputFILE.avi -acodec aac -ab 72k -s 320×176 -aspect 16:9 -vcodec h264 -b 300k -qcomp 0.6 -qmin 16 -qmax 51 -qdiff 4 -flags +loop -cmp +chroma -subq 7 -refs 6 -g 250 -keyint_min 25 -rc_eq ‘blurCplx^(1-qComp)’ -sc_threshold 40 -me_range 12 -i_qfactor 0.71 -directpred 3 outputFILE.mp4
original file was 700MB, resulting mp4 encoded file slightly less then half @300MB…quality is excellent
even though I don’t foresee watching many video’s on this amazing phone, I thought I would share my findings…
hh,
manny
Does anyone know if ffmpeg supports transparent images ? I’m trying to put a sequence of PNGs into a .flv or .mov movies but the transparent parts of the images become black. I searched on Google but can’t find any solution.
Thanks for a really nice post, It really helped me alot.
Awesome. Thanks!
hello…thanks,it’s great but if i convert AVI format into jpg and 3GP into jpg at the same time, how we can determine it is the same frame?can u help me?
Hi! Thanks a lot for this pre-chewed tutorial! The only thing is that I came across errors when trying the command to convert a video to the iPhone/iPod format.
I was able to fix it by removing the word “input” from the command line. Worked perfectly after that. Just wanted to share that with everyone!
Merci encore!
TechDogg
Hi,
I am facing problem to convert video to .flv in my linux server using ffmpeg. I think ffmpeg is not execute in my server. I gave read/write/execute permission to ffmpeg. Can anyone give me idea of this type of problem or how can i solve this?
Advanced thanks for helping me….
:- Morshed Alam
@Morshed
No one can help w/ with such a vague question. It would help if you provided the context of the command you are trying to execute and the resulting error.
Regards,
Cecil
Thankyou so much
A tutorial for humans!!
Just what I’ve been looking for
Awesome cheat sheet! Thanks for all your work to put this together. Many good karma points for you
what a great article
Great article. Thanks.
Dude this is an awesome list of commands. Usually I am only able to find a couple by searching when I need them, kind of hit and miss. You have a great list much more than most. Many Thanks!
When using
ffmpeg -f image2 -i image%d.jpg video.mpg
what if I have hundreds of images starting at image4928.JPG and ending in image5028.JPG, is there a way with out renaming all the files? I tried
ffmpeg -f image2 -i image%04d.jpg video.mpg
but no worky
Hello
I have converted video using ffmpeg for .wmv and then taken a snapshot for that video
Please check the below code
exec($varFFMPEGpath.’ -i ‘.$n_file_name.’ -sameq -ar 44100 -r 25 -ac 2 -ab 128 -b 1200 -qmin 3 -qmax 6 ‘.$filename1);
exec($varFFMPEGpath.’ -i ‘.$n_file_name.’ -deinterlace -an -ss 00:00:02 -r 1 -y -vcodec mjpeg -f mjpeg ‘.$Img_Name.” 2>&1″);
Video is playing but the audio is not getting.
Please suggest me to get through the issue. It will be grateful.
How to replace audio track in mpg file?
Anybodu knows?
Thanks for this nice tutorial,if any one can provide how to make watermark in videos using ffmpeg becaz vhook is not live now…..Pls provide this
AWESOME
Using ffmpeg on our linux server to convert user uploaded videos to FLV. Sort of like a YouTube.
I am not satisfied with the quality, and know there has to be a better way. I have tried several changes, but am not getting where I would like it to be. As good as YouTube.
Please see my command line below, and suggest any changes I can make to improve the output quality.
Please keep in mind that the uploaded “user.fil” could be an flv,avi,wmv or a mpg.
ffmpeg -i user.fil -acodec libfaac -ab 156k -b 1024k output.flv
Thank you for any help you can give, and this is a GREAT cheat sheet. I will keep a copy by my side!!!
Well, I think I got it.
All I did is add the format key, and the results were 100% better. So remember this.
BAD - ffmpeg -i user.fil -acodec libfaac -ab 156k -b 1024k output.flv
GOOD - ffmpeg -i user.fil -acodec libfaac -ab 156k -b 1024k -f flv output.flv