FFmpeg Command Tutorial


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
Display Video Information
Display Video Information

Ffmeg will display following information;

  • encoder shows video encoder of the video file.
  • creation_time describes the create time as year,month,day, hour, minute, second.
  • Duration describes the length of the video file in hour:minute:second format.
  • Stream show 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
Display Audio Information
Display Audio Information

There are following information about the audio file.

  • genre describes the musical type of mp3 as metadata
  • Duration describes the length of the video file in hour:minute:second format
  • Stream show 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 jellyfish.mkv into jellyfish.mp4

$ ffmpeg -i jellyfish.mkv jellyfish.mp4
Convert Mkv To Mp4
Convert Mkv To 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.

  • frame show currently processes frame count
  • fps show the count of frames processed in one second
  • Lsize shows the destination or new file size
  • time shows current position of the convert process in the video length in time
  • bitrate shows the bit size of a second length of the video
LEARN MORE  Pixel Definition and Explanation

Convert Flash and Flv To Mp4

Flash files can be converted to Mp4 like below.

$ ffmpeg -i jellyfish.flv jellyfish.mp4
Convert Flash and Flv To Mp4
Convert Flash and Flv To 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 Avi
Convert Mp4 To 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 Mp4 To Gif
Convert Mp4 To Gif

Convert  Avi To Mp4 with FFmpeg

We can convert avi to 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 aac , mp3 , 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
Extract Audio From Video File
Extract Audio From Video File

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
Mute Audio
Mute Audio

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 x and y sizes. In the example we will resize the video as 640x480 .

$ ffmpeg -i Funny.mkv -s 640x480 -c:a copy  Funny_resize.mkv
Resize Video Resolution
Resize Video Resolution

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
Add Poster Image To Audio File
Add Poster Image To Audio File

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
Cut Video
Cut Video

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 videos.txt

videos.txt

part1.mkv
part2.mkv

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 audio_crop.mp3.

$ ffmpeg -i Funny.mkv -ss 00:00:20  -t 15  Funny_cut.mp3
Crop Audio File
Crop Audio File

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 128k

$ ffmpeg -i Funny.mp3 -ab 128k Funny_128k.mp3
Set Bitrate Of Audio
Set Bitrate Of Audio

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 15

$ ffmpeg -i Funny.mkv -r 15 Funny.mp4
Set Framerate Of Video
Set Framerate Of Video

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 100.000 bits

$ ffmpeg -i Funny.mkv -b 100k Funny.mp4
Set Bitrate Of Audio
Set Bitrate Of Audio

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 1.

$ ffmpeg -i Funny.mkv -r 1 -f image image-%3d.jpeg
Extract Images From Video
Extract Images From Video

2 thoughts on “FFmpeg Command Tutorial”

  1. Hi, How to check if a ffmpeg command is working correctly, by a par of a vido sample from the whole movie
    if suppose, i had given a wrong input, it will process if everthing is ok, but i need to abort in the beginning itself rather than waiting till the end to check and play the video .
    Would you say how to test the formula from ffmpeg

    Reply
  2. how to know if the ffmpeg command is working correcly. ffmpeg would process if the inputs are given. But i want to check if i have given correct input and it is processing correctly immediately after processing.
    Otherwise, i had to wait till the completion of the execution.
    if suppose, i have given a wrong font, it will correct to the wrong font.
    is there any way or formula to check

    Reply

Leave a Comment