FFmpeg structure of FFMPEG-0.11.1 analysis (simple) and Code flow (mainly involved in the preparation of the previous part)

Source: Internet
Author: User

1. Directory of each sub-module in the FFMPEG main directory, omitted.

2. The format, protocol, and CODEC module can be plugin and have their own unified structure types. The open interfaces corresponding to the modules are defined in it. Here, muxer and demuxer have different structures: avoutputformat and avinputformat. encoder and decoder use the avcodec structure and the Protocol is urlprotocol.

3. [Next let's look at FFMPEG. C]

4. ViewRegistration ProcessThe related functions include callback, callback, expires, and av_register_all. Pay attention to the following global static variables: libavutils/utils. cfirst_avcodec, libavutils/utils. cfirst_hwaccel, libavcodec/parser. c
Av_first_parser, libavcodec/bitstream_filter.c first_bitstream_filter, avdevice_register_all (libavformat/utils. cfirst_iformat, first_oformat), avfilter_register_all (libavfilter/avfilter. cregistered_avfilters), av_register_all (avcodec_register_all (), libavformat/utils. cfirst_iformat, first_oformat, libavformat/avio. cfirst_protocol), which of the registered modules and sub-modules are not much said, registration is actually to build a linked list structure, for example, codec, not every format should be encoded, decoded, therefore, encoder and decoder are separated. Registered. Others are similar.

5. Let's take a look at the match of demuxer:

(Interrupt here, by the way, it should be noted that the Command Parsing in FFMPEG has been omitted in the previous chapter.) The command corresponds to the parsing function, which can be seen in const optiondef options, of course, some directly assigned values are not needed, but-I is not used. Therefore, the former corresponds to the opt_input_file function, and the latter corresponds to the opt_output_file function as the function callback.

First look at the call relationship: parse_options-opt_input_file-avformat_open_input-init_input-av_probe_input_format-av_probe_input_format2-av_probe_input_format3, the prototype is avinputformat * partition (avprobedata * PD, int is_opened, int * score_ret), which according to the passed probe_data data, with av_iformat_next traversal chain table first_iformat, call the read_probe interface of demuxer (avinputformat) in sequence to match the input file format with demuxer, and return the avinputformat * pointer.

In the opt_input_file function, if (o-> Format) and format correspond to avinputformat. Name, and then a series of IF Statements are omitted.

Here if the input is streaming media, is opened in the init_input-avio_open2-ffurl_open, and then the protocol is stripped, In the av_probe_input_buffer-av_probe_input_format2 ...... Detection format. This will be discussed later, in order of modules.

6. Let's see the muxer match:

Call relationship: opt_output_file-avformat_alloc_output_context2-av_guess_format, prototype is avoutputformat * av_guess_format (const char * short_name, const char * filename, const char * mime_type ), it is specified based on the suffix of the input parameter or the-F format.

7. Now let's look at the matching of the current encoder/decoder:

Decoder is completed in opt_input_file until it is completed in bytes. encoder is actually opt_input_file-new_video_stream-new_output_stream-choose_encoder-audio. The audio has new_audio_stream, which is stored in. avinputformat. avstream. avcodeccontext. avcodec * codec and avformatcontext.
Avoutputformat. avstream. avcodeccontext. avcodec * codec variable.

8. There are several important structures, or variables:

Static inputfile ** input_files and static outputfile ** output_files. The output struct avinputformat * iformat; struct avoutputformat * oformat; Is In avformatcontext, for an avformatcontext context, Demux and MUX cannot exist at the same time (notboth at the same time is written in the structure comment). Therefore, they initialize and seal them in the inputfile structure respectively, previously, it was directly: static
Avformatcontext * input_files [max_files].

 

Static inputstream ** input_streams and staticoutputstream ** output_streams are discussed later.

 

Avstream stores the decoder, data, and other information associated with the data stream. In the structure, avcodeccontext * codec, which is related to (7. What about the priv_data pointer? Let's look at an encoder. For example, in the first sentence of ff_h1__decoder. ff_h1__decode_init (the prototype is avcodeccontext * avctx), h1_context * H = avctx-> priv_data.

 

Others such as avinputstream, avpacket, and avframe will not round them in sequence.

9. [it is necessary to mention that the module sequence of FFMPEG for streaming media transcoding is as follows: URL (Protocol) à io (read) à Demux (Format) à ^ transcode ^ à MUX à io (write) à URL (Protocol), which contains decoder à scaler à encoder]

10. When I/O (read) matches demuxer in opt_input_file, filename first passes in ffurl_open. If averror_protocol_not_found is returned, it may be localfile. Otherwise, the network media is used. Io (write) is opened in opt_output_file, avio_open2 (avio_flag_write ).

11. at this point, the module is basically ready, and the scaling is swscale. Now the new FFMPEG version has the filter, which will be used later. Similar to Microsoft's dshow, if it is used for development, the structure is still very good, however, filters shared on the Internet must be well managed and controlled.

[This is a big copy of the world's articles. It is inevitable that you will learn from others. Since the ideas can be organized by others, why not borrow them! If the source code is reprinted, it is also possible to describe the source code, just like using open source code as a product. Despite the chaos in China, many old people have not been abolished, and many "rules" have not yet been formulated, so we still have to be honest .]

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.