typedefstructAVFrame{uint8_t*data[AV_NUM_DATA_POINTERS];intlinesize[AV_NUM_DATA_POINTERS];uint8_t**extended_data;intwidth,height;intnb_samples;/* number of audio samples(per channel) described by this frame */intformat;intkey_frame;/* 1->keyframe, 0->not*/enumAVPictureTypepict_type;AVRationalsample_aspect_ratio;int64_tpts;int64_tpkt_pts;int64_tpkt_dts;intcoded_picture_number;intdisplay_picture_number;intquality;void*opaque;/* for some private data of the user */uint64_terror[AV_NUM_DATA_POINTERS];intrepeat_pict;intinterlaced_frame;inttop_field_first;/* If the content is interlaced, is top field displayed first */intpalette_has_changed;int64_treordered_opaque;intsample_rate;/*Sample rate of the audio data*/uint64_tchannel_layout;/*channel layout of the audio data*/AVBufferRef*buf[AV_NUM_DATA_POINTERS];AVBufferRef**extended_buf;intnb_exteneded_buf;AVFrameSideData**side_data;intnb_side_data;intflags;enumAVColorRangecolor_range;enumAVColorPrimariescolor_primaries;enumAVColorTransferCharacteristiccolor_trc;enumAVColorSpacecolorspace;enumAVChromaLocationchroma_location;int64_tbest_effort_timestamp;int64_tpkt_pos;int64_tpkt_duration;AVDictionary*metadata;intdecode_error_flags;intchannels;intpkt_size;AVBufferRef*qp_table_buf;}
typedefstructAVCodec{constchar*name;constchar*long_name;enumAVMediaTypetype;enumAVCodecIDid;intcapabilities;constAVRational*supported_framerates;///< array of supported framerates, or NULL if any, array is terminated by {0,0}constenumAVPixelFormat*pix_fmts;///< array of supported pixel formats, or NULL if unknown, array is terminated by -1constint*supported_samplerates;///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0constenumAVSampleFormat*sample_fmts;///< array of supported sample formats, or NULL if unknown, array is terminated by -1constuint64_t*channel_layouts;///< array of support channel layouts, or NULL if unknown. array is terminated by 0uint8_tmax_lowres;///< maximum value for lowres supported by the decoder, no direct access, use av_codec_get_max_lowres()constAVClass*priv_class;///< AVClass for the private contextconstAVProfile*profiles;///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}intpriv_data_size;structAVCodec*next;int(*init_thread_copy)(AVCodecContext*);int(*update_thread_context)(AVCodecContext*dst,constAVCodecContext*src);constAVCodecDefault*defaults;void(*init_static_data)(structAVCodec*codec);int(*init)(AVCodecContext*);int(*encode_sub)(AVCodecContext*,uint8_t*buf,intbuf_size,int(*encode2)(AVCodecContext*avctx,AVPacket*avpkt,constAVFrame*frame,int*got_packet_ptr);int(*decode)(AVCodecContext*,void*outdata,int*outdata_size,AVPacket*avpkt);int(*close)(AVCodecContext*);void(*flush)(AVCodecContext*);intcaps_internal;}
name:具体的 CODEC 的名称的简短描述,比如”HEVC”/”H264”等。
long_name: CODEC 名称的详细描述,比如”HEVC (High Efficiency Video Coding)”。
AVCodecff_hevc_decoder={.name="hevc",.long_name=NULL_IF_CONFIG_SMALL("HEVC (High Efficiency Video Coding)"),.type=AVMEDIA_TYPE_VIDEO,.id=AV_CODEC_ID_HEVC,.priv_data_size=sizeof(HEVCContext),.priv_class=&hevc_decoder_class,.init=hevc_decode_init,.close=hevc_decode_free,.decode=hevc_decode_frame,.flush=hevc_decode_flush,.update_thread_context=hevc_update_thread_context,.init_thread_copy=hevc_init_thread_copy,.capabilities=AV_CODEC_CAP_DR1|AV_CODEC_CAP_DELAY|AV_CODEC_CAP_SLICE_THREADS|AV_CODEC_CAP_FRAME_THREADS,.profiles=NULL_IF_CONFIG_SMALL(profiles),};
各种不同的编解码器,FFMpeg 使用注册函数avcodec_register_all()来完成。
关于 AVCodec 的通常使用方法:首先,根据特定的 ID 找到特定的编解码器;其次,根据特定的编解码器分配出特定的描述编解码上下文的 AVCodecContext 结构体;之后,打开编解码器;最后,调用编解码器进行编解码。示例代码如下:
typedefstructAVStream{intindex;//stream index in AVFormatContextintid;AVCodecContext*codec;void*priv_data;AVRationaltime_base;int64_tstart_time;int64_tduration;int64_tnb_frames;intdisposition;enumAVDiscarddiscard;AVRationalsample_aspect_ratio;AVDictionary*metadata;AVRationalavg_frame_rate;AVPacketattached_pic;AVPacketSideData*side_data;intnb_side_data;intevent_flags;intpts_wrap_bits;int64_tfirst_dts;int64_tcur_dts;int64_tlast_IP_pts;intlast_IP_duration;intprobe_packets;intcodec_info_nb_frames;/* av_read_frame() support */enumAVStreamParseTypeneed_parsing;structAVCodecParserContext*parser;structAVPacketList*last_in_packet_buffer;AVProbeDataprobe_data;#define MAX_REORDER_DELAY 16int64_tpts_buffer[MAX_REORDER_DELAY+1];AVIndexEntry*index_entries;/**< Only used if the format does not support seeking natively. */intnb_index_entries;unsignedintindex_entries_allocated_size;AVRationalr_frame_rate;intstream_identifier;int64_tinterleaver_chunk_size;int64_tinterleaver_chunk_duration;intrequest_probe;intskip_to_keyframe;intskip_samples;int64_tstart_skip_samples;int64_tfirst_discard_sample;int64_tlast_discard_sample;intnb_decoded_frames;int64_tmux_ts_offset;int64_tpts_wrap_reference;intpts_wrap_behavior;intupdate_initial_durations_done;int64_tpts_reorder_error[MAX_REORDER_DELAY+1];uint8_tpts_reorder_error_count[MAX_REORDER_DELAY+1];int64_tlast_dts_for_order_check;uint8_tdts_ordered;uint8_tdts_misordered;intinject_global_side_data;char*recommended_encoder_configuration;AVRationaldisplay_aspect_ratio;structFFFrac*priv_pts;}AVStream;
typedefstructAVIOContext{constAVClass*av_class;unsignedchar*buffer;/**< Start of the buffer. */intbuffer_size;/**< Maximum buffer size */unsignedchar*buf_ptr;/**< Current position in the buffer */unsignedchar*buf_end;/**< End of the data */int(*read_packet)(void*opaque,uint8_t*buf,intbuf_size);int(*write_packet)(void*opaque,uint8_t*buf,intbuf_size);int64_t(*seek)(void*opaque,int64_toffset,intwhence);int64_tpos;/**< position in the file of the current buffer */intmust_flush;/**< true if the next seek should flush */inteof_reached;/**< true if eof reached */intwrite_flag;/**< true if open for writing */intmax_packet_size;unsignedlongchecksum;unsignedchar*checksum_ptr;unsignedlong(*update_checksum)(unsignedlongchecksum,constuint8_t*buf,unsignedintsize);interror;/**< contains the error code or 0 if no error happened */int(*read_pause)(void*opaque,intpause);int64_t(*read_seek)(void*opaque,intstream_index,int64_ttimestamp,intflags);intseekable;int64_tmaxsize;intdirect;int64_tbytes_read;intseek_count;intwriteout_count;intorig_buffer_size;intshort_seek_threshold;}