Forward from White Wolf Stack: See the original article
Read the directory
- How was the video played?
- The format of the FFmpeg command
- The process of FFMPEG transcoding output
How was the video played?
As we know, most players today are redeveloped based on FFMPEG. Have you ever wondered, when you open a video on your player, how you see the picture and how you hear the sound?
Let’s use this diagram to briefly describe the flow of the video being played.
Here’s a little explanation of what the picture below means.
- Unencapsulated: The player separates the input data in encapsulated formats (MP4, MKV) to produce audio stream and video stream. Note that these two parts of the data are still compressed data, similar to streaming. We will also introduce how to extract audio and video from video files later.
- The next step is the decoding operation. We say decoding is to compress the encoded data of video and audio into uncompressed original data of video and audio. Here, audio is decoded into PCM format data and video is decoded into YUV format data.
- Audio and video synchronous playback: the video information and audio and video data obtained by unsealing and decoding are sent to the video card and sound card for playback.
The format of the FFmpeg command
When we introduced transcoding in the basic concept of audio and video article, we threw a command to transcode, as follows
ffmpeg -i input.flv output.mp4
For the basic format of the FFMPEG command, refer to the FFMPEG website
ffmpeg [global_options] {[input_file_options] -i input_url} ... {[output_file_options] output_url} ...
That translates to
Ffmpeg [global options] {[input file options] -i input file}... {[Output File Options] Output File}...
. Indicates that a command may have multiple inputs and outputs.
For example, we can output multiple files through the input of transcoding
Ffmpeg - I input1 - I input2 \ -acodec... - vcodec... Output1 \ - acodec... - vcodec... Output2 \ - acodec... - vcodec... output3
According to incomplete statistics, the number of options of FFMPEG command is small tens of thousands, so not only to master more learning skills, more is to accumulate experience, by rote memorization is completely impossible.
With so many options in a single command, the basic general rule is:
The input file option only applies to the first input file that follows it. Naturally, the output file option only applies to the first output file that follows it. So there’s an order requirement.
For example, if the global option -y asks us if we want to override the output, we can write it either way
ffmpeg -y -i input.flv output.mp4
ffmpeg -i input.flv -y output.mp4
However, if the commands are very long (like the audio and video examples we gave earlier, where a single command can be hundreds of characters), such global options are best written in front of the input file or the output file.
Also, never write an output file before you write an input file. At the very least, you should write an input file before you write an output file. This is not good writing
ffmpeg output.mp4 -i input.flv
Good habits are a good start.
The process of FFMPEG transcoding output
ffmpeg -i input.flv output.mp4
Again, this simple transcoding command above, for a command like this, for FFMPEG, what do you do?
We use the following diagram to represent the process of transcoding output.
The details are described as follows
- FFmpeg calls a LibavFormat library that contains the demuxer demultiplexer and reads the packets containing the encoding from the input file
- The encoded packet is then passed to the decoder (this step is ignored in stream replication operations)
- The decoder produces uncompressed frames that can be further processed by the filter
- Next, the raw data processed by the filter is passed to the encoder.
- The encoder encodes the incoming data and outputs the encoded data packet
- Finally, this data is written to an output file by the multiplexer (MUXER).
Any complex command must go through the above transcoding process, you can not look at the underlying code, but the whole process must be understood.