19 ffmpeg commands for all needs

by Jean. 163 Comments -

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.

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

More posts about GNU/Linux

Share this article

 

Comments (163) - Leave yours

  1. Web 2.0 Announcer said:

    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.[...]…

  2. damien said:

    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?

  3. damien said:

    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?

  4. jbj said:

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

  5. damien said:

    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!

  6. Michael B said:

    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)

  7. Ffmpeg Your Way to Media Conversion Bliss [Media Conversion] | DiyUs.com said:

    [...] I­f­ y­o­u pr­ef­er­ st­i­c­ki­n­g t­o­ t­he speed o­f­ t­he c­o­mman­d l­i­n­e when­ever­ po­ssi­bl­e, webl­o­g C­at­sWho­C­o­de det­ai­l­s ho­w t­o­ use Ffmpe­g&mdash­;t­h­e­ c­r­o­ss-plat­fo­r­m c­o­mman­d-lin­e­ t­o­o­l t­h­at­ r­un­s in­ t­h­e­ bac­k­gr­o­un­d o­f mo­st­ po­pular­ me­dia c­o­n­ve­r­sio­n­ t­o­o­ls&mdash­;t­o­ c­o­n­v­er­t­ v­i­deo­, audi­o­, an­d i&…. [...]

  8. links for 2008-09-23 « B-link List said:

    [...] 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. (tags: linux video ffmpeg encoding command txt) [...]

  9. damien said:

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

  10. v3g said:

    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?

  11. onlydarksets said:

    @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

  12. v3g said:

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

  13. onlydarksets said:

    @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

  14. links for 2008-09-25 « copula’s weblog said:

    [...] 19 ffmpeg commands for all needs catswhocode.com — 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. (tags: 09 2008 media convert tips) [...]

  15. links for 2008-10-26 | New Trommetter Times said:

    [...] 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. (tags: video utilities tutorial tips software reference) Be Sociable [...]

  16. Matt said:

    @M Kenyon II

    Handbrake-DVD to AVI (multiplatform, open source)
    http://www.applemacvideo.com/articles/rip-dvd-on-mac-using-handbrake.html#126

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

    [...] If yo­u pre­fe­r st­ic­k­in­g t­o­ t­h­e­ spe­e­d o­f t­h­e­ c­o­mman­d lin­e­ wh­e­n­e­v­e­r po­ssible­, we­blo­g C­at­sWh­o­C­o­de­ de­t­ails h­o­w t­o­ use­ Ffmpe­g—the­ cross-p­latform comman­­d-li­n­­e­ tool that ru­n­­s i­n­­ the­ b­ack­grou­n­­d of most p­op­u­lar me­di­a con­­ve­rsi­on­­ tools—to c­o­n­ver­t­ video­, audio­, an­d imag­es t­o&#173…. [...]

  18. mrmanny said:

    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

  19. Jay said:

    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.

  20. ajoism said:

    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?

  21. TechDogg said:

    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

  22. Morshed Alam said:

    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

  23. cesman said:

    @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

  24. gameutopia said:

    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!

  25. Jason said:

    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 said:

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

      Thanks
      Hubert

  26. suba said:

    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.

  27. akthar said:

    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

  28. Herron said:

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

  29. Herron said:

    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

  30. Kapil Sakhare said:

    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

  31. Jean-Baptiste Jung said:

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

    • himanshu said:

      Hi,

      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.

  32. sony said:

    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

  33. Jan said:

    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

  34. rabih said:

    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

  35. Noxxxone said:

    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.

  36. danpaluska said:

    # 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

    • moB said:

      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.

      #!/bin/sh
      # 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

      no=0

      # 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
      fi

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

  37. james said:

    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

    • stib said:

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

  38. Cire said:

    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?

  39. Jaime Gomez said:

    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

  40. Chewey said:

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

  41. Sohel Khan said:

    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,
    Sohel

  42. Shahid Umar said:

    Hi,
    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.

  43. sarvanhsr said:

    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

    • Mahendra Tipale said:

      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:
      http://gallery.menalto.com/node/41725
      Eg:
      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

  44. Derrick said:

    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!

    Thanks,
    Derrick

    • cesman said:

      @Derrick,

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

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

      Regrads,

      Cecil

  45. muralidhar said:

    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.

  46. Backpacker said:

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

  47. Ipsita said:

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

    $fromdurasec=”10″;
    $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.

    • Mahendra said:

      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!

  48. aanand said:

    Hi,
    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.

    Thanks,
    Aanand

  49. Pedro said:

    Hello,
    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.
    Tks
    Pedro

  50. Sushant Danekar said:

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

    Regards
    Sushant Danekar

  51. Joal said:

    Great! :D

    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

  52. Tim said:

    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 said:

      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.

  53. PhpTribe said:

    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/21
    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.

    • Kirk said:

      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.

  54. Arokia Vinoth said:

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

  55. priya said:

    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.

  56. JM said:

    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 :(

  57. R said:

    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?

  58. Lampis said:

    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?

    Thanks

  59. Jubair said:

    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 said:

      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

  60. Sumroo said:

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

    thanks in advance

  61. sai said:

    Hi,
    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

    result:

    FFmpeg version 0.5.9, Copyright (c) 2000-2009 Fabrice Bellard, et al.
    configuration:
    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

  62. Helard said:

    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

  63. papin said:

    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…

  64. dhanashree said:

    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.

  65. sagar said:

    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.

  66. cordeg said:

    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.

  67. saman said:

    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

  68. Nilesh said:

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

  69. Alexandre said:

    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?

Leave a Reply

Your email address will not be published. Required fields are marked *

Please respect the following rules: No advertising, no spam, no keyword in name field. Thank you!