In today’s multimedia world there are a lot of different formats for video and audio. In order to use video and audio we generally need to convert and edit operations. There are different tools for this job but the most popular and useful tool is FFmpeg. FFmpeg is used by a lot of different free and commercial software. It provides a very large feature set. In this tutorial, we will look most wanted and useful features like a convert, resize,… of FFmpeg. FFmpeg is a free video editing software that works from the command line. As we know FFmpeg is provided for Windows operating systems too. So following commands will work seamlessly in Windows operating systems to if FFmpeg is downloaded and set up correctly.
Display Video Information
Video files have different options about their structure. These information can be display with ffmpeg.
$ ffmpeg -i jellyfish-3-mbps-hd-h264.mkv
Ffmeg will display following information;
encodershows video encoder of the video file.
creation_timedescribes the create time as year,month,day, hour, minute, second.
Durationdescribes the length of the video file in hour:minute:second format.
Streamshow video stream information. A video file like mkv, mp4 may have more than one .stream for different purposes. In this example, we have only one stream with index 0:0 . There is information about the video stream like a video format resolution frame per second.
Display Audio Information with FFmpeg
We can also get audio information from video file or audio file.
$ ffmpeg -i test.mp3
There are following information about the audio file.
genredescribes the musical type of mp3 as metadata
Durationdescribes the length of the video file in hour:minute:second format
Streamshow audio information like format type, quality of the stream
Convert Mkv To Mp4
Now we can start converting files into different format. We will start converting
Mkv video file into
Mp4 format. In this example we will convert file named
$ ffmpeg -i jellyfish.mkv jellyfish.mp4
In the example, the first thing is printing the source file information and then the convert operation starts. During the convert operation following statistical information is provided in real-time.
frameshow currently processes frame count
fpsshow the count of frames processed in one second
Lsizeshows the destination or new file size
timeshows current position of the convert process in the video length in time
bitrateshows the bit size of a second length of the video
Convert Flash and Flv To Mp4
Flash files can be converted to Mp4 like below.
$ ffmpeg -i jellyfish.flv jellyfish.mp4
Convert Mp4 To Mp3 with FFmpeg
Mp4 files are mainly used for mobile media devices or smartphones. This type of video can be converted to the mp3 audio file with the following command.
$ ffmpeg -i jellyfish.mp4 -q:a 0 jellyfish.mp3
Convert Mp4 To Avi with FFmpeg
Mp4 is a popular format as stated before. In the old time
avi was the most popular advanced format.
$ ffmpeg -i jellyfish.mp4 jellyfish.avi
Convert Mp4 To Gif with FFmpeg
Gif format is generally used to show simple, low size video to the user in the web pages without video players. Gif is a picture format that can store motions as different frames in pictures.
$ ffmpeg -i jellyfish.mp4 jellyfish.gif
Convert Avi To Mp4 with FFmpeg
We can convert
mp4 with the following command.
$ ffmpeg -i jellyfish.avi jellyfish.mp4
Extract Audio From Video File with FFmpeg
We can extract audio stream from the video file and save audio as a separate file in formats like
vorbis etc. We will provide
-vn -ab 128 options.
-ab 128 specifies the bitrate. The audio extraction will be done very little time.
$ ffmpeg -i Funny.mkv -vn -ab 128 Funny.mp3
Mute or Remove Audio From Video with FFmpeg
As we see previous example audio file is stored as separate stream. This gives the ability to mute audio of the video file. We will use
-an option to mute audio.
$ ffmpeg -i Funny.mkv -an Funny_muted.mkv
Resize Video Resolution with FFmpeg
Video files can be resized. Scaling down the resolution will made the video file less in size. We will use
-s with the new resoution
y sizes. In the example we will resize the video as
$ ffmpeg -i Funny.mkv -s 640x480 -c:a copy Funny_resize.mkv
Add Poster Image To Audio File with FFmpeg
As audio files provides only sound the singers albums need some poster to show while playing the song. This poster image can be embedded into audio file as metadata like below.
$ ffmpeg -i Funny.mkv -i smiley.jpg Funny_poster.mkv
Cut Video By Specifying Start and End Time with FFmpeg
We can cut video from specified time as specified time range. Original file will be kept without changing. We will specify the start time with
-ss option and duration with
-t option. In this example we will cut video from 20 seconds to 35 seconds.
$ ffmpeg -i Funny.mkv -ss 00:00:20 -codec copy -t 15 Funny_cut.mkv
Merge Video Files with FFmpeg
Multiple video files can be concatenated into single video file. We will provide the video file list as a text file with
-f concat and
-c copy options. The video files are listed like below named
Now we will join togather.
$ ffmpeg -f concat -i videos.txt -c copy Funny_join.mkv
Crop Audio File
We have previously cut the video file. There is also an option to cut audio files. We will use the same options with video file but the output will be an audio file. In this example, we crop
$ ffmpeg -i Funny.mkv -ss 00:00:20 -t 15 Funny_cut.mp3
Set Bitrate Of Audio with FFmpeg
Bitrate of a video effects the quality of the audio more bitrate means more quality but also more audio size. We can change the audio file bitrate
-ab option. In the example we will change bitrate to
$ ffmpeg -i Funny.mp3 -ab 128k Funny_128k.mp3
Set Framerate Of Video with FFmpeg
The framerate specifies the count of pictures in one second. High framerate means more fluid movies but costs more CPU and disk. We can change framerate with
-r option. In the example, we will set framerate
$ ffmpeg -i Funny.mkv -r 15 Funny.mp4
Set Bitrate Of Video with FFmpeg
Bitrate of video provides color density about the frames. More bitrate means more detailed colors but more in size. We can set video bitrate with ffmpeg by using
-b option. In the example we will change bitrate to
100k which means
$ ffmpeg -i Funny.mkv -b 100k Funny.mp4
Extract Images From Video with FFmpeg
As you know movie rippers generally provide some picture thumbnail about movies and video files. This picture thumbnail can be created with FFmpeg. We will use
-r option to specify rate and
-f option for the format. In the example, we will create a thumbnail with rate
$ ffmpeg -i Funny.mkv -r 1 -f image image-%3d.jpeg