FFmpeg Basics for Beginners

If I were to tell a reason why I like FFmpeg so much, ofcourse other than its power, I would definitely go with the ease it provides through command line. I don't have to open an application, select some file and then ask it to convert it. All of it can be done in just a single command. Check this out, and you will understand how easy media conversion becomes with FFmpeg.

Basic syntax of FFmpeg command

Lets begin with a simple example, I want to convert an avi file into mpg format. This is how we do this in ffmpeg.

[shredder12]$ ffmpeg -i input.avi output.mpg

A good thing about ffmpeg is that it automatically guesses which encoders to use by noticing the format of input and output files. So, until you are going to specify the encoders, make sure you mention the full filename, along with the appropriate format. Because of this feature the commands are really small. So, now we can even generalize the default command syntax of ffmpeg.

[shredder12]$ ffmpeg -i inputfile.fmt1 outputfile.fmt2

Here, the inputfile is in the format "fmt1" and the output file in format "fmt2". So, I hope, now you can see the power and level of abstraction provided by FFmpeg. If you are looking for some basic conversions you don't need to know a lot of specs. Just write a simple command following the above syntax and FFmpeg will do the rest for you.

Please note that, FFmpeg options always apply to the next file in the argument list. Doesn't matter whether it is the input or the output file. e.g any flag/argument mentioned in the command after the input file name will apply to the output file.

But there is one slight flaw. Since FFmpeg devs had to keep a default setting for the audio and video bitrate, they settled on a 64kbps audio(radio quality) and 200 kbps for video, a bad video quality. But these options can always be changed so this is not a big issue.

Here are some of the general options that you might need while using ffmpeg.

How to keep the video quality of an output file same as the input video file in FFmpeg

For example, if you want to keep the video quality of the output file same as the input file you can easily do this using the -sameq option. This is how it works.

[shredder12]$ ffmpeg -i input.avi -sameq output.mpg

Or, if you know what type of audio and video quality you are looking for. You can manually various options for doing so.

Pre-defined audio and video options for various file formats in FFmpeg

Suppose you just recorded a video from your camera and now want to burn it into a dvd. So, before burning you might want to convert the video into a proper DVD format. This is how you do it using the "-target" option in FFmpeg.

[shredder12]$ ffmpeg -i input.avi -target dvd output.mpg

Since, there are standards for such file formats, ffmpeg will automatically apply them on the output file. Thus, easing the task for you. For more such standards take a look at its man page.

How to fix the time duration of the output file using FFmpeg

This can be easily done using the "-t" option. Take a look at the example.

[shredder12]$ ffmpeg -i input.fmt1  -t 30 output.fmt2

The time specified is in seconds. But the format hh.mm.ss is also supported. This command will convert the first 30 seconds of the file input.fmt2  into output.fmt2.

Various Audio and Video FFmpeg options

Refer to these articles for various basic options for audio transcoding and video transcoding using FFmpeg.

This article is intended to just give the user a quick start on media conversion using FFmpeg. There are a lots of other stuff that can be done using FFmpeg. I will try and cover some common use cases in other such how tos.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <p> <br>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Use syntax $$latex$$ to insert LaTeX formulas.
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.
  • Search Engines will index and follow ONLY links to allowed domains.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.