How to convert video files into various other video formats using FFmpeg
Media Conversion into various formats is probably the widest and most popular use of FFmpeg. As I have already shown in the FFmpeg for Basics, a simple ffmpeg command should take care of most of your media conversion. e.g. If you want to convert a flv file to mpeg.
[shredder12]$ ffmpeg -i inputfile.flv -sameq outputfile.mpeg
FFmpeg is smart enough to take care of it. Please not that, we are using the -sameq option to ensure that FFmpeg uses the same audio and video quality as the input file and doesn't use its default options for media conversion.
How to set the resolution or frame size of a video using ffmpeg
We can use various other options. e.g. If you want to lower the resolution of the output video file, you can do this by setting the frame size of the final video using '-s' flag.
[shredder12]$ ffmpeg -i inputfile.avi -s 320x240 outputfile.avi
You can even use direct notations in place of writing down the resolution. e.g. hd720 stands for 1280x720. Use the notation. You can find more information in the table I have specified in this howto.
How to force FFmpeg to use a particular type of video codec for conversion.
Sometimes you might want to force a particular type of codec or format for video conversion. You can easily do it using the -vcodec flag.
[shredder12]$ ffmpeg -i inputfile.mpg -vcodec mpeg4 outputfile.avi
If you want to force a particular format. You can easily do this using the '-f' flag.
How to convert a high quality file into a .flv file format
Now, lets up all this knowledge to convert a single high quality file you have shot from your video camera and convert it into a low quality file, say flv for a player. Although the flags and the method we are using is all that matters, I am using flv to just define the output video's specs.
Video Bitrate: < 500 kbps
aspect ratio: 480x360
audio bitrate: 32kbps
Frames per second: 25
We will use the following command to make this happen.
[shredder12]$ ffmpeg -i recorded_file.mov -ar 22050 -ab 32k -r 25 -s 480x360 -vcodec flv -qscale 9.5 output_file.avi
ar is used to set the audio frequency of the output file. The default value is 41000Hz but we are using a low value to produce a low flv quality file.
qscale is a quantisation scale which is basically a quality scale for variable bitrate and coding, with lower number indicating a higher quality. You can try running the above command with and without qscale flag and then you can easily see the quality difference.
In order to get a list of all the formats supported by ffmpeg, run this command.
[shredder12]$ ffmpeg -formats
I hope I have covered most of the options to let you easily convert video media files into various formats yourself.


























1 Comment
Post new comment