Compact cameras like the Kodak Zi6 (or my shiny, new, optical image-stabilizing HD Zi8) sure are convenient. They also do some weird things with their video and audio encoding. ffmpeg to the rescue. Image (CC-BY) Ofer Deshe.

I freaking love ffmpeg. This command-line utility, backed by one of the most versatile video engines anywhere, can convert from just about anything to just about anything. It’s free, it’s more compatible than anything I’ve seen, it’s absolutely robust, and it’s also really, really fast. It’s just the thing when you encounter a video file that’s causing trouble, or if Apple just (cough) stripped out important features from QuickTime Pro X.

And when you’re in a big hurry, the command line really is the way to go.

I’ll have a series of recipes with ffmpeg, but to kick things off, make sure you can get ffmpeg running on your OS of choice.

ffmpeg official site

On Linux, your distro likely has a current release packaged up and ready to go. (The only reason you might want not to use it, in fact, is if you need to compile a specific version to stay in sync with a video editor. ffmpeg is actually reasonably easy to build, too, if it comes that.)

On Mac, you can go with the GUI port, ffmpegx. But come on: you’ve got a lovely bash command line ready to go. I suggest this how-to:
Installing and using FFmpeg on Mac OS X

Windows turns out not to be as bad as you’d think; you just need MinGW, the lightweight compiler that drags Windows kicking and screaming into the GNU age. Full instructions from the official ffmpeg docs. (Using MinGW is a lot easier than mucking about with Cygwin or Virtual C++, but if you need to do that for some reason – like, you’re a developer, for instance – they cover that, as well.)
FFMPEG Windows how-to

For our first recipe, let’s split some video and audio, and transcode the audio.

I’m a huge fan of handheld flash memory cameras; I like their lo-fi footage. Someday, years from now, people will like the sensor wobble, even. The problem with them is that they do some strange things in encoding their video. Many video editors refuse to read the audio track out of my Kodak Zi8, I expect because it doesn’t exactly follow the spec.

And, of course, another reason to strip audio from video as a VJ/visualist is that you don’t need it (meaning you could easily script this so it worked on an entire folder, etc.)

ffmpeg, away!

1. To copy video and remove audio from a file:

ffmpeg -i [inputfile] -an -vcodec copy [outputfile]

This switches off the audio (-an) and simply copies the video data without touching it (-vcodec copy).

2. To copy audio of the video, transcoding to WAV:

ffmpeg -i [input file] -acodec adpcm_ima_wav [output file]

This copies just the audio, and sets the audio codec to a standard PCM wav readable on Windows and other OSes.

