Ulyssesonline

the tech surfer

  • Home
  • About
  • Archives
You are here: Home / General / FFMPEG

April 17, 2009

FFMPEG

I recently installed FFMPEG on my Ubuntu desktop. FFMPEG is an open-source cross-platform software capable of recording, editing and streaming audio and video formats. It supports most of the available video formats like AVI, WMV, FLV, MPG and graphics formats like JPG, GIF, PNG and audio formats like MP3, MP2, AVI, YUV, WAV, etc.

Installing FFMPEG in Ubuntu is a breeze. You can either use the Synaptic Package Manager or use the Terminal by typing the following command:

Install

# sudo apt-get install ffmpeg

# sudo apt-get install ffmpeg

The FFMPEG program is not for the faint of heart. You have to run the program from the Terminal. There is no graphic interface, no GUI and no clicking of the mouse. Don’t be alarmed. It’s quite easy to use as you will later see.

Conversion from one format to another is easily done using the simple syntax displayed below. Of course, there area several dozen switches available to you if you want customize your own conversion, but the basic syntax is:

Basic Syntax

# ffmpeg -i input.avi output.flv

# ffmpeg -i input.avi output.flv

Here’s a list of the more popular options I have used extensively.

Video Options

-i snow.wmv  = the source file
-y snow.flv  = the output file
-r 25	  = video frame rate in fps
-qscale .1  = video quality .1 for high, 2 for medium, 4 for low quality
-s 300x200  = video size in pixels, use even numbers only for last digit

-i snow.wmv = the source file -y snow.flv = the output file -r 25 = video frame rate in fps -qscale .1 = video quality .1 for high, 2 for medium, 4 for low quality -s 300x200 = video size in pixels, use even numbers only for last digit

Audio Options

-ar 44100  = audio sample rate in Hz
-ab 448  = audio bitrate in kb
-ac 2  = audio channel. Use 1 or 2

-ar 44100 = audio sample rate in Hz -ab 448 = audio bitrate in kb -ac 2 = audio channel. Use 1 or 2

Example

To convert a WMV to FLV format in high quality, I used:

# ffmpeg -i snow.wmv -r 25 -ac 2 -ab 448 -ar 44100 -s 450x300 -qscale .1 -y snow.flv

# ffmpeg -i snow.wmv -r 25 -ac 2 -ab 448 -ar 44100 -s 450x300 -qscale .1 -y snow.flv

But, I had a little problem. No audio. I was missing some codec files. I was getting messages like “the libmp3lame was not found.” I found this awesome little script that fixed my problem. The script will download the latest FFMPEG version from the repository and recompile it right before your eyes.

I downloaded the script to my Desktop and made it executable by typing this command on my Terminal. Make sure you are in the correct directory, otherwise it will say the file is not found.

Make script executable

# sudo chmod +x ffmpeg.sh

# sudo chmod +x ffmpeg.sh

Run the shell script

# sudo ./ffmpeg.sh

# sudo ./ffmpeg.sh

Take a break and sip some coffee. This will take several minutes to complete. The script will create several temporary files and directories that you can later delete at your leisure. Once finished, you can begin experimenting with FFMPEG. Try converting different formats and use different options. Check out the documentation online.

Example

Here’s an example of a snowboarding video I converted from the WMV to the FLV format. I’m using the JW Flash Player to display the video. I used the following options to convert from WMV to FLV format with high audio and video quality options to fit in a 450×300 video screen.

# ffmpeg -i snow.wmv -r 25 -ac 2 -ab 448 -ar 44100 -s 300x200 -qscale .1 -y snow.flv

# ffmpeg -i snow.wmv -r 25 -ac 2 -ab 448 -ar 44100 -s 300x200 -qscale .1 -y snow.flv

<script src="http://ulyssesonline.com/files/swfobject.js" type="text/javascript"></script>
<div id="player">This text will be replaced</div>
<script type="text/javascript"><!--
var so = new SWFObject('http://ulyssesonline.com/files/player.swf','mpl','270','200','9');
so.addParam('allowscriptaccess','always');
so.addParam('allowfullscreen','true');
so.addParam('flashvars','&#038;file=http://ulyssesonline.com/files/snowboarding.flv&#038;image=http://ulyssesonline.com/files/snowboard.png');
so.write('player');
// --></script>

<script src="http://ulyssesonline.com/files/swfobject.js" type="text/javascript"></script> <div id="player">This text will be replaced</div> <script type="text/javascript"><!-- var so = new SWFObject('http://ulyssesonline.com/files/player.swf','mpl','270','200','9'); so.addParam('allowscriptaccess','always'); so.addParam('allowfullscreen','true'); so.addParam('flashvars','&#038;file=http://ulyssesonline.com/files/snowboarding.flv&#038;image=http://ulyssesonline.com/files/snowboard.png'); so.write('player'); // --></script>

Filed Under: General, HTML, Linux, PHP, WordPress Tagged With: ffmpeg

Comments

  1. Orion says

    April 17, 2009 at 11:10 am

    Nice article Ulusses. I think I will try it soon 🙂 What version of Ubuntu you have been installed it ??

    • ulyssesr says

      April 17, 2009 at 1:26 pm

      Orion, FFMPEG works on both Ubuntu 8.04 and 8.10. I use 8.04.

  2. Surupa says

    August 31, 2010 at 1:54 am

    It is very useful and nice article.
    But the size of file is increasing after conversion. Can you please tell me how to keep the file size unchanged?

    Thanks in advance…

    • Ulysses says

      August 31, 2010 at 7:38 am

      The video quality is set to high. You can lower it or just drop the -qscale 0.1 option from the command. You can try and see if the file is equal or smaller.

  3. James says

    March 9, 2011 at 3:06 pm

    For those looking for a way off the command line, ffmpeg and mencoder can be used together in a cross-platform GUI program called Mobile Media Converter.

  4. Thomas says

    May 20, 2011 at 2:48 am

    Some other uses of FFmpeg and its commands are
    Changing the Frame Rate:
    Syntax: ffmpeg -i inputfile -r 5 outputfile.
    Extracting Audio From The Video:
    Syntax: ffmpeg -i input.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 audio.mp3
    Converting Images To Videos:
    Syntax: ffmpeg -f image2 -i image%d.jpg output.mpg.
    Also helps in converting videos from one format to another.
    To know more visit: UbuntuManual.org

Copyright © 2003 - 2018