FFMpeg is an open-source utility for recording,streaming and converting digital video and audio. We will see the usage of a few functionalities to convert between multiple file formats.
In simplest form ffmpeg can be used as:
ffmpeg -i <input filename> <outputfilename>
Eg: Convert a flash (flv)video to avi format
safeer@penguinpower:~$ffmpeg -i SELinux4EveryOne.flv SELinux4EveryOne.avi
This will throw a lot of output and then start converting the video. Once the conversion is finished play the the file with a media player like vlc or mplayer.
This should play the new avi file nicely (provided mplayer is installed):
safeer@penguinpower:~$mplayer SELinux4EveryOne.avi
Now, what if we want to extract the audio track alone from the Video? This is the command.
safeer@penguinpower:~$ffmpeg -i SELinux4EveryOne.flv SELinux4EveryOne.mp3
You can also convert flv to wav or wav to mp3
safeer@penguinpower:~$ffmpeg -i SELinux4EveryOne.flv SELinux4EveryOne.wav
safeer@penguinpower:~$ffmpeg -i SELinux4EveryOne.wav SELinux4EveryOne.mp3
A wide variety of media formats are supported by ffmpeg. To get a full list, use "ffmpeg -formats"
A few useful options:
-f <format> : Usually ffmpeg can determine the output format by the extension name itself. But incase you want to force the output format, use this option.
Eg: ffmpeg -i SELinux4EveryOne.wav -f mp3 SELinux4EveryOne.mp3
-ab : Audio bitrate ( 64k is default, 128k would be a reasonable value )
-ar : Audio frequency - 44100 Kz is default
-ac : Audio channel, a value of 1 is mono, 2 is sterio
-an : Disable audio recording.
-b : Video bit rate
-r : Video frame rate
-s : Video frame size ( Screen resolution )
Any option that you give before any input/output file will apply to that file. Also remember that you can have multiple input files each specified with "-i" option and multiple output files ins some cases.
A couple of other interesting uses of ffmpeg:
Extracting images from a video:
ffmpeg -i myvideo.avi -r 1 -s svga -f image2 img-%03d.jpg
This will extract one image per second from the video for its total length. The frame size of the images will be 800*600 ( svga ). The output file name img-%03d.jpg will be automatically expanded and used in the following way: the part "%03d" will change to 3 digit numbers padded with zeros - img-001.jpg,img-002.jpg....img-031.jpg ...
Video capturing yout desktop can be done with :
ffmpeg -f x11grab -s xga -r 50 -i :0.0 /tmp/out.avi
This will capture "1024x768" sized portion from the upper left corner of the screen. The frame rate will be 50 frames per second.
There many such uses for ffmpeg. to learn more, checkout their documentation.
No comments:
Post a Comment