Most Common FFMPEG Commands I Use
In this tutorial, I will discuss a couple useful ffmpeg commands that anyone can use to perform some simple video editing. Before I start this tutorial, I must state the fact that ffmpeg is pretty awesome. But there are a lot of limitations. Using it to do complex video editing, the end result can sometimes be fairly disappointing. Some issues I have encountered so far:
- When trying to stitch multiple videos together, the audio of the last two minutes often becomes blank.
- When attempt to resize a video, from dimension 853X467 to 720x480, the clarity and resolution is very disappointing.
- When perform a complex operation, if you don't choose the right format, nothing would happen.
There might be many other problems I have not discovered. You might ask, if this tool has so many problems, why you use it? To me, besides the problems, it is a really handy tool. For some simple operations it is very efficient and the end result is very beautiful. Here are some commands that should convince you.
The very first thing I learned about ffmpeg is that I can extract mp3 audio out of the mp4 videos. This is a very useful functionality. And it can be achieved by the following command:
ffmpeg -i test-input.mp4 test-output.mp3
This little command, with -i and input file name, then follow by the output file name, can easily rip the audio out of the original video file. Now, if I want to set the bit rate of the output audio file, I do this:
ffmpeg -i test-input.mp4 -ab 192k test-output.mp3
The command line option
-ab 192k means the output file has baudrate of 192k bites per second.
Alternative to ripping audio out of video file, it is possible to convert the video file from one format to another, like mp4 to mpg or mp4 to avi. Here is a simple example of converting between mp4 and avi:
ffmpeg -i test-input.mp4 test-output.avi
Cutting Video or Audio Files
Another thing I found very useful is cutting the video or audio files. The command that does it is:
ffmpeg -i test-input.mp4 -ss 00:00:05 -t 00:30:00 test-output.mp4
The way this command works is
-i <file name> specifies the input file (test-input.mp4). The last part file name (test-output.mp4) is the output file. The
-ss hh:mm:ss specify the start point to cut, and
-t hh:mm:ss specify the end point.
Alternative to the format of hh:mm:ss, you can just specify the seconds of start point and end point. Using the above example, the start point would be 5 (5 seconds from the very beginning) and the end point would be 1800 (1800 seconds from the very beginning). I prefer the format of hh:mm:ss because I can easily get this from the video player. Using seconds as format requires some calculation which can be tie consuming.
The above command requires re-encoding of the audio or video file. To make it efficient, I can disable the unnecesary re-encoding. The command to do this is:
ffmpeg -i test-input.mp4 -ss 00:00:05 -t 00:30:00 -c copy test-output.mp4
-c copy will force the video to be cut as it is without the re-encoding, which makes the operation extremely fast.
Remove Audio from Video Files
I don't know if any one wants to do this - remove the audio from a video file. I do it 5% of all my simple editings. Here is the command:
ffmpeg -i test-input.mp4 -vcodec copy -an test-output.mp4
-an is the option to remove audio.
-vcodec copy forces the operation not to re-encode the video, which makes the operation exgtremely fast.
Change the Dimension of Video Files
The command to change the dimension of a video file is not the best command to use. This one line command uses all the default settings and can lead to low quality videos. But, in case one needs to sdo such a thing. This is the command:
ffmpeg -i test-input.mp4 -vf scale=320:240 test-output.avi
Note that, the only way this can work is to specify the output as *.avi. If you do straight mp4 to mp4. The end result of the output would be no change to the output file.
Concat a Series of Videos into One
The command that concats two or more videos into one would be:
ffmpeg -f concat -i all_vids.txt -codec copy test-output.mp4
all_vids.txt should be a text file that contains all the full path to the source video files. The format of this file should look like this:
c:\testfolder\test-input1.mp4 c:\testfolder\test-input2.mp4 c:\testfolder\test-input3.mp4
When there are a lot of files in this list, the last two minutes of the output video has no audio. Not sure why this happens. So I use professional editing software for this.
That is it. Have fun editing videos.