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















Thanks for the cheat sheet, submitted this to stumble…
Thanks, Stephen!
Great article! Submitted to digg.
Regards,
Cecil
Thanks, cesman!
You’re welcome.
Some of my favorite ffmpeg commands. I use mencoder for the rest.
How about DVD to avi?
Pretty cool! In converting images to a video, how do you start in a different #… like say i want to do image50 to image100.jpg?
I guess it didn’t take my comment. I was wondering if there was a way to turn images into video, but, by specifying a range of images… i.e. image50 - image500 . only converting those images?
I only use ffmpeg with xine. I thought it was a library but it seems it is also a command line tool. And a very powerful at that.
Thanks a lot.
@damien: I don’t know why but Akismet flagged your comment as spam…Btw, I never tried to start of at image50.jpg, but I’m pretty sure that it will work if you define a integer shell variable named d which have 50 as a value.
@Olivier: You can use ffmpeg both as a command line tool, or as a library. I’m pretty sure that Youtube uses it to convert mpeg and avi videos submitted by its users to the flv files they displays on the site.
How would you define that in a command line? How about doing btws? Between image50 and image500? I know this is a lot to ask, but thanx for replying and your help!
iPhone question (yeah, yeah, I know). From looking online it appears that the iPhone can play XVID/DIVX files, since they’re basically MPEG4. Does anyone know a way to do a fast transcode? Leave the data the same, just change the bare minimum (headers/container) so that iTunes will import and sync it to the iPod? It’d take up more space, but it would take minute or so to do an entire (for sake of argument, mind you) TV show that you found on the intertubes.
(And thanks for the reminder on FFMPEG - I needed something like that last night)
@ jbj
I have images in sequence that look like this:
image00001.jpg
all the way to image05000.jpg
I tried doing the code up there but nothing. I get an error. Here’s what i tried:
ffmpeg -f image2 -i image%d.jpg video.mpg
I get this error:
image%d.jpg: I/O error occurred
Usually that means that input file is truncated and/or corrupted.
What’s interesting is if i change the file name to 001.jpg and so on, it works. I really don’t have control of what the jpg name is going to be so how do i get it to work with that naming convention? Thanx again!
Thanks for the recipe, but can’t encode tv show to mp4 ipod. I get “Unable to find a suitable output format for ‘input’” error. Tried on Ubuntu and FreeBSD, video is:
Input #0, avi, from ‘Eureka.avi’:
Duration: 00:41:56.8, start: 0.000000, bitrate: 1157 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 624×352, 23.98 fps(r)
Stream #0.1: Audio: mp3, 48000 Hz, stereo, 128 kb/s
Maybe, I need to install something else? I updated ffmpeg to the latest. Is there an option for dynamic scaling, or the tool can calculate it?
@15 - v3g: “input” is a typo - just delete it. The OP is using the command line from the ffmpeg documentation, which uses “input” as a placeholder for the name of the input file.
Also, if you get an error about not having the aac codec, use libfaac instead.
http://ffmpeg.mplayerhq.hu/faq.html#SEC25
Thanks, now its working, but the quality is awfull:
ffmpeg -i xxxxx.avi -acodec libfaac -ab 128kb -vcodec libx264 -b 1157kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 312×176 -title X xxxxx.mp4
Input #0, avi, from ‘xxxxx.avi’:
Duration: 00:41:56.8, start: 0.000000, bitrate: 1157 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 624×352, 23.98 fps(r)
Stream #0.1: Audio: mp3, 48000 Hz, stereo, 128 kb/s
File ‘eureka.mp4′ already exists. Overwrite ? [y/N] y
Output #0, mp4, to ‘xxxxx.mp4′:
Stream #0.0: Video: libx264 (hq), yuv420p, 312×176, q=2-31, 1157 kb/s, 23.98 fps(c)
Stream #0.1: Audio: libfaac, 48000 Hz, stereo, 128 kb/s
And that worked on FreeBSD, not Ubuntu. For vcodec mpeg4, I couldn’t change the width and height, but only with libx264. And still doesn’t work with Ubuntu.
How do you change the quality, something like ‘q=2′ or ‘q=9′?
@v3g : When you change the video codec, you have to use the correct parameters. I have a few examples listed here for h.264:
http://onlydarksets.wordpress.com/2008/09/19/convert-sage-recordings-to-iphone/#more-408
TOUT SIMPLEMENT
BRAVISIMO
Thanks Dude , You Are the GNU
@damien
might find some help here:
http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html#SEC3
@M Kenyon II
Handbrake-DVD to AVI (multiplatform, open source)
http://www.applemacvideo.com/articles/rip-dvd-on-mac-using-handbrake.html#126
arrived through stumble… excellent info.