Latest ffmpeg Source Code Analysis 1: Framework

Source: Internet
Author: User

(Ffmpeg v0.9)


Framework
In the latest ffmpeg version, a new thing was found: avconv, and ffmpeg. c and avconv. c looked like one. Only after a research found that ffmpeg was renamed avconv under libav.

What is the relationship between libav and ffmpeg? I am confused, too.

The main function of ffmpeg is the conversion and processing of audio and video. the power of its functions has reached an incredible level (a bit for it ). its main feature is that it can re-combine any of the several streams in multiple input files into the output file. Of course, there can also be multiple output files.

Therefore, we will find that there are some variables similar to the following in ffmpeg. c:
<Span style = "font-size: 18px;"> static InputStream * input_streams = NULL;
Static int nb_input_streams = 0;
Static InputFile * input_files = NULL;
Static int nb_input_files = 0;
 
 
Static OutputStream * output_streams = NULL;
Static int nb_output_streams = 0;
Static OutputFile * output_files = NULL;
Static int nb_output_files = 0; </span>
<Span style = "font-size: 18px;"> static InputStream * input_streams = NULL;
Static int nb_input_streams = 0;
Static InputFile * input_files = NULL;
Static int nb_input_files = 0;


Static OutputStream * output_streams = NULL;
Static int nb_output_streams = 0;
Static OutputFile * output_files = NULL;
Static int nb_output_files = 0; </span>
Where:
Input_streams is an array of input streams, and nb_input_streams is the number of input streams.
InputFile is an array of input files (or devices), and input_files is the number of input files.
The following output variables do not need to be explained. www.2cto.com

We can see that the files and streams are saved separately. as you can imagine, the structure InputStream should contain the serial number of the file to which it belongs in input_files, and the structure OutputStream should also contain the serial number of the file to which it belongs in output_files. the input stream array should be filled like this: Whenever a stream is found in the input file, it is added to input_streams, therefore, the stream corresponding to an input file is closely related to input_streams. Therefore, the InputFile structure should contain the start sequence number of the first stream in input_streams and the number of streams placed in input_streams, because not all streams in an input file will be transferred to the output file. let's take a look at InputFile:
<Span style = "font-size: 18px;"> typedef struct InputFile {
AVFormatContext * ctx;
Int eof_reached;/* true if eof reached */
Int ist_index;/* index of first stream in input_streams */
Int buffer_size;/* current total buffer size */
Int64_t ts_offset;
Int nb_streams;/* number of stream that ffmpeg is aware of; may be different
From ctx. nb_streams if new streams appear during av_read_frame ()*/
Int rate_emu;
} InputFile; </span>
<Span style = "font-size: 18px;"> typedef struct InputFile {
AVFormatContext * ctx;
Int eof_reached;/* true if eof reached */
Int ist_index;/* index of first stream in input_streams */
Int buffer_size;/* current total buffer size */
Int64_t ts_offset;
Int nb_streams;/* number of stream that ffmpeg is aware of; may be different
From ctx. nb_streams if new streams appear during av_read_frame ()*/
Int rate_emu;
} InputFile; </span>
Note the ist_index and nb_streams.

In the output stream, in addition to saving the serial number of the output file in output_files, the serial number of the corresponding input stream in input_streams should also be saved, the sequence number of the stream in the output file should also be saved. in the output file, you only need to save the sequence number of its first stream in output_streams. But why not save the number of streams in the output file? I do not know, but I know that it does not need to be saved or affect the implementation function (hey, It is not said ).
You can see how ffmpeg can regroup any stream in multiple files and add it to the output file?

The stream and file are ready. Here is the conversion. What is the conversion process? Let me guess:
First open the input files, then prepare and open the decoder with the data input stream, then prepare and open the encoder with the data output stream, and then create the output files, then write the header for all output files, convert the input stream to the output stream in the loop, and write it to the output file. After the conversion, jump out of the loop and write it to the end of the file, close all output files.


Here is the overview. Several important functions will be analyzed in detail later.


From the column of nkmnkm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.