Fast Forward MPEG (FFmpeg) is one of the most popular and best multimedia networks in the world. It offers plenty of tools for you to play the video, convert the formats, stream live broadcasts and even analyze the multimedia stream. These are the tools that actually make FFmpeg is a great framework to work with. They provide you with the 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 play 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 that converts an MP4 file into the 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 the FFmpeg video converter convert an MP4 file into a file. It is as simple as that. However, it is also recommended to declare other specifications such as bitrate and codex as well.
In the context of the above discussion, the following are some FFmpeg examples of the commands you can use to convert video formats.
.AVI VIDEO TO .MPG:
.avi and .mpg are two of the most popular video formats. The following commands help you convert .avi video to .mpg.
# FFmpeg –i original_video.mpg final_vidoe.avi
Conversely, the following command will convert a .avi video into a .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 a .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 the 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 that 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 to convert MP4 to MOV format.
# FFmpeg -i input_file.mp4 -acodec copy -vcodec copy -f mov output_file.mov
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 the 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 extracts from 35 seconds to 55 seconds of the 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 the video resolution of the original video to reduce the size of the 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 the 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
The above mentioned are some of the many FFmpeg command line examples for reducing the size of an animated gif.
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.
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 that compresses .AVI to DIVX.
# FFmpeg –i –original_video.avi –s 320x240 –vcodec msmpeg4v2 video_output.avi
Similarly, you can use the 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
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.
Sometimes, you only need to copy the audio of a video. Following the FFmpeg, the 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:
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
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 it is converting a standard .avi file to a Quick Time Apple Prores.
Apart from using FFmpeg to convert video formats, you can also use its 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 the 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 the width and height of the video, you will use the 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.
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:
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 a duration of 4 minutes 30 seconds.
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 320x240 -ar 11025 -f flv -r 30.0 "rtmp://publish.live.streamshark.io/2050C7/jumbwywy/livestreamdemo_328?mypassword
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.
This is one of the most important FFMPEG commands. This command will create images called pic1.jpg, pic2.jpg, etc, from a presented video file. The resulting image formats that can be obtained by this command are PGM, SGI, PPM, PGMYUV, PAM, TIFF, JPEG, GIF, PNG.
ffmpeg -i video.mpg pic%d.jpg
The above command is used to convert video to images. There are many parameters. With the -f mp4 parameter, you can also define that the product file will have an mp4 format. With vcodec libx264 parameter, you can specify the video codec that you desire to apply.
If you want to apply a container that can manage any stream but still determine which codecs are in the result file then FFmpeg is the best for such a job. You can choose the codecs required by applying the – c flag. This flag allows you to arrange the various codec to apply for each stream. For instance, to install a stream like Vorbis, you would apply the following command:
ffmpeg -i myfile.mp3 -c:a libvorbis result.ogg
The command FFmpeg -codecs will publish every codec FFmpeg associates around. The result of this command will vary depending on the tale of FFmpeg you have established.
If you want to convert videos for iPod or iPhone then with the help of a source file and an audio codec it can be achieved. For this, you have to mention video bitrate and video size so that it will generate the output. For example,
ffmpeg -i src_vid.avi input -acodec aac -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320x180 -title X output_vid.mp4
The above command will convert the source video into the output video which is suitable for iPods and iPhones
Now, converting .avi video to .mpg is very simple.You just have to mention the source video file and with the help of some parameters, you can convert .avi to .mpg. For example,
ffmpeg -i source_video.avi result_video.mpg
The above command is one of the most important commands. As you can see, the above command is using the parameter “-i” which then converts the .avi file to .mpg.
MPEG-2 is the conventional form for SVCD/CVD which users can sting on CDR and play on a Television with an SVCD-CVD congenial DVD player. Now, if you want to compress the .avi to SVCD mpeg2 then depending on the player format, you have to use various commands with various parameters. For example, if you want to use NTSC, then the following command will be used.
ffmpeg -i source_video.avi -target ntsc-svcd output_video.mpg
The above command is used to compress into NTSC format. Now, if you have a PAL format player and you want to compress the file then in the above command you just have to replace the NTSC with PAL and it will automatically compress it. This is one of the most used commands and it all depends on what type of player format you have.