Fast Forward MPEG (FFmpeg) is one of the most popular and the best multimedia networks in the world. It offers plenty of tools for you to play the video, convert the formats, stream live broadcast and even analysis the multimedia stream. These are the tools which actually make FFmpeg is a great framework to work with. They provide you with best technical solutions, also offering a myriad of extremely useful yet free software to the users.

FFmpeg can perform many functions when it comes to digitally playing or recording your videos and audios. For instance, you can easily convert the video from one format to another. Following is a very simple example of a command line which converts MP4 file into AVI file.

  # ffmpeg –i  Shawshank_Redemption.mp4  Shawshank_Redemption.avi

 This is the simplest example of any command line you will come across in the FFmpeg. This command will make ffmpeg video converter to convert MP4 file into an file. It is as simple as that. However, it is also recommended to declare other specification such as bitrate and codex as well.

Various Command Lines to Convert Video Formats.

In the context of above discussion, following are some ffmpeg examples of the commands you can use to convert video formats.


.avi and .mpg are two of the most popular video formats. Following commands help you convert .avi video to .mpg.

  # ffmpeg –i original_video.mpg final_vidoe.avi

Conversely, following command will convert an .avi video into an .mpg video.

  # ffmpeg –i – Shawshank_Redemption.avi  Shawshank_Redemption.mpg

.MP4 to .WMV:

The following commands convert .mp4 and .wmv formats between each other.

    # ffmpeg –i  – video_name.mp4  final_video_name.wmv

Now, simply reverse the code to make ffmpeg convert video to mp4. It can’t be simpler than that.

    # ffmpeg –i  – video_name.wmv final_video_name.mp4

.AVI to Uncompressed Animated Gifs:

Sometimes, you also want to convert your videos to animated gifs, especially if you run a blog or online video channel. Following is the Ffmpeg command for converting an .avi video to an uncompressed gif.

    # ffmpeg –i  – original_video.avi gif_uncompressed.gif

.AVI to .FLV:

.flv is another very popular video format. The command line used for converting .avi video format to .flv is slightly different from rest of the commands. Take a look at the following example.

    # ffmpeg –i  – original_video.avi –f flv final_video.flv

.AVI to DV:

DV is a new video format which is quickly garnering popularity among users. Following is a command line you can use to convert .AVI file to a DV file.  

    # ffmpeg –i  – origine.avi -s pal -r pal -aspect 4:3 -ar 48000 -ac 2 video_finale.dv

.ffmpeg Convert MP4 to MOV:

Ffmpeg also makes it very simple to convert an MP4 video into a MOV video. Following is a command which enables ffmpeg convert MP4 to MOV format.

    # ffmpeg -i input_file.mp4 -acodec copy -vcodec copy -f mov

Reducing the Size of Animated Gif:

It is pertinent to note that you only have to add .gif extension to in the output file and leave the rest to ffmpeg. You need to remember that gif files are usually much larger than original videos. However, ffmpeg allows you to considerably reduce the size of the gif file. First of all, the line you will write to make an animated gif from the video is as follows.

    # ffmpeg –i  – video_320x180.avi agif_320x180.gif –hide_banner

You also need to remember that there is no sound in animated gifs. Now, you can use different ffmpeg command lines to reduce the size of output file. The first of these commands is as under.

    # ffmpeg –i  – video_320x180.avi -ss 35 –t 20  agif_35-55_320x180.gif –hide_banner

What this command does is that it extracts from 35 seconds to 55 of seconds of original gif and reduces it to a 20-second video. Understandably, the size of the output video, in this case, will be much smaller.

Secondly, you can also reduce video resolution of the original video to reduce the size of output video. Following is an ffmpeg command to accomplish this task.

    # ffmpeg -i video_500x300.avi -vf scale=160:90 agif_160x90.gif -hide_banner

The above command reduces the video resolution from 500×300 to 160×190, thus considerably reducing the size of output gif.

There are many other ffmpeg command line options to reduce the size of the gif video. For instance, you can have a smaller gif video simply by decreasing the frame per second rate of the original video. The following ffmpeg command allows you to do exactly the same.

    # ffmpeg –i  – video_500x300.avi –r 10 agif_r10_500x300.gif

Above mentioned are some of the many ffmpeg command line examples for reducing the size of animated gif.

Converting formats for DVD players:

When it comes to converting videos for DVD players, you need a different line of code. Take a look at the following example.

    # ffmpeg –i  –original_video.avi –target pal-dvd –ps 1000000000 –aspect 16:9 final_video.mpeg

 Following is a brief explanation of the above command line.

  • Aspect ratio is 16:9 which is perfect for widescreens.
  • ps 1000000000 is the size of the output file in bites. It is the maximum size for the output video in this particular case.
  • target pal-dvd determines the output format of the video.

In addition to converting video formats between each other, Ffmpeg can also help users to compress different formats between each other. Following is an example of a command line which compresses .AVI to DIVX.

    # ffmpeg –i  –original_video.avi –s 320×240 –vcodec msmpeg4v2 video_output.avi

Similarly, you can use following commands to COMPRESS .AVI TO SVCD MPEG2.

