From white Wolf Stack: Check out the original
Read the directory
- How did the video get played?
- Ffmpeg command format
- Ffmpeg transcoding output process
How did the video get played?
We know that most players today are redeveloped based on FFMPEG. Have you ever wondered how you see and hear a video when you open it on your player?
Let’s use this diagram to briefly depict the flow of the video being played.
Here’s a little explanation of what this means.
- Unencapsulation: The player separates the input data from the encapsulated formats (MP4, MKV) to create an audio stream and a video stream. Note that these two parts of the data are still compressed data, similar to shunt. Later we will explain how to separate the audio and video from the video file.
- The next step is the decoding operation, we say that decoding is to compress the video and audio encoded data, decode into uncompressed video and audio original data. Here, the audio is decoded to PCM data and the video is decoded to YUV data.
- Audio and video synchronous playback: send the video information and audio and video data obtained by unsealing and decoding respectively to the graphics card and sound card for playback.
Ffmpeg command format
When we introduced transcoding in the basic concepts of audio and Video, we threw a transcoding command as follows
ffmpeg -i input.flv output.mp4
Copy the code
For the basic format of the FFmpeg command, see the ffmpeg official website
ffmpeg [global_options] {[input_file_options] -i input_url} ... {[output_file_options] output_url} ...
Copy the code
Which translates to
Ffmpeg [global options] {[input file options] -i input file}... {[Output file option] Output file}...Copy the code
. Indicates that a command may have multiple inputs and outputs.
For example, we can output multiple files through the input of multiple files transcoding
Ffmpeg-i input1 -i input2 \ -acodec... - vcodec... Output1 \ - acodec... - vcodec... Output2 \ - acodec... - vcodec... output3Copy the code
According to incomplete statistics, the number of options ffMPEG command has tens of thousands of small, so not only to master learning skills, more is more accumulation of experience, by rote memorization is completely impossible.
With so many options, embodied in a single command, a basic general rule is:
The input file option only works on the first input file after it, and naturally, the output file option only works on the first output file after it. So there are order requirements.
The global option can be written arbitrarily. For example, if the global option -y asks us if we want to overwrite the output, we can write it either way
ffmpeg -y -i input.flv output.mp4
ffmpeg -i input.flv -y output.mp4
Copy the code
However, if the command is very long (such as the audio and video example we gave earlier, even several hundred characters in a single command), global options like this are best written before the input file or output file.
In addition, do not write the output file first and then write the input file, at least write the input file, then write the output file, such as the following is not good writing method
ffmpeg output.mp4 -i input.flv
Copy the code
Good habits are the beginning.
Ffmpeg transcoding output process
ffmpeg -i input.flv output.mp4
Copy the code
Or the above simple transcoding command, for such a command, for FFmPEG, and how to deal with it?
We use the following figure to show the transcoding output process.
Detailed description is as follows
- Ffmpeg calls a libavFormat library containing the demultiplexer Demuxer to read the packet containing the encoding from the input file
- The encoded packet is then passed to the decoder (stream replication ignores this step)
- Decoders produce uncompressed frames (i.e. raw frames) that can be further filtered
- Next, the raw data processed by the filter is passed to the encoder
- The encoder encodes the transmitted data and outputs coded packets
- Finally, the data is written to the output file by the multiplexer (Muxer).
Any complex command, must go through the above transcoding process, you can not see the underlying code, but the whole process must be understood.