1. Some commands cannot be used simultaneously
For example: Areverse when specifying that the audio encoding of the video file is copy
ffmpeg -i in.mp4 -vcodec copy -acodec copy -af areverse out.mp4
Copy the code
Error: Filtergraph'reverse' was defined for audio output stream 0:1 but codec copy was selected.
Filtering and streamcopy cannot be used together.
Copy the code
Reverse if the encoding mode of the specified video file is copy
ffmpeg -i in.mp4 -vcodec copy -acodec copy -vf reverse out.mp4
Copy the code
Note that this is only true if the encoding mode is copy, but OK if it is changed to another encoding mode, such as the following:
// Set the video encoder to libx264, and the reverse command ffmpeg -I in.mp4 -vcodec libx264-libx264-preset fast-VF reverse out6.mp4 can be used simultaneouslyCopy the code
In this way, it seems that there will be no problems mentioned before, but there may also be new disadvantages, please continue to see the following questions:
2. Reduce unnecessary coding
When only the specified code stream is processed, the stream that does not need to be processed is directly copied to the original encoding mode, which can save the encoding time again.
For example, to re-encode the video stream while removing audio:
ffmpeg -i in.mp4 -vcodec libx264 -preset fast -an out.mp4
Copy the code
This loop results in frame-by-frame recoding, which can take a lot of execution time even with libx264’s fast encoding:
And if the original video encoding mode is directly copied:
ffmpeg -i in.mp4 -vcodec copy -an out.mp4
Copy the code
It can be said that second compilation, speed and the above is a day difference, so we must pay attention to specify the encoding method to determine whether it is necessary to re-encode, direct copy will be much faster.
Similarly, if the encoding mode is not changed when removing the video track, the following will also be much faster:
ffmpeg -i in.mp4 -vcodec libx264 -preset fast -acodec copy -vn out4.mp4
Copy the code
Note, however, that if the video stream is reversed, even the original encoding method will be re-encoded frame by frame, so it is also possible to specify a new encoding method. For example, if the video stream is reversed, specify the encoder as libx264:
ffmpeg -i in.mp4 -vcodec libx264 -preset fast -acodec copy -vf reverse out.mp4
Copy the code
Compare to direct copy encoding for compiling:
ffmpeg -i in.mp4 -vf reverse out9.mp4
Copy the code
At this point, it’s not clear who is faster or slower, but there are scenarios where x264 is more maneuverable.
3. Pay attention to potential conditions for executing the command
In some cases, there are potential conditions for command execution, such as reversing the audio track when we want to convert a video file to an audio file. In addition to the obvious file format conversion, there is also a potential condition for removing the video track and leaving only the audio track processing. If the preconditions of removing video track are satisfied, the extra video coding process in format conversion can be reduced.
We can test the specific effects:
ffmpeg -i in.mp4 -af areverse out1.mp3
Copy the code