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 192k -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 192k -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


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.

This article is an English adaptation of Jean Cartier ffmpeg exemples.

  • Pingback: Business blog » Blog Archive » 19 ffmpeg commands for all needs()

  • Pingback: Web 2.0 Announcer()

  • Thanks for the cheat sheet, submitted this to stumble…

  • jbj

    Thanks, Stephen!

  • Great article! Submitted to digg.



  • jbj

    Thanks, cesman!

  • You’re welcome.

  • Some of my favorite ffmpeg commands. I use mencoder for the rest.

  • Pingback: Web 2.0 Announcer()

  • M Kenyon II

    How about DVD to avi?

  • damien

    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?

  • damien

    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.

  • jbj

    @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.

  • damien

    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!

  • Michael B

    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)

  • Pingback: B On The Move - Tech News » Blog Archive » Ffmpeg Your Way to Media Conversion Bliss [Media Conversion]()

  • Pingback: Ffmpeg Your Way to Media Conversion Bliss [Media Conversion] | DiyUs.com()

  • Pingback: links for 2008-09-23 « B-link List()

  • Pingback: Web Sites of Interest » links for 2008-09-23()

  • Pingback: links for 2008-09-24 « Donghai Ma()

  • Pingback: links for 2008-09-24 • Blog Archive • Opéra Gothique()

  • Pingback: Conversion avi vers mp4 avec ffmpeg (pour Nokia XpressMusic 5310) | Le blog de David Loureiro()

  • damien

    @ jbj

    I have images in sequence that look like this:


    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!

    • Regor

      %##d where the ## is your number sequence, try %05d

  • v3g

    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?

  • Pingback: Mac Fan Boy » Command line iPhone video()

  • Pingback: How to convert a Wav file to Mp3 format | Internet Marketing Blog()

  • Pingback: Ffmpeg Your Way to Media Conversion Bliss [Media Conversion] | The tech blog()

  • @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.


  • Pingback: Ffmpeg Your Way to Media Conversion Bliss [Media Conversion] | CHARGED's 24/7 News Aggregator()

  • Pingback: blreber.net › Daily Blog Post 09/24/2008 (p.m.)()

  • v3g

    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’?

  • Pingback: Ffmpeg Your Way to Media Conversion Bliss [Media Conversion] | schario.net()

  • @v3g : When you change the video codec, you have to use the correct parameters. I have a few examples listed here for h.264:

  • Pingback: links for 2008-09-25 « copula’s weblog()

  • Pingback: How a blog post becomes popular()



    Thanks Dude , You Are the GNU 🙂

  • Pingback: Ffmpeg Your Way to Media Conversion Bliss [Media Conversion] @ ZDima.net()

  • Pingback: Tech Bytes» Blog Archive » 19 ffmpeg commands for all needs()

  • PhillyPhanatic


    might find some help here:


  • Pingback: xnxlinks #20081002 « xnx labs()

  • Pingback: links for 2008-10-06 - Craig's Blog()

  • Pingback: 19 cosas útiles que puedes hacer con ffmpeg()

  • Pingback: 19 cosas útiles que puedes hacer con ffmpeg | Noticias, novedades, tecnología, programación - Bit & Bit()

  • Pingback: Master & Programmer » Blog Archive » Posibilidades de ffmpeg()

  • Pingback: Ffmpeg Your Way to Media Conversion Bliss [Media Conversion] | Semantic Web Reviews()

  • Pingback: stefan.waidele.info » Blog Archive » Stopmotionvideos mit ffmpeg (auch Videos für iPhone etc.)()

  • Pingback: links for 2008-10-26 | New Trommetter Times()

  • Matt

    @M Kenyon II

    Handbrake-DVD to AVI (multiplatform, open source)

  • Pingback: Lista de conversiones útiles de video usando ffmpeg()

  • Pingback: Ffmpeg Your Way to Media Conversion Bliss [Media Conversion]| All Technology Oriented News, Articles, Reviews, Geek Friendly Site| Suffire.com | Geek Stuffs, Technology Related()

  • socky

    arrived through stumble… excellent info.

  • anyone has a code that will convert wmv to 3gp???

    Thank for the efforts!

  • Pingback: How do you download applications and videos on IPHONE free of cost? | Download Cell Phone Themes, Applications,Ringtunes,Games()

  • Pingback: Cats Who Code & WP-recipes :: blog [dot] john010117 [dot] com()

  • mrmanny

    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…


    • I copy your example and get this error: Incorrect frame size How can I solve it?

  • Jay

    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.

  • Imran Ali

    Thanks for a really nice post, It really helped me alot. 🙂

  • Awesome. Thanks!

  • Pingback: ffmpeg-Beginner | psycho-city.de()

  • ajoism

    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?

  • Pingback: Korisni linkovi « SvaÅ¡tarija()

  • TechDogg

    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!


  • Morshed Alam

    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.



  • jimmy

    Thankyou so much
    A tutorial for humans!!
    Just what I’ve been looking for

  • Nancy

    Awesome cheat sheet! Thanks for all your work to put this together. Many good karma points for you 🙂

  • what a great article

  • Pingback: Webzappr’s Lifestream « My Random Web Snippets()

  • 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!

  • Jason

    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

    • Hubert

      I have the same problem in ffmpeg with more then 9 pictures to make a move
      ffmpeg -f image2 -i image%d.jpg video.mpg
      Do you find a remedy for that ?
      What means -f image2 ?


  • suba


    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.

  • R

    How to replace audio track in mpg file?
    Anybodu knows?

  • Pingback: RSS Week #59: letture per il weekend - Matteo Moro()

  • akthar

    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

  • Jatin Sadana


  • Pingback: 19 ffmpeg commands for all needs | Video Software Site()

  • 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

  • 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: This is the code for cut specific area from mp3

    ffmpeg -ss starttime -t totalseconds -i inout.mp3 -acodec copy output.mp3


    (Provided by Haleel Rahman)

    • himanshu


      I want to convert one jpg into .3gp file using ffmpeg. It should be of some duration (e.g. 10-20 sec) . audio mixing can be optional.
      Please provide commands for all steps.

      Thanks in advance.

  • Haleel

    Any can provide to make watermark in videos,also how do make the avi videos for mobile?

  • Pingback: quick ffmpeg audio-video encoding usage help « <!– something random just like junk – yard –>()

  • sony

    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.


  • Pingback: 7 Tasks You Shouldn’t Use a GUI For()

  • Pingback: 你用Linux命令行吗? | 酷壳()

  • Peter

    Thanks for the cool tips. Do you think, that there is ffmpeg preset page for all mobile phones?

  • Pingback: 7 wonderful LINUX command line tools | IT OPERATIONZ()

  • Jan

    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.


  • there is also another way to get good quality ffmpeg flv: using AviSynth+VP6.2 codec+patched ffmpeg

  • rabih

    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
    ldt_now=”$(date +”%y-%m-%d-%H-%M-%S”)”
    ffmpeg -t 60 -i “http://IP…” /home/grabbing/file_compressed_for_$ldt_now.mpg

    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

  • Pingback: Compumegared.com.ar » Links de miércoles – Semana 36()

  • 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.

  • Pingback: links for 2009-11-07 « lugar do conhecimento()

  • # rename files sequentially for FFMPEG to work properly
    for f in *.jpg; do
    let “counter+=1”
    mv $f screen${counter:1}.jpg

    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?


    • moB

      Thanks for the code snippet dan.

      I modified it to make symlinks to images one level up. Make video from links in the directory. No need to rename your data to fit with one time use.

      Runs in linux.

      # This will make a set of symlinks to files in directory
      # one level up continuously from screen1.jpg screen2.jpg …
      # The total is displayed on the terminal command prompt.

      # Then you say something like
      # ffmpeg -r .2 -i screen%03d.jpg outputmovie.mp4
      # or
      # ffmpeg -r 24 -b 1800 -i screen%03d.jpg output.mp4
      # moB 16 Oct 2010


      # edit this line to select files: S1* or *.jpg …
      for f in ../*.jpg; do
      no=$((no+1)); linkname=screen

      if [ “$no” -lt “10” ] ; then linkname=${linkname}00
      elif [ “$no” -lt “100” ] ; then linkname=${linkname}0

      ln -s $f ${linkname}${no}.jpg
      # hardlink
      # ln $f screen00${no}.jpg
      # symbolic
      # ln -s $f screen00${no}.jpg
      echo Total files linked\: $no

  • james

    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!


    • stib

      why not just halve the frame rate? If you know the frame rate of the input files just divide it by 2 (or whatever number you like). Has the advantage of not increasing your file size, or needing any recompression.

      ffmpeg -i input.mp4 2>&1|grep Video|sed “s/.*kb\/s,[[:space:]]*\([0-9\.]*\).*/\1/”

      gets the fps from the metadata (the sed expression is good for Mac/Darwin, on linux or other OSes it may need tweakage).

  • “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.

  • Great info. Excellent list of commands for an amazing product like FFMPEG.

  • That’s useful information to know. Thanks for sharing the how to back up tips.

  • Cire


    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’:
    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?

  • Pingback: ffmpeg commands @ Life, Liberty, and the Pursuit of Open Standards()

  • Jaime Gomez

    If you’re working with more recent builds, and have errors with some flags, you may want to try this:

    -flags +4mv+aic -trellis 1

  • Pingback: Dicas-L Receitas prontas para usar o comando ffmpeg « .Info – windows, linux, software e mais.()

  • Chewey

    Thanks for this info. The text of your commands are all clipped in Firefox 3. I had to view source to use them.

  • HI

    Make it 20 and add the line for converting one image and an MP3 to a flv 😉


  • Sohel Khan

    Thanks Jean, useful post.
    One query about the audio-video mix command?

    ffmpeg -i son.wav -i video_origine.avi video_finale.mpg

    Will this mix or replace embedded audio with new audio file?, is there any specific command to achieve that? i.e. completely delete the existing audio in video and replace with a new file?

    Thanks a lot,

  • Pingback: How to encode all of your videos, fast! « PiCloud Blog()

  • Shahid Umar

    I am looking for the conversion of .mov file to avm2 swf file, but it seems .mov file not supported well in ffmpeg. If I use the -an switch in the conversion command then it create the avm2 swf file. But i need the audio conversion as well.

  • Hi can you please update ffmpeg command for making watermark.. on video file using png logo…
    (Without using depreciated function vhook/imlib2.so…..
    may be using libavfilter or some other new function

    • For adding text watermark, use below:

      /usr/local/ffmpeg/bin/ffmpeg -sameq -i avi/Shakira_V-song.mpg -vhook ‘/usr/local/ffmpeg/vhook/drawtext.so -f /usr/share/fonts/truetype/freefont/FreeMono.ttf -x 5 -y 50 -t Mahendra’ -y ‘output2.mpg

      make sure path for .so of vhook is correct. Co-ordiante are as per video resolution.

      For png image watermarking:
      ffmpeg -loop -i /tmp/input.mpeg -vhook /usr/lib/vhook/drawtext.so -x 10 -y 10 -t MyVideo -f /usr/X11R6/lib/X11/fonts/truetype/arial.ttf /tmp/output.mpeg

      mahendra@mahendra-laptop:/media/DATA/Videos/avi$ /usr/local/ffmpeg/bin/ffmpeg -sameq -i Shakira_V-song.mpg -vhook ‘/usr/local/ffmpeg/vhook/watermark.so -f overlay.gif’ ohh.mpg
      ffmpeg version CVS, build 3277056, Copyright (c) 2000-2004 Fabrice Bellard
      configuration: –enable-amr_nb –enable-amr_nb-fixed –enable-amr_wb –enable-amr_if2
      built on Sep 13 2006 10:18:11, gcc: 4.0.0 20050519 (Red Hat 4.0.0-8)
      Input #0, mpeg, from ‘Shakira_V-song.mpg’:
      Duration: 00:04:14.8, start: 0.000000, bitrate: 757 kb/s
      Stream #0.0[0x1e0], 29.97 fps: Video: mpeg1video, yuv420p, 352×240, 104857 kb/s
      Stream #0.1[0x1c0]: Audio: mp2, 44100 Hz, stereo, 192 kb/s
      Output #0, mpeg, to ‘ohh.mpg’:
      Stream #0.0, nan fps: Video: mpeg1video, yuv420p, 352×240, q=2-31, 200 kb/s
      Stream #0.1: Audio: mp2, 44100 Hz, stereo, 64 kb/s
      Stream mapping:
      Stream #0.0 -> #0.0
      Stream #0.1 -> #0.1
      Press [q] to stop encoding
      [mpeg1video @ 0x836b128]warning, clipping 1 dct coefficients to -255..255
      [mpeg1video @ 0x836b128]warning, clipping 1 dct coefficients to -255..255
      frame= 7787 q=0.0 Lsize= 37466kB time=259.6 bitrate=1182.3kbits/s
      video:35155kB audio:2028kB global headers:0kB muxing overhead 0.761828%

      Make sure u choose correct watermark image and format.
      /usr/local/ffmpeg/bin/ffmpeg -sameq -i Shakira_V-song.mpg -vhook ‘/usr/local/ffmpeg/vhook/watermark.so -f overlay.gif’ ohh.mpg

      For windows OS:
      C:\ffmpeg\bin>ffmpeg -i robot.avi -vhook “c:/ffmpeg/bin/vhook/watermark.dll
      -m 1 -f 1.png” -ar 44100 test.flv

  • Derrick

    OK… stupid newb question….

    How do I convert a whole directory full of videos as a batch, ie: video01.mp4 to video01.avi ….. video25.mp4 to video25.avi?

    This is the command that I’m using right now to convert 1920×1080/60i h.264 video with 128kb AAC sound to standard def at 30 fps rather than the 60. Makes a big difference in the file size, and uncompressing seems to make it play a lot smoother. Mostly though, I want to be able to edit it in an NLE like Kdenlive (haven’t tried PiTiVi… maybe I should) so that I can cut stuff, add titling, etc.

    ffmpeg -i HDV_0028.MP4 -s 720×480 -r 29.97 -vcodec mpeg4 -acodec libmp3lame -ac 2 -ab 128000 -aspect 16:9 -b 15000k HDVsd_0028.avi

    Any help is appreciated!


    • cesman


      I don’t know if ffmpeg suppose this however, it should be easy to script. Something like:

      for i in $(ls video*.mp4)
      ffmpeg -i -$i s 720×480 -r 29.97 -vcodec mpeg4 -acodec libmp3lame -ac 2 -ab 128000 -aspect 16:9 -b 15000k $i.avi



  • Use this php for cutting movies same quality.

    exec(“/usr/bin/ffmpeg -sameq -ss 00:00:00.0 -t 60 -i input.mpg -acodec copy -vcodec copy output.mpg”);

    it will cut 60 seconds video file.

    thank you.

    • Hey Man really gr8 1

      thanks for your help It really worked for me
      I just cut the 1 min video of the movie

      Sushant Danekar

  • Backpacker

    @BlackSheep: Only just seen this so you’re probably long gone, but in case anyone else is interested, here’s the command I use to code any video into .3gp format:

    ffmpeg -y -i $1 -vcodec mpeg4 -s 480×320 -r 15 -b 700k -acodec libfaac -ac 2 -ar 32000 -ab 64k -f 3gp $OUTFILE

    Change the 480×320 to the size required.

  • Ipsita

    Can any one please help me to write the command to make .jpeg from .flv through ffmpeg ?

    $ffmpegpath = FFMPEG_PATH;
    $input = “video_file/orig/Lady.flv”;
    $output = “video_file/thumb/Lady.jpeg”;
    $command = “$ffmpegpath -i $input -an -ss 00:00:$fromdurasec -r 1 -vframes 1 -s 80×80 -f mjpeg -y $output”;

    The above works fine for .mpg and etc, but not for .flv files.
    Please help me to find out the command to make .jpeg file out of a .flv file.

    • ffmpeg -i video.flv -y -f image2 -ss 8 -sameq -t 0.001 -s 320*240 /image_dir/screenshot.jpg

      -ss : after seconds, screen captured
      -s : screenshot size dim.
      -f : askes ffmpeg to convert img output format

      should work!

  • ffmpeg -i video.flv -vcodec png -vframes 1 -an -f rawvideo -s 320×240 output_img_name

  • aanand

    I have a major issue with ffmpeg. I m using ffmpeg to create thumbnails of video and image both. When the input image is transparent gif or png, output image have black background.

    Is anybody here to provide me guidelines to fix this issue.


  • Pedro

    Does anyone knows how to limit the process of ffmpeg.exe to only 50% of the CPU, to avoid the CPU to stay on 100% on every conversion.

  • Hey Cats!!
    What a nice name for the web site !!

    I have lots of question .. but for now Just one !!

    1) How can we extract limited .. or specific piece of sound from a video..
    Like.. I have a movie and I liked one song .. I just want to get that songs’s starting .. ..
    Can you please guide me how can we just extract a sound from location 1 to location 2

    Thanks for your attention!!

    Sushant Danekar

  • Joal

    Great! 😀

    Just a note:

    Convert a wav file to Mp3
    ffmpeg -i son_origine.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 son_final.mp3

    son_origine.wav should be son_origine.wav

    • Joal

      son_origine.avi should be son_origine.wav
      now my mistake 😉

  • Tim

    With regards to personal preference, pragmatism, and/or programming syntax/structure, is there any particular reason why these 19 pearls aren’t bundled in a “user-friendly” gui? I have struggled so much with various versions of Linux but refuse to give up. I just have to scratch my head and wonder what is the attraction for the purist who prefers line commands. Is it just me or has anyone else noticed how the body of human knowledge has quickly and greatly expanded as we went from dial-up BBS to graphically rich internet content?

    • Don

      Say for example, you had 10,000 mpegs that you wanted to convert to avi. Would you want to use a gui to do that? I think not. No, one would use the CLI and likely wrap a bourne, bash, perl or python script around it and be done with it.

      What if you want to convert an mpeg to avi automatically at some time of the day as part of an unattended process? GUI? Nope. A script and a cron job.

      Another extremely powerful linux/unix command is xargs. Google it. Learn how to use it. Then maybe you’ll begin to appreciate the power of the shell.

      GUIs are wonderful. But there are a multitude of examples of tasks which are better performed from the shell. This page provides excellent recipes which can easily be embedded in scripts.

  • PhpTribe

    I am trying to create a video with dyamically generated images, which are stored in database.

    eg: http://localhost/image/id/20
    http://localhost/image/id/51 etc.

    Can I create video with these kind of images or by getting them directly from database.
    I’m using ffmpeg-php library. Its documentation says we can use ffmpeg_animated_gif. But it doesn’t look like exist anymore.
    So help here would be great.

    Many Thanks.

    • PHPTribe,

      I would keep it very simple.

      Write your php code so it looks thru your database, and copies the images you want to turn in to a video, to a “Temp” directory, while also renaming each image to “image1”, image2, image3… and so on.
      For example: copy /image/id/21.* /temp/image1. (very easily done with a “While Statement”.)

      One issue is, they all need to be of the same type. .jpg, .bmp, .gif

      Then use the above example: ffmpeg -f image2 -i temp/image%d.jpg video.mpg

      Then have your code clear out the temp directory.

      This is just a thought. Not sure exactly how you plan to implement.

  • This is so helpful. I’ve googled for 3 different things today and keep hitting this article.

  • You should try out http://transloadit.com – it can convert all videos for you without you having to install the tools or find a webhost with ffmpeg.

  • Can ffmpeg combine two audio sources into one?

  • Arokia Vinoth

    I want to combine two wav files using ffmpeg command. But i do no the command can any one say to combine two wav files using ffmpeg command ? ? ?

  • Thank you for the list of commands. I search for your link each time I need to use ffmpeg :).

  • asd

    ffmpeg -i felicity_final.flv -vcodec copy -acodec copy -ss 00:00:16 -t 00:01:05 trimmed_video.avi

  • teo

    What about #20: extract video only (i.e. drop the audio)

  • SuckMyBalls

    The command to convert a video to an animated gif doesn’t work. You’re an idiot.

  • priya

    Rotate video in 90 degree, i use these command
    exec(‘ffmpeg -i test.MOV -vf “transpose=1” outputfile.mp4’,$vOutput, $vReturn);
    when i execute a command it return success but a video size is less compare to original video and a video play but no images seen.

  • whenever i need the essentials I google ‘ffmpeg 19’

  • JM

    Heya. Having an issue while trying to merge a FLV video (consisting of a single picture file looping for 1,5h) with a MP3 file, basicly trying to create a video of a podcast-mp3 with a single static picture as the only visual element.

    Got the 1,5h picture FLV working with [ffmpeg -loop 1 -i picture.jpg -t 01:22:16 -r 1 -vcodec flv -an film.flv]

    But when trying to merge these by using [ffmpeg -i film.flv -i podcast.mp3 -acodec copy -vcodec copy podcastvid.flv]

    .. it ends up with: [flv @ 00000000040517D0] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 304327 >= 304327 av_interleaved_write_frame(): Invalid argument

    No idea how to try this otherwise 🙁

  • Many Thx for this, it makes things clearer.

  • R

    Turn X images to a video sequence: ffmpeg -f image2 -i image%d.jpg video.mpg

    How about the delay between images? If I want to have e.g. 3 seconds for each image?

  • Lampis

    Hi everyone,

    I’m trying to decode an mp4 stream to its frames and extract information about Motion Vectors and DC coefficients for each MB of the frames. Does anyone can help?
    Could -debug mv and -debug dc_coeff provide the necessary information? how can i properly use them?


  • every server config is different… and the video conversion to mobile quality vid wasn’t working as I was expecting it to, after some research and some work on this I came up with this:

    ffmpeg -i original.mp4 -acodec aac -strict experimental -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+aic -trellis 1 -cmp 2 -subcmp 2 -s 320×180 new_mobile.mp4

    • Samir

      Hi jubair,

      i tried your setting but it is not working on android i tried samsung s3
      do u hav idea.. i appreciate your hellp thanks

      Samir Shaikh

  • After converting video into mp4 to 3gp, it is not working in blackberry, showing ERROR “Unsupported media type: application/octet-stream”

    thanks in advance

  • sai

    Can somebody help me in getting a mts file coverted to avi? tried this and no luck 🙁

    ffmpeg -i video1.mts -f avi video2.avi


    FFmpeg version 0.5.9, Copyright (c) 2000-2009 Fabrice Bellard, et al.
    libavutil 49.15. 0 / 49.15. 0
    libavcodec 52.20. 1 / 52.20. 1
    libavformat 52.31. 0 / 52.31. 0
    libavdevice 52. 1. 0 / 52. 1. 0
    built on May 25 2012 20:12:42, gcc: 4.1.2 20080704 (Red Hat 4.1.2-46)
    Input #0, mpegts, from ‘video1.mts’:
    Duration: 00:01:06.08, start: 1.000067, bitrate: 22552 kb/s
    Program 1
    Stream #0.0[0x1011]: Video: h264, yuv420p, 1920×1080 [PAR 1:1 DAR 16:9], 59.94 tbr, 90k tbn, 59.94 tbc
    Stream #0.1[0x1100]: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
    Output #0, avi, to ‘video1.avi’:
    Stream #0.0: Video: mpeg4, yuv420p, 1920×1080 [PAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 59.94 tbc
    Stream #0.1: Audio: mp2, 0 channels, s16, 64 kb/s
    Stream mapping:
    Stream #0.0 -> #0.0
    Stream #0.1 -> #0.1
    [mp2 @ 0x91cb7d0]encoding 0 channel(s) is not allowed in mp2
    Error while opening codec for output stream #0.1 – maybe incorrect parameters such as bit_rate, rate, width or height

  • Helard

    Hi, congrats on the post, i was wondering wich is the code that i have to use to convert an mkv video file to an avi uncompressed file (yuv format), taking into account the audio too, from a AC-3 to PCM, thanks in advanced

  • papin

    There’s an error in the extract video and convert to MP3 part: “-ab 192” should be “-ab 192k” instead
    Don’t know if an audio at 192 bytes/s would be audible…

  • b3n

    how about M4V to avi (divx)? tried mp4 to avi but didn’t work ..

  • require command to convert .DAT file to .flv and .vob to .flv as media in my software just plays .flv files .Till done for the conversion of .avi, mpeg, .mov and many more..please provide some suggestion regarding the same.

  • sir… i need to divide a video, say avi file into png images and then get the uncompressed video, say avi file from these images.

    i am getting confused for the last one week. if possible.. please help me. i need to submit my project. i will be very thank ful to you.

    the commands i used are..

    ffmpeg -y -i input.avi -an -vcodec png -s 1024×768 pic%d.png`

    ffmpeg -i pic%d.png -y -f avi -b 1150 -s 1024×768 -r 29.97 -g 12 -qmin 3 -qmax 13 -ab 224 -ar 44100 -ac 2 test.avi

    hope some body reply to my best… thanks in advance.

  • cordeg

    I have a device that dumps blocks of fixed-length uncompressed audio samples at 48kHz in signed 16-bit LE format and I would like to use this as input to FFMPEG so that it can multicast an audio stream via RTP (it doesn’t have to compress the data on output, but if it does it should use something like MPEG-1 L2 ES format). Can you help me understand how this can be done with FFMPEG? I can interpose a simple pipe between the device and FFMPEG if necessary.

  • Please help in converting wav to mxf with 24 fps with ffmpeg
    what is the command

  • saman

    here is an example of code for converting image sequences to mov format,
    I get often reasonable result out of it,
    it mayu help somebody

    ffmpeg -y -probesize 5000000 -f image2 -r 25 -force_fps -i seqBnew.%3d.jpg -probesize 5000000 -f image2 -r $25 -force_fps -i seqBnew.%3d.jpg -c:v libx264 -profile:v main -g 1 -tune stillimage -crf 9 -bf 0 -pix_fmt yuv420p -s 960×540 -r 25 Aoutput.mov

  • Nilesh

    how i can add background music to mp3 files after every 5 seconds in php ?

  • Nilesh

    i want to add background music to mp3 files after every 5 seconds using this command :

    passthru(“$ffmpeg -i sun.mp3 -i stock.mp3 -filter_complex \
    ‘[0:a][1:a]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[out]' \
    -map 1:a -map '[out]' -c:a copy -t 5 -c:a libfdk_aac -shortest output.mp3");

    but its not working. please help me . . .

  • Alexandre

    Hi… I’m using ffmpeg and Matlab. I need read a yuv video and to save each frame inside a matrix. For example, the video is 1280x720px and it has 500 frames. I want save each frame as 1280*720 per column. The matriz will have size of 1280*720×500. Is it possible do it using ffmpeg?

  • cara baru convert video ke mp3
    terima kasih banyak

  • davidzyx

    “Extracting sound from a video, and save it as Mp3”
    there is a missing k after the 192
    and all lines related

  • Rajan

    How can I run these commands in my iOS app?

  • betternamess

    You may try Avdshare VideoGo to
    add audio track to mp4,

    Working as an Audio
    Volume Booster, Avdshare VideoGo

    can easily Add auido to MP4
    like add MP3 to MP4, WAV to MP4, M4A to MP4, AAC to MP4, FLAC to MP4, AC3 to
    MP4, etc.

  • In Oxford

    Instead of posting a load of specific commands why can’t anyone anywhere simply post an explanation of what each of the command line items mean and how to position them, i.e. if you want to save converted file to a different folder use this command in this place, if you want to keep the file from being recompressed use this command in the line etc etc – Can’t learn much from pre-built lines with no explanations of the actual meaning of the command parts! 🙁

    • Lists are very useful but you’re right, they are for users who are already familiar with the program in question. Maybe someday soon I’ll write a detailed article which can be used as a starting point for beginners.

    • OldPoorRichard

      That would be the ffmpeg documentation which is huge. This kind of tutorial is exactly the sort of thing I bookmark, quick sample command lines. Thanks to catswhocode for posting.

  • smallcated

    I highly recommend iDealshare VideoGo to converterConvert MP4 to MPG, MPEG, MPEG-1, AVI, MOV, FLV, WMV and any other video format with the highest exporting quality,it is very good

  • Less “S”

    I prefer mencoder … more efficient in my opinion . to encode folder , only the sound in 44100 khz , mp3 128 kb , without touching the video
    create a script:
    for f in * .mkv
    mencoder ” $ f” -ovc copy -oac mp3lame -srate 44100 -lameopts br = 128: q = 9: aq = 9: CBR : -o mode = 1 00 ” $ f”
    just change for f in * .mkv in for f in * .avi , * .mp4 for f in etc etc
    je préfère mencoder … plus efficace a mon avis encoder le son en mp3 44100 khz 128 kb sans toucher a la video
    creer un script :
    for f in *.mkv
    mencoder “$f” -ovc copy -oac mp3lame -srate 44100 -lameopts br=128:q=9:aq=9:cbr:mode=1 -o 00″$f”
    il faut juste changer for f in *.mkv en for f in *.avi , for f in *.mp4 etc etc

  • bkorb

    I just want to extract a snippet. Instead, I have all these instructions for how to do a mess of fancy things and instructions for extracting 20 seconds out of a .AVI file are completely missing.

  • dark star

    how to change a youtube downloaded file audio codec from MPEG-4 AAC to .mp3????