• Posted on May 6, 2013

Converting Files with FFMpeg

If you have to convert video or audio files of any type you may be overwhelmed by how many software options you have to pick from. And if that isn’t bad enough, a lot of those software options contain adware, viruses and more.

But there is a solution that is very simple and powerful, FFMpeg. FFMpeg is a free console based program that lets you convert audio and video files. A lot of websites and software we discussed above use it. But why use a third party client when you can use the real thing and have more power, control and security.

Below I will show you some way to convert files and settings for those files, such as lossless converting, FPS, resizing and more.

Converting Between File Types

$ ffmpeg -i "filename-input.avi" "filename-out.flv"

After -i you specify the input file you wish to convert. At the end of the FFMpeg command you specify the output file and extension. It will convert the file type by the input and output extensions. In the above case it will convert from AVI to FLV

Converting Lossless

$ ffmpeg -i "filename-input.avi" -qscale 0 -vcodec rawvideo "filename-out.flv"

The command is the same besides the -qscale and -vcodec parameters. The -qscale sets the quality scale. It does vary per codec but 0 usually is lossless / highest quality.

The -vcodec is the type of codec to encode the new video with. Rawvideo means raw codec. This will create large file sizes but be truly lossless. If you wish to use another codec you can list all the codecs with the following command.

$ ffmpeg -codecs

You will want to find a codec that has both E (encoding) and V (video codec).

Change FPS of Video

$ ffmpeg -i "filename-input.avi" -r 30 "filename-out.avi"

This will change the FPS of input video to 30FPS and save it to the same file extension / type. The -r parameter is the rate for the video. You can set this to any FPS you want, but picking higher FPS’s will take up more disk space.

Resizing Video

$ ffmpeg -i "filename-input.avi" -vf scale=1280:720 "filename-out.avi"

The above code converts the video (or image) to a 720p resolution. If your footage isn’t 16:9 by default, you will have a stretched video. To prevent your video from stretching you should replace either 1280 or 720 with -1. This will keep the video or image aspect ratio the same.

$ ffmpeg -i "filename-input.avi" -vf scale=1280:-1 "filename-out.avi"

There are also “variables” you can set the width and height to such as “iw” and “ih”. These are the input videos or images height (ih) and width (iw). So if you wish to scale the video to half you can do the following.

$ ffmpeg -i "filename-input.avi" -vf scale=iw/2:ih/2 "filename-out.avi"

Supported Files

FFMpeg supports a lot of file types, that is why it is so widely used and successful. Below are the most common file types it supports.

AVI, MOV, MP2, MP3, MP4, M4V, FLV, F4V, WebM, WMV, H264, 3GP, 3GP2, SWF, AVM2, 3GPP, and many many more. Some formats only support encoding or decoding. Make sure you pick the correct formats to use. The more popular formats above allow for both encoding and decoding.

For a full list of files and codecs FFMpeg supports you can see a list at http://ffmpeg.org/general.html#File-Formats

For more information on FFMpeg you can look at their documentation for more paramaters at http://ffmpeg.org/ffmpeg.html.

To download FFMpeg you will want to go to http://ffmpeg.org/download.html and most likely find “Windows Builds”. Get the stable/static release. If you don’t know between 32-bit or 64-bit, go with the 32bit option.