Convert Video Formats Using FFMPEG

By  on  
FFMPEG

Getting a video into the format you like can be important when providing media to your users on the web. Unfortunately your customer or video source may not give you media in the desired format. No problem: use the FFMPEG library to quickly and easily convert your media from and to any format you'd like.

Installing FFMPEG

sudo port install ffmpegx

The above installs FFMPEG with MacPorts. The install process took quite a while because FFMPEG required that I upgrade quite a few packages. Be patient...it's worth it.

Basic Conversion Shell Script

ffmpeg -i myVideo.mpeg myVideo.flv

This is a very basic conversion directive. Since Flash video has become the standard for embedding video, I've chosen to convert to the FLV format. If you want to control more of the conversion details, grab the documentation and experiment. I've installed FFMPEG on a few websites and used PHP to direct FFMPEG to dynamically generate videos.

If you need to take control of your media, try FFMPEG. FFMPEG also has a GUI version if you prefer to avoid command line.

Recent Features

  • By
    7 Essential JavaScript Functions

    I remember the early days of JavaScript where you needed a simple function for just about everything because the browser vendors implemented features differently, and not just edge features, basic features, like addEventListener and attachEvent.  Times have changed but there are still a few functions each developer should...

  • By
    Responsive and Infinitely Scalable JS Animations

    Back in late 2012 it was not easy to find open source projects using requestAnimationFrame() - this is the hook that allows Javascript code to synchronize with a web browser's native paint loop. Animations using this method can run at 60 fps and deliver fantastic...

Incredible Demos

Discussion

  1. You can use WinFF, it’s an other GUI for ffmpeg with presets. It works for Linux and Windows.

  2. @Sylvain: Thanks for sharing that. I still prefer the command line — it’s faster and you can’t easily automate the GUI.

  3. I have it configured like this:
    ./configure –enable-libtheora –enable-libvorbis
    and am using the following command to create open videos for the new firefox 3.5 (3.1+) video tag:
    ffmpeg -i sourcefile_ie.wmv -acodec libvorbis -vcodec libtheora finalfile_the.ogv

    Some ffmpeg documentation:
    http://www.ffmpeg.org/ffmpeg-doc.html

  4. adamnfish

    Awesome, thanks David.

    If you’re on Windows, get Super. It’s a deeply ugly program, but it is awesomely powerful. Basically, it’s a GUI wrapper for a number of command line tools (including ffmpeg and others) and picks which tools to use depending on your input and output settings. Any format you’ve heard of and many you haven’t.

    Super’s websiteand here’s the actual link to the file (finding it on the website is not easy…Super setup

  5. Here is my collection of useful FFMPEG commands. I have done this for Linux – but should work on mac as well.

  6. Awesome tips Binny V A! Everyone check out Binny’s link!

  7. Wes

    For mac, I use this GUI:

    http://www.ffmpegx.com/

  8. Vince

    Is it possible to convert to .mov?

  9. @Vince:
    I think http://ubuntuforums.org/showthread.php?t=561087 has your answer:

    “To encode a .mov you’ll need to use the target option.”

    ffmpeg -i input.avi -target X output.mov
    Where X stands for a target type as defined in the FFmpeg docs

  10. Ronny

    I get this on my Mac: sudo: port: command not found

    Why?

  11. Ronny's Concious

    @Ronny: You need to install MacPorts: http://www.macports.org/

  12. sundaymicky

    You can try Cucusoft DVD and Video converters suite which includes Cucusoft Ultimate DVD and Video Converter Suite. It is the best all-in-one DVD and video conversion software converts DVDs and videos to play on almost any portable device including iPod, iPhone, Zune, PSP, video capable MP3 players, video capable mobile phones, and Pocket P.C., etc.
    You can free download this software free from here:
    http://freedvdripper.org/dvdvideoconverter/cucusoft-ultimate-dvd-video-converter-suite.html

  13. abdulla

    I have converted video to FLV format. But the problem is File size is
    0kb.

    So, Am not getting any perfect solution on this. IF any one knows Pls help me.

  14. @David Walsh: I’m trying to use ffmpeg on my website to dynamically ge t thumbnails created of flv fils, but it doesn’t seem to work out that well. i have checked the php.info and made sure its installed correctly, but i was wondering how to do this with php, every method i have found isntworking.

  15. Boyd

    Try this to create thumbnails, I have it working. You must have the GD library installed in order for this to work!

    //Only used to create an image with the same name as the video with .jpg ext
    $thumb=substr(filename,0,(strlen(filename)-strlen(filetype)));
    $command="ffmpeg -i ".escapeshellarg(html_entity_decode("directory/to/video/filename"))." -an -ss ".escapeshellarg("00:00:08")." -an -r 1 -vframes 1 -y -f mjpeg ".escapeshellarg(html_entity_decode("directory/to/jpg/".$thumb."jpg"));
    
    //change this to your library path
    shell_exec("export LD_LIBRARY_PATH=/usr/local/lib/");
    shell_exec("nohup nice -n 1 $command > /dev/null & echo $!");
    
    sleep(5);
    chmod("".FILES_DIR.$file_id."-".$thumb."jpg",0700);
    

    This will create an image of the 8th second of the video

  16. Boyd

    BTW I just can’t seem to be able to convert videos I get 0Kb files, but I am able to execute the same command from the command line

    Any help would be appreciated, you can email me

  17. Ffmpeg is great for converting files but complex codec and parameters setting is often required when you are using it on linux. As far windows platform is concerned, Ffmpeg is awesome.

    • Jeff

      Thunder (or anyone), I’ve been trying to get FFmpeg working on WAMP for days. Can you please help me?

      I have found little info about installing and testing FFmpeg and flvtool2 on WAMP. I could really use someone’s help.

      I already hFFmpegmpeg, flvtool2 and FFmpegmpeg installed but I’m not sure if I have installed the correct versions of each so they all work together.

      Every test script I try gives some sort of error or I get a 0kb flv file. Maybe because the scripts are for NIX. I just don’t know.

      If someone is willing to take the time, I surappreciaterechiate it :)

      Shoot me an email:

      jeffshead at hotmail.c0m

  18. srini

    How can i convert videos in short time? guys anyone can please suggest…

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!