Requests for recipes? Tricks of your own? Let us know.

  • http://www.lotech.co.nz lotech

    Although there are features missing in Quicktime X, I don't think they were removed, more they haven't been added yet. It is a whole new playback system and this is very much its first release. Theres a good read here about what Apple have done – <a href="http://arstechnica.com/apple/reviews/2009/08/mac-os-x-10-6.ars/6” target=”_blank”>http://arstechnica.com/apple/reviews/2009/08/mac-os-x-10-6.ars/6
    I hope they add features before 10.7 but by including the ability to use the old Quicktime system we haven't lost much – and in the long term we will be better off.

  • http://www.klangfreund.com Samuel Gaehwiler

    Hi Peter,

    do you suggest to work with the svn-version of ffmpeg or with the latest stable release (0.5, from march 3, 2009)? Do you have experienced any issues with the (cutting edge) svn-versions so far?

    The way I installed the svn-version on my OSX system (since I have http://www.macports.org installed) :

    > sudo port install lame faac ffmpeg-devel

  • Peter Kirn

    @lotech: Well, the issue is, QuickTime is many things… a utility, a player, a playback back-end, an API. Sometimes, it decides it's cross-platform. Sometimes, it decides it's platform-exclusive. Sometimes, it's a way of marketing iTunes. But given all that, I wouldn't be sure what will or won't wind up in QuickTime X, the player.

    And given the weird legal and licensing issues around video – which ffmpeg itself may violate if you have a legal department around and you're operating in the US – I don't expect commercial tools will ever approach what ffmpeg can do. Bottom line, until patent activists and lawyers (if ever) manage to iron out all the bizarre hypotheticals around codecs and patent law, and until the day Apple's QuickTime team exists solely to transcode some weird file you've come across, ffmpeg wins. ;)

    So I'm not blaming Apple, necessarily; this is just the reality. And these legal concerns are only an issue if you're a big company; for individuals, it's kind of a non-starter. But Apple and even Red Hat (see note below) count as big companies.

    @Samuel: Well, for what it's worth I see the ffmpeg I'm using with Fedora via RPMFusion is actually a November svn build. It's probably a tested svn.

    Honestly, I'd go with the stable, though, if you're running standalone. The only reason you'd likely grab from svn is given some specific use case, like needing the svn version to work with a matched version of Blender. Maybe someone else knows something I don't?

  • Peter Kirn

    Shorter answer, though Samuel — going that way via ports is probably your best bet, yeah!

  • http://www.klangfreund.com Samuel Gaehwiler

    I was just curious because in the download-section of the ffmpeg homepage, it's kind of suggested to use the svn snapshot (besides the order of download links: svn, git, stable):

    "FFmpeg has always been a very experimental and developer-driven project… SVN snapshots work really well 99% of the time so people are not afraid to use them."

    Obviously, I started working with the svn snapshot. I let you (and the ffmpeg devs) know if I run into any issues.

    (it's "sudo port install lame faac ffmpeg" if you wanna install the latest stable ffmpeg 0.5 on your mac, instead of the svn snapshot)

  • Peter Kirn

    Yeah, indeed, svn seems preferred for several projects that rely on ffmpeg, as well.

    If you're just using it for CLI conversion, of course, it probably doesn't matter as much.

  • bob phillips

    @peterkirn

    do you have a workflow to get things into a format that max/msp likes?

  • http://kevin.deldycke.com Kevin Deldycke

    Here is my contribution to the topic, a list of command lines to manipulate videos:

    → <a href="http://kevin.deldycke.com/2006/11/usefull-commands-video” target=”_blank”>http://kevin.deldycke.com/2006/11/usefull-commands-video
     

    I collected them over the last few years while using Linux as my main OS.

  • yair

    thnx kevin, nice collection.

    windows tip:

    thnx kevin, nice collection.

    tip #75

    using batch files you can create a batch name "dragToSilence.bat" containing:

    pushd %~dp1

    Q:inFFmpegffmpeg.exe -i %1 -an -vcodec copy %~n1_noAudio%~x1

    this will process any valid file (%1) you drag onto the batch file, output name will be foo_noAudio.avi (more here)

    you can also drag multipale files(!)

     

     

     

  • Fat Elvis

    Some general notes from our in-house wiki…

    <a title="Edit section: Calculate MPEG4 (or similar) Bitrate" href="http://fileserver/wiki/index.php?title=Current_Command_Pieces&action=edit&section=25&quot; rel="nofollow">Calculate MPEG4 (or similar) Bitrate

    Where the values for W, H and FPS are the values you're using for the destination video file.

    Where QUALITY is from 0.15 to 0.20 to 0.25 (aprox: low, medium, high)

    Slideshows and other still material can use a much lower bitrate.

    (W * H * FPS * QUALITY) / 1000 = VIDEO_BITRATE

    Note: Use common sense. If it looks like crap, increase the bitrate or change the options!

    See the note on using "qscale" istead of bitrate in FFMPEG!

    <a title="Edit section: Automatically Set Bitrate in FFMPEG" href="http://fileserver/wiki/index.php?title=Current_Command_Pieces&action=edit&section=26&quot; rel="nofollow">Automatically Set Bitrate in FFMPEG

    "The avai­la­ble qscale values range from 1 (highest qua­lity) to 31 (lowest qua­lity). Going worse than a 13 qscale pro­du­ces unac­cep­tably poor qua­lity"

    The "q" is also shown during encoding. If you see a lot of "q=1" you're not using enough compression. If you see lots of "q" values over 13, you may be using too much.

    Use -qscale to set the (variable) bitrate. Try -qscale 4 or -qscale 5

    The "-b" bitrate switch has no effect with "-qscale". It will default to 200kbit and show 200kbit, but actual bitrates will be adjusted to match the q value!

    <a title="http://www.kilobitspersecond.com/2007/05/24/ffmpeg-quality-comparison/&quot; href="http://www.kilobitspersecond.com/2007/05/24/ffmpeg-quality-comparison/&quot; rel="nofollow"&gt <a href="http://;http://www.kilobitspersecond.com/2007/05/24/ffmpeg-quality-comparison/” target=”_blank”>;http://www.kilobitspersecond.com/2007/05/24/ffmpeg-quality-comparison/

    <a title="Edit section: Convert a (short) DVD into an MOV file" href="http://fileserver/wiki/index.php?title=Current_Command_Pieces&action=edit&section=27&quot; rel="nofollow">Convert a (short) DVD into an MOV file

    In this case, the whole video is contained in VTS_01_1.VOB

    For longer stuff split across VOBs, this won't work!

    Linux or Windows version of FFMPEG

    Example shows Windows paths.

    We use this to make MOVs from DVDs.

    ffmpeg.exe -i E:VIDEO_TSVTS_01_1.VOB -s 640×480 -acodec libmp3lame -b 800k output.mov

    <a title="Edit section: Convert any video file into a DV stream" href="http://fileserver/wiki/index.php?title=Current_Command_Pieces&action=edit&section=28&quot; rel="nofollow">Convert any video file into a DV stream

    Windows or Linux

    something.avi could be anything FFMPEG can read – MOV, MPG, AVI, etc.

    ffmpeg -i something.avi -target ntsc-dv output.dv

    <a title="Edit section: Convert any video file into a DVD VOB stream" href="http://fileserver/wiki/index.php?title=Current_Command_Pieces&action=edit&section=29&quot; rel="nofollow">Convert any video file into a DVD VOB stream

    Windows or Linux

    something.avi could be anything FFMPEG can read – MOV, MPG, AVI, etc.

    ffmpeg -i something.avi -target ntsc-dvd output.vob

    <a title="Edit section: Convert a file's Container without Reencoding" href="http://fileserver/wiki/index.php?title=Current_Command_Pieces&action=edit&section=30&quot; rel="nofollow">Convert a file's Container without Reencoding

    Example shows encapsulating a DV stream into a QuickTime MOV container.

    Warning: Just because FFMPEG can do it doesn't mean a given program will play it!

    ffmpeg -i something.dv -acodec copy -vcodec copy output.mov

  • Fat Elvis

    Crap, that was really well formatted when I submitted it…

  • Pingback: Create Digital Motion » More ffmpeg Recipes for Free Video Conversion on Any Platform

  • yair

    btw, there is no need (in windows) to build from source.

    you can find autobuild servers around the web that do it for you

    <a href="http://www.google.co.il/search?q=ffmpeg+win32&quot; rel="nofollow"&gt <a href="http://;http://www.google.co.il/search?q=ffmpeg+win32” target=”_blank”>;http://www.google.co.il/search?q=ffmpeg+win32