19 ffmpeg commands for all needs
ffmpeg 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.




102 Comments + Trackbacks
9.22.2008
Thanks for the cheat sheet, submitted this to stumble…
9.22.2008
Thanks, Stephen!
9.22.2008
Great article! Submitted to digg.
Regards,
Cecil
9.22.2008
Thanks, cesman!
9.23.2008
You’re welcome.
9.23.2008
Some of my favorite ffmpeg commands. I use mencoder for the rest.
9.23.2008
How about DVD to avi?
9.23.2008
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?
9.23.2008
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?
9.23.2008
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.
9.23.2008
@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.
9.23.2008
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!
9.23.2008
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)
9.24.2008
@ 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!
9.24.2008
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?
9.24.2008
@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
9.25.2008
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′?
9.25.2008
@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
9.27.2008
TOUT SIMPLEMENT
BRAVISIMO
Thanks Dude , You Are the GNU
9.30.2008
@damien
might find some help here:
http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html#SEC3
10.27.2008
@M Kenyon II
Handbrake-DVD to AVI (multiplatform, open source)
http://www.applemacvideo.com/articles/rip-dvd-on-mac-using-handbrake.html#126
11.12.2008
arrived through stumble… excellent info.
11.22.2008
anyone has a code that will convert wmv to 3gp???
Thank for the efforts!
12.23.2008
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
12.29.2008
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.
1.1.2009
Thanks for a really nice post, It really helped me alot.
1.16.2009
Awesome. Thanks!
1.31.2009
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?
2.7.2009
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
2.15.2009
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
2.15.2009
@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
3.3.2009
Thankyou so much
A tutorial for humans!!
Just what I’ve been looking for
3.4.2009
Awesome cheat sheet! Thanks for all your work to put this together. Many good karma points for you
4.4.2009
what a great article
4.9.2009
Great article. Thanks.
5.13.2009
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!
5.26.2009
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
5.27.2009
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.
6.3.2009
How to replace audio track in mpg file?
Anybodu knows?
6.23.2009
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
6.23.2009
AWESOME
6.27.2009
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!!!
6.28.2009
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
7.10.2009
Hello,
I would like to cut the audio file for selected time..
Say I have a .mp3 of duration 00:50 sec..
I would like to cut the audio from 00:20 to 00:30 sec.
Please help me using ffmpeg command line.
Thanks in advance.
–Kapil
7.10.2009
@Kapil: This is the code for cut specific area from mp3
code:
ffmpeg -ss starttime -t totalseconds -i inout.mp3 -acodec copy output.mp3
startime=00:00:30
totalseconds:25
(Provided by Haleel Rahman)
7.16.2009
Any can provide to make watermark in videos,also how do make the avi videos for mobile?
7.19.2009
hi,
i am using ubuntu hardy. i was searching for a tool to convert 700mb avi files to 300mb avi without losing quality. is there any to serve that?.
thanks guys.
-me
8.27.2009
Thanks for the cool tips. Do you think, that there is ffmpeg preset page for all mobile phones?
9.10.2009
with ffmpeg I am trying to record video from my Toshiba laptop webcam. Video Recording is going fine but with no sound . Recording with sound is working well with cheese.
Please guide me how to do video recording with sound on ffmpeg with webcam.
Regards
10.1.2009
there is also another way to get good quality ffmpeg flv: using AviSynth+VP6.2 codec+patched ffmpeg
10.3.2009
Hi All…I can see there is some experts in ffmpeg in this blog…
I’m using ffmpeg in order to compress a continuous streamed mpeg2 retrieved from a dream box machine (satellite receiver)
I want to compress each minute in a separate file…
I’ve used the -t option, but in fact I’m loosing some gaps between each consecutive files
this is the script i’m using:
while test 1=1
do
ldt_now=”$(date +”%y-%m-%d-%H-%M-%S”)”
ffmpeg -t 60 -i “http://IP…” /home/grabbing/file_compressed_for_$ldt_now.mpg
done
I’m wondering if any one can give me any hints regarding how to output from ffmpeg in different consecutive files without having any lost gaps
Any help will be very appreciated
TIA
Rabih
11.1.2009
Hello,
thanks for the samples.
I think you should add a command to convert mp3 for iphones/ipods, this article is number one on google for linux convert mp3 for iphone.
PS: fix a typo for IPpod and add a copy command flash button like on github for urls.
11.17.2009
# rename files sequentially for FFMPEG to work properly
counter=10000
for f in *.jpg; do
let “counter+=1″
mv $f screen${counter:1}.jpg
done
this will rename a set of files continuously from 0001 then do something like
ffmpeg -i screen%04d.jpg outputmovie.mp4
and a question. what is the ffmpeg command to capture a snapshot from the webcam? just a jpg? or is another library better for that?
thanks,
dan
11.22.2009
Hello, All!
I’m using custom ffmpeg commands on a Drupal website for automatic conversion of uploaded files. It converts various file types to mpeg-4 (H.264) and is working fine. I need to add a simple slow motion to this process – simply repeated frames. In other words, I need a command to convert a video file with the following frames (A, B, C…) to (A, A, B, B, C, C…) for a 50% slomo.
If there’s some fancy way to do it with interpolation that would be even better, but for now I’ll settle for frame duplication.
Thanks in advance!
-James
12.27.2009
“Turn X images to a video sequence” – What can we do with it ? I don’t understand :-s . Can you explain for me ? Thank you very much.
1.6.2010
Great info. Excellent list of commands for an amazing product like FFMPEG.
1.18.2010
That’s useful information to know. Thanks for sharing the how to back up tips.
2.3.2010
Hello,
I’ve been trying to convert a .flv file I got from youtube and convert it to a .mp4 file playable on my iPod but can’t seem to make it work. I type in:
ffmpeg -i sniper.flv -acodec aac -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320×180 -title X sniper.mp4
but it gives me the following message:
FFmpeg version SVN-r21125, Copyright (c) 2000-2010 Fabrice Bellard, et al.
built on Jan 10 2010 13:49:22 with gcc 4.4.1
configuration: –enable-gpl –enable-version3 –enable-nonfree –enable-postproc –enable-pthreads –enable-libfaac –enable-libfaad –enable-libmp3lame –enable-libopencore-amrnb –enable-libopencore-amrwb –enable-libtheora –enable-libx264 –enable-libxvid –enable-x11grab
libavutil 50. 7. 0 / 50. 7. 0
libavcodec 52.47. 0 / 52.47. 0
libavformat 52.46. 0 / 52.46. 0
libavdevice 52. 2. 0 / 52. 2. 0
libswscale 0. 8. 0 / 0. 8. 0
libpostproc 51. 2. 0 / 51. 2. 0
[flv @ 0x9815390]Estimating duration from bitrate, this may be inaccurate
Seems stream 0 codec frame rate differs from container frame rate: 59.93 (29967/500) -> 29.92 (359/12)
Input #0, flv, from ’sniper.flv’:
Metadata:
duration : 326
starttime : 0
totalduration : 326
width : 320
height : 180
videodatarate : 201
audiodatarate : 64
totaldatarate : 271
framerate : 30
bytelength : 11073949
canseekontime : true
sourcedata : B4A7DA446
Duration: 00:05:26.15, start: 0.000000, bitrate: 206 kb/s
Stream #0.0: Video: h264, yuv420p, 320×180 [PAR 1:1 DAR 16:9], 206 kb/s, 58.82 fps, 29.92 tbr, 1k tbn, 59.93 tbc
Stream #0.1: Audio: aac, 22050 Hz, stereo, s16
[NULL @ 0x980c020]Unable to parse option value “trell”: undefined constant or missing (
Invalid value ‘+4mv+trell’ for option ‘flags’
What am I doing wrong?