PAL format

    # ffmpeg –i  –original_video.avi –target pal-svcd final_video.mpg

NTSC format:

    # ffmpeg –i  –original_video.avi –target ntsc-svcd final_video.mpg

FFmpeg Copy Video Command Line:

Sometimes, it is not a good idea to recode your video. All you need to do is to copy the contents especially when you are editing the video and cutting some of its parts. Following is the command you should use when you want to copy the video instead of recording it.

    # ffmpeg –i  –origine.mp4 –c:v copy –c:a copy –final.mkv

You can use the same command to copy the video in any format.

FFmpeg Copy Audio Command Line:

Sometimes, you only need to copy the audio of a video. Following ffmpeg copy audio command enables you to extract only audio from your video.

    # ffmpeg –i  –origine.mp4 –vn –acodec copy audio.aac

Here is a short explanation of the command:

  • As you must know, i specifies the input file.
  • You will skip the video part using the vn part.
  • acodec copy part keeps the original codec while copying the audio part.

Command Line Examples h264:

Ffmpeg also comes with the latest x264 encoder which allows you to create high-quality H.264 videos quite easily. There are actually two ways you can use x264 encoder to create videos. First of all, you need to choose a CRF value and a preset. Subsequently, apply your chosen values in the coder to get the video. This will also help you maintain the quality of all of the future videos you want to encode as well. Take a look at these ffmpeg command line examples h264.

Ffmpeg CRF Example:

    # ffmpeg –i  –input –c:v libx264 –preset fast –crf 22 –c:a copy output.mkv

 FFmpeg Transcode Example:

If you are looking for a more flexible way to use FFmpeg for encoding videos, you must consider using the transcoding feature. You can convert any video and audio format into your specified video codecs and audio output. Following is an example of FFmpeg transcoding.

ffmpeg –i  {filepath/inputfile}.{inputwrapper} –vcodec {desired video codec} –acodec {desired audio codec} {outputfile}.{output wrapper}

The transcode code can look like this in real life.

    # ffmpeg –i  origine.avi –vcodec prores –acodec pcm_s16Ie file.

What this command line is doing that it is converting a standard .avi file to a Quick Time Apple Prores.

Ffmpeg Video Scaling Commands:

Apart from using ffmpeg to convert video formats, you can also use it scale images as well. You can actually scale the original video to any size you want using the following command.

    # ffmpeg -i input.avi –vf scale=320:180 output.avi

You can scale the original video to any size just by adding the width and height of your choice in above command. This is the simplest of the commands to scale the video but it might disturb the aspect ratio of the output video.

On the other hand, you can use the following ffmpeg command to maintain the aspect ratio of the scaled video.

    # ffmpeg -i input.avi –vf scale=320:180 output.avi

However, if you want to change the aspect ratio of the video, you will use the following command.

    # ffmpeg -i input.avi -vf scale=”‘if(gt(a,1/1),320,-1)’:’if(gt(a,1/1),-1,240)'” output.avi

Now, if you want to crop width and height of the video, you will use following ffmpeg crop video command.

    # ffmpeg -i input.avi -vf  “crop=320:180:x:y” input_crop.avi

The above command will crop the video to the size of 320×180 pixels where 320 is the width and 180 is the height. The vf in the command stands for “video filter” whereas x and y represent left and top coordinates of the video respectively. 

Splitting Video Using ffmpeg:

It is also possible to split or cut a video using different ffmpeg command line options. Take a look at the following ffmpeg split video command.

     ffmpeg -ss <start> -t <duration> -i in1.avi -vcodec copy -acodec copy out1.avi

Following is a brief explanation of the command:

  • Start: the part of the video from where you want the video to start splitting. The format used is hours:minutes:seconds (00:00:00).
  • Duration: the total duration of the video you want to split from the original video. The format used is hours:minutes:seconds (00:00:00).

Now, if you use actual parameters in the above ffmpeg split video command, it will look like this.

     ffmpeg -ss 01:05:35 -t 01:10:00 -i in1.avi -vcodec copy -acodec copy out1.avi

The ffmpeg cut video command cuts a part of the video from 1 hour minutes 35 seconds to 1 hour 10 minutes. The split video has duration of 4 minutes 30 seconds.

Video Streaming with the Help of ffmpeg:

It is also possible to stream video using ffmpeg. Following is a general ffmpeg streaming command for a Ubuntu machine. You can also adjust the parameters for your own specific system.

     # ffmpeg -f alsa -i default -f v4l2 -i /dev/video0 -s 320×240 -ar 11025 -f flv -r 30.0 “rtmp://

FFmpeg Command Line Generators:

You can use many generators or editors to generate command lines for FFmpeg. For instance, FFmpeg Little Helper is a very popular ffmpeg command line generator. Similarly, you can also use Command Line Encoder if you are using windows 10. This particular encoder makes it really simple to generate FFmpeg command lines for windows. There are in fact innumerable command line generates you can use. Just do a little search on the Internet and you will get plenty of options to choose from.

Finally, it is also important for you to check the official documentation of FFmpeg if you are new to this multimedia framework. This will help you learn more about FFmpeg and all the amazing things you can do using this extremely popular video converting framework.