FFmpeg codec usage Summary

Source: Internet
Author: User

 

Category:
Video coding and decoding Technology
283 reading comments (0)
Favorites
Report

FFmpeg provides many encoder and decoder. For details, see the enumerated variable codecid in avcodec. h.

 

Macro definition

# Define register_encoder (x, x ){/
Extern avcodec x ##_ encoder ;/
If (# x ###_ encoder) avcodec_register (& X ##_ encoder );}

 

# Define register_decoder (x, x ){/
Extern avcodec x ##_ decoder ;/
If (# codec_id _ # X #) avcodec_register (& X ##_ decoder );}

 

For example:

Register_decoder (h264, h264 );

It is equivalent to extern avcodec hsf-_decoder;

If (codec_id_h264)

Avcodec_register (& hsf-_decoder );

 

The actual functions of these three lines of code are as follows:

Avcodec codec;

Codec = & hsf-_decoder;

 

After codec is configured,

Define the global variable avcodeccontext * avctx;

Then avctx-> codec = codec;

 

In the future, you can call common APIs:

Avctx-> codec-> init Initialization

Avctx-> codec-> decode Decoding

Or avctx-> codec-> encode Encoding

Avctx-> codec-> close

Encoding or decoding

 

Codec is a struct and is defined as follows:

Typedef struct avcodec {
Const char * Name;
Enum codectype type;
Enum codecid ID;
Int priv_data_size;
INT (* init) (avcodeccontext *); // initialize the Function
INT (* encode) (avcodeccontext *, uint8_t * Buf, int buf_size, void * data );
// Encoding function
INT (* close) (avcodeccontext *); // close the Function
INT (* decode) (avcodeccontext *, void * outdata, int * outdata_size, avpacket * avpkt );
// Decoding function

For different codec, the three APIs correspond to different functions.

For codec_id_h264, hsf-_decoder is defined

 

Avcodec hsf-_decoder = {
"H264 ",
Codec_type_video,
Codec_id_h264,
Sizeof (hsf-context ),
Decode_init,
Null,
Decode_end,
Decode_frame,

}

The definition of codec_id_h263 and h263_decoder is as follows:

Avcodec h263_decoder = {
"H263 ",
Codec_type_video,
Codec_id_h263,
Sizeof (mpegenccontext ),
Ff_h263_decode_init,
Null,
Ff_h263_decode_end,
Ff_h263_decode_frame,
Codec_cap_draw_horiz_band | codec_cap_dr1 | codec_cap_truncated | codec_cap_delay,
//. Flush = ff_mpeg_flush,
//. Long_name = null_if_config_small ("H.263/H.263-1996, H.263 +/H.263-1998/H.263 Version 2 "),
//. Pix_fmts = ff_hwaccel_pixfmt_list_420,
};

 

The definition of codec_id_mpeg4 and mpeg4_decoder is as follows:

Avcodec mpeg4_decoder = {
"MPEG4 ",
Codec_type_video,
Codec_id_mpeg4,
Sizeof (mpegenccontext ),
Ff_h263_decode_init,
Null,
Ff_h263_decode_end,
Ff_h263_decode_frame,
Codec_cap_draw_horiz_band | codec_cap_dr1 | codec_cap_truncated | codec_cap_delay,
//. Flush = ff_mpeg_flush,
//. Long_name = null_if_config_small ("MPEG-4 Part 2 "),
//. Pix_fmts = ff_hwaccel_pixfmt_list_420,
};

 

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.