AV系列结构体之AVCodec、AVCodecParameters、AVCodecParser、AVCodecParserContext、AVCodecDescriptor - 图1

    AVCodec: 编解码器结构体
    位于libavcodec/avcodec.h中

    1. typedef struct AVCodec {
    2. const char *name; // codec的名字,保持全局唯一,标识名
    3. const char *long_name; // codec的名字,全名
    4. enum AVMediaType type; // Media类型,是视频,音频,还是字幕
    5. enum AVCodecID id;
    6. int capabilities; // codec的容量,参考 AV_CODEC_CAP_*
    7. const AVRational *supported_framerates; //支持的帧率,如果是null,返回是{0,0}
    8. const enum AVPixelFormat *pix_fmts; //支持的像素格式,如果是null或unknown,返回-1
    9. const int *supported_samplerates; //支持的采样率,如果是null或unknown,返回0
    10. const enum AVSampleFormat *sample_fmts; //支持的采样率,如果是null,返回-1
    11. const uint64_t *channel_layouts; //支持的声道数, 如果是null,返回0
    12. uint8_t max_lowres; //解码器支持的最大lowres
    13. const AVClass *priv_class; //定义AVClass 成员变量
    14. const AVProfile *profiles; //定义AVProfile 成员变量
    15. /*****************************************************************
    16. * No fields below this line are part of the public API. They
    17. * may not be used outside of libavcodec and can be changed and
    18. * removed at will.
    19. * New public fields should be added right above.
    20. *****************************************************************
    21. */
    22. int priv_data_size;
    23. struct AVCodec *next;
    24. /**
    25. * @name Frame-level threading support functions
    26. * @{
    27. */
    28. /**
    29. * If defined, called on thread contexts when they are created.
    30. * If the codec allocates writable tables in init(), re-allocate them here.
    31. * priv_data will be set to a copy of the original.
    32. */
    33. int (*init_thread_copy)(AVCodecContext *);
    34. /**
    35. * Copy necessary context variables from a previous thread context to the current one.
    36. * If not defined, the next thread will start automatically; otherwise, the codec
    37. * must call ff_thread_finish_setup().
    38. *
    39. * dst and src will (rarely) point to the same context, in which case memcpy should be skipped.
    40. */
    41. int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src);
    42. /** @} */
    43. /**
    44. * Private codec-specific defaults.
    45. */
    46. const AVCodecDefault *defaults;
    47. /**
    48. * Initialize codec static data, called from avcodec_register().
    49. */
    50. void (*init_static_data)(struct AVCodec *codec);
    51. int (*init)(AVCodecContext *);
    52. int (*encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size,
    53. const struct AVSubtitle *sub);
    54. /**
    55. * Encode data to an AVPacket.
    56. *
    57. * @param avctx codec context
    58. * @param avpkt output AVPacket (may contain a user-provided buffer)
    59. * @param[in] frame AVFrame containing the raw data to be encoded
    60. * @param[out] got_packet_ptr encoder sets to 0 or 1 to indicate that a
    61. * non-empty packet was returned in avpkt.
    62. * @return 0 on success, negative error code on failure
    63. */
    64. int (*encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame,
    65. int *got_packet_ptr);
    66. int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt);
    67. int (*close)(AVCodecContext *);
    68. /**
    69. * Decode/encode API with decoupled packet/frame dataflow. The API is the
    70. * same as the avcodec_ prefixed APIs (avcodec_send_frame() etc.), except
    71. * that:
    72. * - never called if the codec is closed or the wrong type,
    73. * - AVPacket parameter change side data is applied right before calling
    74. * AVCodec->send_packet,
    75. * - if AV_CODEC_CAP_DELAY is not set, drain packets or frames are never sent,
    76. * - only one drain packet is ever passed down (until the next flush()),
    77. * - a drain AVPacket is always NULL (no need to check for avpkt->size).
    78. */
    79. int (*send_frame)(AVCodecContext *avctx, const AVFrame *frame);
    80. int (*send_packet)(AVCodecContext *avctx, const AVPacket *avpkt);
    81. int (*receive_frame)(AVCodecContext *avctx, AVFrame *frame);
    82. int (*receive_packet)(AVCodecContext *avctx, AVPacket *avpkt);
    83. /**
    84. * Flush buffers.
    85. * Will be called when seeking
    86. */
    87. void (*flush)(AVCodecContext *);
    88. /**
    89. * Internal codec capabilities.
    90. * See FF_CODEC_CAP_* in internal.h
    91. */
    92. int caps_internal;
    93. } AVCodec;

    AVCodecParameters:描述一个解码后的流的属性
    sizeof(AVCodecParameters),并不是public的api, 这个结构必须通过avcodec_parameters_alloc()分配空间,通过avcodec_parameters_free()释放空间。

    1. typedef struct AVCodecParameters {
    2. /**
    3. * General type of the encoded data.
    4. */
    5. enum AVMediaType codec_type;
    6. /**
    7. * Specific type of the encoded data (the codec used).
    8. */
    9. enum AVCodecID codec_id;
    10. /**
    11. * Additional information about the codec (corresponds to the AVI FOURCC).
    12. */
    13. uint32_t codec_tag;
    14. /**
    15. * Extra binary data needed for initializing the decoder, codec-dependent.
    16. *
    17. * Must be allocated with av_malloc() and will be freed by
    18. * avcodec_parameters_free(). The allocated size of extradata must be at
    19. * least extradata_size + AV_INPUT_BUFFER_PADDING_SIZE, with the padding
    20. * bytes zeroed.
    21. */
    22. uint8_t *extradata;
    23. /**
    24. * Size of the extradata content in bytes.
    25. */
    26. int extradata_size;
    27. /**
    28. * - video: the pixel format, the value corresponds to enum AVPixelFormat.
    29. * - audio: the sample format, the value corresponds to enum AVSampleFormat.
    30. */
    31. int format;
    32. /**
    33. * The average bitrate of the encoded data (in bits per second).
    34. */
    35. int64_t bit_rate;
    36. /**
    37. * The number of bits per sample in the codedwords.
    38. *
    39. * This is basically the bitrate per sample. It is mandatory for a bunch of
    40. * formats to actually decode them. It's the number of bits for one sample in
    41. * the actual coded bitstream.
    42. *
    43. * This could be for example 4 for ADPCM
    44. * For PCM formats this matches bits_per_raw_sample
    45. * Can be 0
    46. */
    47. int bits_per_coded_sample;
    48. /**
    49. * This is the number of valid bits in each output sample. If the
    50. * sample format has more bits, the least significant bits are additional
    51. * padding bits, which are always 0. Use right shifts to reduce the sample
    52. * to its actual size. For example, audio formats with 24 bit samples will
    53. * have bits_per_raw_sample set to 24, and format set to AV_SAMPLE_FMT_S32.
    54. * To get the original sample use "(int32_t)sample >> 8"."
    55. *
    56. * For ADPCM this might be 12 or 16 or similar
    57. * Can be 0
    58. */
    59. int bits_per_raw_sample;
    60. /**
    61. * Codec-specific bitstream restrictions that the stream conforms to.
    62. */
    63. int profile;
    64. int level;
    65. /**
    66. * Video only. The dimensions of the video frame in pixels.
    67. */
    68. int width;
    69. int height;
    70. /**
    71. * Video only. The aspect ratio (width / height) which a single pixel
    72. * should have when displayed.
    73. *
    74. * When the aspect ratio is unknown / undefined, the numerator should be
    75. * set to 0 (the denominator may have any value).
    76. */
    77. AVRational sample_aspect_ratio;
    78. /**
    79. * Video only. The order of the fields in interlaced video.
    80. */
    81. enum AVFieldOrder field_order;
    82. /**
    83. * Video only. Additional colorspace characteristics.
    84. */
    85. enum AVColorRange color_range;
    86. enum AVColorPrimaries color_primaries;
    87. enum AVColorTransferCharacteristic color_trc;
    88. enum AVColorSpace color_space;
    89. enum AVChromaLocation chroma_location;
    90. /**
    91. * Video only. Number of delayed frames.
    92. */
    93. int video_delay;
    94. /**
    95. * Audio only. The channel layout bitmask. May be 0 if the channel layout is
    96. * unknown or unspecified, otherwise the number of bits set must be equal to
    97. * the channels field.
    98. */
    99. uint64_t channel_layout;
    100. /**
    101. * Audio only. The number of audio channels.
    102. */
    103. int channels;
    104. /**
    105. * Audio only. The number of audio samples per second.
    106. */
    107. int sample_rate;
    108. /**
    109. * Audio only. The number of bytes per coded audio frame, required by some
    110. * formats.
    111. *
    112. * Corresponds to nBlockAlign in WAVEFORMATEX.
    113. */
    114. int block_align;
    115. /**
    116. * Audio only. Audio frame size, if known. Required by some formats to be static.
    117. */
    118. int frame_size;
    119. /**
    120. * Audio only. The amount of padding (in samples) inserted by the encoder at
    121. * the beginning of the audio. I.e. this number of leading decoded samples
    122. * must be discarded by the caller to get the original audio without leading
    123. * padding.
    124. */
    125. int initial_padding;
    126. /**
    127. * Audio only. The amount of padding (in samples) appended by the encoder to
    128. * the end of the audio. I.e. this number of decoded samples must be
    129. * discarded by the caller from the end of the stream to get the original
    130. * audio without any trailing padding.
    131. */
    132. int trailing_padding;
    133. /**
    134. * Audio only. Number of samples to skip after a discontinuity.
    135. */
    136. int seek_preroll;
    137. } AVCodecParameters;

    AVCodecParser

    1. typedef struct AVCodecParser {
    2. int codec_ids[5]; /* several codec IDs are permitted */
    3. int priv_data_size;
    4. int (*parser_init)(AVCodecParserContext *s);
    5. /* This callback never returns an error, a negative value means that
    6. * the frame start was in a previous packet. */
    7. int (*parser_parse)(AVCodecParserContext *s,
    8. AVCodecContext *avctx,
    9. const uint8_t **poutbuf, int *poutbuf_size,
    10. const uint8_t *buf, int buf_size);
    11. void (*parser_close)(AVCodecParserContext *s);
    12. int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size);
    13. struct AVCodecParser *next;
    14. } AVCodecParser;

    AVCodecParserContext :Frame parsing

    1. typedef struct AVCodecParserContext {
    2. void *priv_data;
    3. struct AVCodecParser *parser;
    4. int64_t frame_offset; /* offset of the current frame */
    5. int64_t cur_offset; /* current offset
    6. (incremented by each av_parser_parse()) */
    7. int64_t next_frame_offset; /* offset of the next frame */
    8. /* video info */
    9. int pict_type; /* XXX: Put it back in AVCodecContext. */
    10. /**
    11. * This field is used for proper frame duration computation in lavf.
    12. * It signals, how much longer the frame duration of the current frame
    13. * is compared to normal frame duration.
    14. *
    15. * frame_duration = (1 + repeat_pict) * time_base
    16. *
    17. * It is used by codecs like H.264 to display telecined material.
    18. */
    19. int repeat_pict; /* XXX: Put it back in AVCodecContext. */
    20. int64_t pts; /* pts of the current frame */
    21. int64_t dts; /* dts of the current frame */
    22. /* private data */
    23. int64_t last_pts;
    24. int64_t last_dts;
    25. int fetch_timestamp;
    26. #define AV_PARSER_PTS_NB 4
    27. int cur_frame_start_index;
    28. int64_t cur_frame_offset[AV_PARSER_PTS_NB];
    29. int64_t cur_frame_pts[AV_PARSER_PTS_NB];
    30. int64_t cur_frame_dts[AV_PARSER_PTS_NB];
    31. int flags;
    32. #define PARSER_FLAG_COMPLETE_FRAMES 0x0001
    33. #define PARSER_FLAG_ONCE 0x0002
    34. /// Set if the parser has a valid file offset
    35. #define PARSER_FLAG_FETCHED_OFFSET 0x0004
    36. #define PARSER_FLAG_USE_CODEC_TS 0x1000
    37. int64_t offset; ///< byte offset from starting packet start
    38. int64_t cur_frame_end[AV_PARSER_PTS_NB];
    39. /**
    40. * Set by parser to 1 for key frames and 0 for non-key frames.
    41. * It is initialized to -1, so if the parser doesn't set this flag,
    42. * old-style fallback using AV_PICTURE_TYPE_I picture type as key frames
    43. * will be used.
    44. */
    45. int key_frame;
    46. #if FF_API_CONVERGENCE_DURATION
    47. /**
    48. * @deprecated unused
    49. */
    50. attribute_deprecated
    51. int64_t convergence_duration;
    52. #endif
    53. // Timestamp generation support:
    54. /**
    55. * Synchronization point for start of timestamp generation.
    56. *
    57. * Set to >0 for sync point, 0 for no sync point and <0 for undefined
    58. * (default).
    59. *
    60. * For example, this corresponds to presence of H.264 buffering period
    61. * SEI message.
    62. */
    63. int dts_sync_point;
    64. /**
    65. * Offset of the current timestamp against last timestamp sync point in
    66. * units of AVCodecContext.time_base.
    67. *
    68. * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
    69. * contain a valid timestamp offset.
    70. *
    71. * Note that the timestamp of sync point has usually a nonzero
    72. * dts_ref_dts_delta, which refers to the previous sync point. Offset of
    73. * the next frame after timestamp sync point will be usually 1.
    74. *
    75. * For example, this corresponds to H.264 cpb_removal_delay.
    76. */
    77. int dts_ref_dts_delta;
    78. /**
    79. * Presentation delay of current frame in units of AVCodecContext.time_base.
    80. *
    81. * Set to INT_MIN when dts_sync_point unused. Otherwise, it must
    82. * contain valid non-negative timestamp delta (presentation time of a frame
    83. * must not lie in the past).
    84. *
    85. * This delay represents the difference between decoding and presentation
    86. * time of the frame.
    87. *
    88. * For example, this corresponds to H.264 dpb_output_delay.
    89. */
    90. int pts_dts_delta;
    91. /**
    92. * Position of the packet in file.
    93. *
    94. * Analogous to cur_frame_pts/dts
    95. */
    96. int64_t cur_frame_pos[AV_PARSER_PTS_NB];
    97. /**
    98. * Byte position of currently parsed frame in stream.
    99. */
    100. int64_t pos;
    101. /**
    102. * Previous frame byte position.
    103. */
    104. int64_t last_pos;
    105. /**
    106. * Duration of the current frame.
    107. * For audio, this is in units of 1 / AVCodecContext.sample_rate.
    108. * For all other types, this is in units of AVCodecContext.time_base.
    109. */
    110. int duration;
    111. enum AVFieldOrder field_order;
    112. /**
    113. * Indicate whether a picture is coded as a frame, top field or bottom field.
    114. *
    115. * For example, H.264 field_pic_flag equal to 0 corresponds to
    116. * AV_PICTURE_STRUCTURE_FRAME. An H.264 picture with field_pic_flag
    117. * equal to 1 and bottom_field_flag equal to 0 corresponds to
    118. * AV_PICTURE_STRUCTURE_TOP_FIELD.
    119. */
    120. enum AVPictureStructure picture_structure;
    121. /**
    122. * Picture number incremented in presentation or output order.
    123. * This field may be reinitialized at the first picture of a new sequence.
    124. *
    125. * For example, this corresponds to H.264 PicOrderCnt.
    126. */
    127. int output_picture_number;
    128. /**
    129. * Dimensions of the decoded video intended for presentation.
    130. */
    131. int width;
    132. int height;
    133. /**
    134. * Dimensions of the coded video.
    135. */
    136. int coded_width;
    137. int coded_height;
    138. /**
    139. * The format of the coded data, corresponds to enum AVPixelFormat for video
    140. * and for enum AVSampleFormat for audio.
    141. *
    142. * Note that a decoder can have considerable freedom in how exactly it
    143. * decodes the data, so the format reported here might be different from the
    144. * one returned by a decoder.
    145. */
    146. int format;
    147. } AVCodecParserContext;

    AVCodecDescriptor:描述单个解码器的属性,单个解码器被描述是通过AVCodecID

    1. typedef struct AVCodecDescriptor {
    2. enum AVCodecID id;
    3. enum AVMediaType type;
    4. const char *name;
    5. const char *long_name;
    6. /**
    7. * Codec properties, a combination of AV_CODEC_PROP_* flags.
    8. */
    9. int props;
    10. /**
    11. * MIME type(s) associated with the codec.
    12. * May be NULL; if not, a NULL-terminated array of MIME types.
    13. * The first item is always non-NULL and is the preferred MIME type.
    14. */
    15. const char *const *mime_types;
    16. /**
    17. * If non-NULL, an array of profiles recognized for this codec.
    18. * Terminated with FF_PROFILE_UNKNOWN.
    19. */
    20. const struct AVProfile *profiles;
    21. } AVCodecDescriptor;

    AVCodecID:枚举出FFmpeg所有解码器id

    1. enum AVCodecID {
    2. AV_CODEC_ID_NONE,
    3. /* video codecs */
    4. AV_CODEC_ID_MPEG1VIDEO,
    5. AV_CODEC_ID_MPEG2VIDEO, ///< preferred ID for MPEG-1/2 video decoding
    6. #if FF_API_XVMC
    7. AV_CODEC_ID_MPEG2VIDEO_XVMC,
    8. #endif /* FF_API_XVMC */
    9. AV_CODEC_ID_H261,
    10. AV_CODEC_ID_H263,
    11. AV_CODEC_ID_RV10,
    12. AV_CODEC_ID_RV20,
    13. AV_CODEC_ID_MJPEG,
    14. AV_CODEC_ID_MJPEGB,
    15. AV_CODEC_ID_LJPEG,
    16. AV_CODEC_ID_SP5X,
    17. AV_CODEC_ID_JPEGLS,
    18. AV_CODEC_ID_MPEG4,
    19. AV_CODEC_ID_RAWVIDEO,
    20. AV_CODEC_ID_MSMPEG4V1,
    21. AV_CODEC_ID_MSMPEG4V2,
    22. AV_CODEC_ID_MSMPEG4V3,
    23. AV_CODEC_ID_WMV1,
    24. AV_CODEC_ID_WMV2,
    25. AV_CODEC_ID_H263P,
    26. AV_CODEC_ID_H263I,
    27. AV_CODEC_ID_FLV1,
    28. AV_CODEC_ID_SVQ1,
    29. AV_CODEC_ID_SVQ3,
    30. AV_CODEC_ID_DVVIDEO,
    31. AV_CODEC_ID_HUFFYUV,
    32. AV_CODEC_ID_CYUV,
    33. AV_CODEC_ID_H264,
    34. AV_CODEC_ID_INDEO3,
    35. AV_CODEC_ID_VP3,
    36. AV_CODEC_ID_THEORA,
    37. AV_CODEC_ID_ASV1,
    38. AV_CODEC_ID_ASV2,
    39. AV_CODEC_ID_FFV1,
    40. AV_CODEC_ID_4XM,
    41. AV_CODEC_ID_VCR1,
    42. AV_CODEC_ID_CLJR,
    43. AV_CODEC_ID_MDEC,
    44. AV_CODEC_ID_ROQ,
    45. AV_CODEC_ID_INTERPLAY_VIDEO,
    46. AV_CODEC_ID_XAN_WC3,
    47. AV_CODEC_ID_XAN_WC4,
    48. AV_CODEC_ID_RPZA,
    49. AV_CODEC_ID_CINEPAK,
    50. AV_CODEC_ID_WS_VQA,
    51. AV_CODEC_ID_MSRLE,
    52. AV_CODEC_ID_MSVIDEO1,
    53. AV_CODEC_ID_IDCIN,
    54. AV_CODEC_ID_8BPS,
    55. AV_CODEC_ID_SMC,
    56. AV_CODEC_ID_FLIC,
    57. AV_CODEC_ID_TRUEMOTION1,
    58. AV_CODEC_ID_VMDVIDEO,
    59. AV_CODEC_ID_MSZH,
    60. AV_CODEC_ID_ZLIB,
    61. AV_CODEC_ID_QTRLE,
    62. AV_CODEC_ID_TSCC,
    63. AV_CODEC_ID_ULTI,
    64. AV_CODEC_ID_QDRAW,
    65. AV_CODEC_ID_VIXL,
    66. AV_CODEC_ID_QPEG,
    67. AV_CODEC_ID_PNG,
    68. AV_CODEC_ID_PPM,
    69. AV_CODEC_ID_PBM,
    70. AV_CODEC_ID_PGM,
    71. AV_CODEC_ID_PGMYUV,
    72. AV_CODEC_ID_PAM,
    73. AV_CODEC_ID_FFVHUFF,
    74. AV_CODEC_ID_RV30,
    75. AV_CODEC_ID_RV40,
    76. AV_CODEC_ID_VC1,
    77. AV_CODEC_ID_WMV3,
    78. AV_CODEC_ID_LOCO,
    79. AV_CODEC_ID_WNV1,
    80. AV_CODEC_ID_AASC,
    81. AV_CODEC_ID_INDEO2,
    82. AV_CODEC_ID_FRAPS,
    83. AV_CODEC_ID_TRUEMOTION2,
    84. AV_CODEC_ID_BMP,
    85. AV_CODEC_ID_CSCD,
    86. AV_CODEC_ID_MMVIDEO,
    87. AV_CODEC_ID_ZMBV,
    88. AV_CODEC_ID_AVS,
    89. AV_CODEC_ID_SMACKVIDEO,
    90. AV_CODEC_ID_NUV,
    91. AV_CODEC_ID_KMVC,
    92. AV_CODEC_ID_FLASHSV,
    93. AV_CODEC_ID_CAVS,
    94. AV_CODEC_ID_JPEG2000,
    95. AV_CODEC_ID_VMNC,
    96. AV_CODEC_ID_VP5,
    97. AV_CODEC_ID_VP6,
    98. AV_CODEC_ID_VP6F,
    99. AV_CODEC_ID_TARGA,
    100. AV_CODEC_ID_DSICINVIDEO,
    101. AV_CODEC_ID_TIERTEXSEQVIDEO,
    102. AV_CODEC_ID_TIFF,
    103. AV_CODEC_ID_GIF,
    104. AV_CODEC_ID_DXA,
    105. AV_CODEC_ID_DNXHD,
    106. AV_CODEC_ID_THP,
    107. AV_CODEC_ID_SGI,
    108. AV_CODEC_ID_C93,
    109. AV_CODEC_ID_BETHSOFTVID,
    110. AV_CODEC_ID_PTX,
    111. AV_CODEC_ID_TXD,
    112. AV_CODEC_ID_VP6A,
    113. AV_CODEC_ID_AMV,
    114. AV_CODEC_ID_VB,
    115. AV_CODEC_ID_PCX,
    116. AV_CODEC_ID_SUNRAST,
    117. AV_CODEC_ID_INDEO4,
    118. AV_CODEC_ID_INDEO5,
    119. AV_CODEC_ID_MIMIC,
    120. AV_CODEC_ID_RL2,
    121. AV_CODEC_ID_ESCAPE124,
    122. AV_CODEC_ID_DIRAC,
    123. AV_CODEC_ID_BFI,
    124. AV_CODEC_ID_CMV,
    125. AV_CODEC_ID_MOTIONPIXELS,
    126. AV_CODEC_ID_TGV,
    127. AV_CODEC_ID_TGQ,
    128. AV_CODEC_ID_TQI,
    129. AV_CODEC_ID_AURA,
    130. AV_CODEC_ID_AURA2,
    131. AV_CODEC_ID_V210X,
    132. AV_CODEC_ID_TMV,
    133. AV_CODEC_ID_V210,
    134. AV_CODEC_ID_DPX,
    135. AV_CODEC_ID_MAD,
    136. AV_CODEC_ID_FRWU,
    137. AV_CODEC_ID_FLASHSV2,
    138. AV_CODEC_ID_CDGRAPHICS,
    139. AV_CODEC_ID_R210,
    140. AV_CODEC_ID_ANM,
    141. AV_CODEC_ID_BINKVIDEO,
    142. AV_CODEC_ID_IFF_ILBM,
    143. #define AV_CODEC_ID_IFF_BYTERUN1 AV_CODEC_ID_IFF_ILBM
    144. AV_CODEC_ID_KGV1,
    145. AV_CODEC_ID_YOP,
    146. AV_CODEC_ID_VP8,
    147. AV_CODEC_ID_PICTOR,
    148. AV_CODEC_ID_ANSI,
    149. AV_CODEC_ID_A64_MULTI,
    150. AV_CODEC_ID_A64_MULTI5,
    151. AV_CODEC_ID_R10K,
    152. AV_CODEC_ID_MXPEG,
    153. AV_CODEC_ID_LAGARITH,
    154. AV_CODEC_ID_PRORES,
    155. AV_CODEC_ID_JV,
    156. AV_CODEC_ID_DFA,
    157. AV_CODEC_ID_WMV3IMAGE,
    158. AV_CODEC_ID_VC1IMAGE,
    159. AV_CODEC_ID_UTVIDEO,
    160. AV_CODEC_ID_BMV_VIDEO,
    161. AV_CODEC_ID_VBLE,
    162. AV_CODEC_ID_DXTORY,
    163. AV_CODEC_ID_V410,
    164. AV_CODEC_ID_XWD,
    165. AV_CODEC_ID_CDXL,
    166. AV_CODEC_ID_XBM,
    167. AV_CODEC_ID_ZEROCODEC,
    168. AV_CODEC_ID_MSS1,
    169. AV_CODEC_ID_MSA1,
    170. AV_CODEC_ID_TSCC2,
    171. AV_CODEC_ID_MTS2,
    172. AV_CODEC_ID_CLLC,
    173. AV_CODEC_ID_MSS2,
    174. AV_CODEC_ID_VP9,
    175. AV_CODEC_ID_AIC,
    176. AV_CODEC_ID_ESCAPE130,
    177. AV_CODEC_ID_G2M,
    178. AV_CODEC_ID_WEBP,
    179. AV_CODEC_ID_HNM4_VIDEO,
    180. AV_CODEC_ID_HEVC,
    181. #define AV_CODEC_ID_H265 AV_CODEC_ID_HEVC
    182. AV_CODEC_ID_FIC,
    183. AV_CODEC_ID_ALIAS_PIX,
    184. AV_CODEC_ID_BRENDER_PIX,
    185. AV_CODEC_ID_PAF_VIDEO,
    186. AV_CODEC_ID_EXR,
    187. AV_CODEC_ID_VP7,
    188. AV_CODEC_ID_SANM,
    189. AV_CODEC_ID_SGIRLE,
    190. AV_CODEC_ID_MVC1,
    191. AV_CODEC_ID_MVC2,
    192. AV_CODEC_ID_HQX,
    193. AV_CODEC_ID_TDSC,
    194. AV_CODEC_ID_HQ_HQA,
    195. AV_CODEC_ID_HAP,
    196. AV_CODEC_ID_DDS,
    197. AV_CODEC_ID_DXV,
    198. AV_CODEC_ID_SCREENPRESSO,
    199. AV_CODEC_ID_RSCC,
    200. AV_CODEC_ID_Y41P = 0x8000,
    201. AV_CODEC_ID_AVRP,
    202. AV_CODEC_ID_012V,
    203. AV_CODEC_ID_AVUI,
    204. AV_CODEC_ID_AYUV,
    205. AV_CODEC_ID_TARGA_Y216,
    206. AV_CODEC_ID_V308,
    207. AV_CODEC_ID_V408,
    208. AV_CODEC_ID_YUV4,
    209. AV_CODEC_ID_AVRN,
    210. AV_CODEC_ID_CPIA,
    211. AV_CODEC_ID_XFACE,
    212. AV_CODEC_ID_SNOW,
    213. AV_CODEC_ID_SMVJPEG,
    214. AV_CODEC_ID_APNG,
    215. AV_CODEC_ID_DAALA,
    216. AV_CODEC_ID_CFHD,
    217. AV_CODEC_ID_TRUEMOTION2RT,
    218. AV_CODEC_ID_M101,
    219. AV_CODEC_ID_MAGICYUV,
    220. AV_CODEC_ID_SHEERVIDEO,
    221. AV_CODEC_ID_YLC,
    222. /* various PCM "codecs" */
    223. AV_CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs
    224. AV_CODEC_ID_PCM_S16LE = 0x10000,
    225. AV_CODEC_ID_PCM_S16BE,
    226. AV_CODEC_ID_PCM_U16LE,
    227. AV_CODEC_ID_PCM_U16BE,
    228. AV_CODEC_ID_PCM_S8,
    229. AV_CODEC_ID_PCM_U8,
    230. AV_CODEC_ID_PCM_MULAW,
    231. AV_CODEC_ID_PCM_ALAW,
    232. AV_CODEC_ID_PCM_S32LE,
    233. AV_CODEC_ID_PCM_S32BE,
    234. AV_CODEC_ID_PCM_U32LE,
    235. AV_CODEC_ID_PCM_U32BE,
    236. AV_CODEC_ID_PCM_S24LE,
    237. AV_CODEC_ID_PCM_S24BE,
    238. AV_CODEC_ID_PCM_U24LE,
    239. AV_CODEC_ID_PCM_U24BE,
    240. AV_CODEC_ID_PCM_S24DAUD,
    241. AV_CODEC_ID_PCM_ZORK,
    242. AV_CODEC_ID_PCM_S16LE_PLANAR,
    243. AV_CODEC_ID_PCM_DVD,
    244. AV_CODEC_ID_PCM_F32BE,
    245. AV_CODEC_ID_PCM_F32LE,
    246. AV_CODEC_ID_PCM_F64BE,
    247. AV_CODEC_ID_PCM_F64LE,
    248. AV_CODEC_ID_PCM_BLURAY,
    249. AV_CODEC_ID_PCM_LXF,
    250. AV_CODEC_ID_S302M,
    251. AV_CODEC_ID_PCM_S8_PLANAR,
    252. AV_CODEC_ID_PCM_S24LE_PLANAR,
    253. AV_CODEC_ID_PCM_S32LE_PLANAR,
    254. AV_CODEC_ID_PCM_S16BE_PLANAR,
    255. /* new PCM "codecs" should be added right below this line starting with
    256. * an explicit value of for example 0x10800
    257. */
    258. /* various ADPCM codecs */
    259. AV_CODEC_ID_ADPCM_IMA_QT = 0x11000,
    260. AV_CODEC_ID_ADPCM_IMA_WAV,
    261. AV_CODEC_ID_ADPCM_IMA_DK3,
    262. AV_CODEC_ID_ADPCM_IMA_DK4,
    263. AV_CODEC_ID_ADPCM_IMA_WS,
    264. AV_CODEC_ID_ADPCM_IMA_SMJPEG,
    265. AV_CODEC_ID_ADPCM_MS,
    266. AV_CODEC_ID_ADPCM_4XM,
    267. AV_CODEC_ID_ADPCM_XA,
    268. AV_CODEC_ID_ADPCM_ADX,
    269. AV_CODEC_ID_ADPCM_EA,
    270. AV_CODEC_ID_ADPCM_G726,
    271. AV_CODEC_ID_ADPCM_CT,
    272. AV_CODEC_ID_ADPCM_SWF,
    273. AV_CODEC_ID_ADPCM_YAMAHA,
    274. AV_CODEC_ID_ADPCM_SBPRO_4,
    275. AV_CODEC_ID_ADPCM_SBPRO_3,
    276. AV_CODEC_ID_ADPCM_SBPRO_2,
    277. AV_CODEC_ID_ADPCM_THP,
    278. AV_CODEC_ID_ADPCM_IMA_AMV,
    279. AV_CODEC_ID_ADPCM_EA_R1,
    280. AV_CODEC_ID_ADPCM_EA_R3,
    281. AV_CODEC_ID_ADPCM_EA_R2,
    282. AV_CODEC_ID_ADPCM_IMA_EA_SEAD,
    283. AV_CODEC_ID_ADPCM_IMA_EA_EACS,
    284. AV_CODEC_ID_ADPCM_EA_XAS,
    285. AV_CODEC_ID_ADPCM_EA_MAXIS_XA,
    286. AV_CODEC_ID_ADPCM_IMA_ISS,
    287. AV_CODEC_ID_ADPCM_G722,
    288. AV_CODEC_ID_ADPCM_IMA_APC,
    289. AV_CODEC_ID_ADPCM_VIMA,
    290. #if FF_API_VIMA_DECODER
    291. AV_CODEC_ID_VIMA = AV_CODEC_ID_ADPCM_VIMA,
    292. #endif
    293. AV_CODEC_ID_ADPCM_AFC = 0x11800,
    294. AV_CODEC_ID_ADPCM_IMA_OKI,
    295. AV_CODEC_ID_ADPCM_DTK,
    296. AV_CODEC_ID_ADPCM_IMA_RAD,
    297. AV_CODEC_ID_ADPCM_G726LE,
    298. AV_CODEC_ID_ADPCM_THP_LE,
    299. AV_CODEC_ID_ADPCM_PSX,
    300. AV_CODEC_ID_ADPCM_AICA,
    301. AV_CODEC_ID_ADPCM_IMA_DAT4,
    302. AV_CODEC_ID_ADPCM_MTAF,
    303. /* AMR */
    304. AV_CODEC_ID_AMR_NB = 0x12000,
    305. AV_CODEC_ID_AMR_WB,
    306. /* RealAudio codecs*/
    307. AV_CODEC_ID_RA_144 = 0x13000,
    308. AV_CODEC_ID_RA_288,
    309. /* various DPCM codecs */
    310. AV_CODEC_ID_ROQ_DPCM = 0x14000,
    311. AV_CODEC_ID_INTERPLAY_DPCM,
    312. AV_CODEC_ID_XAN_DPCM,
    313. AV_CODEC_ID_SOL_DPCM,
    314. AV_CODEC_ID_SDX2_DPCM = 0x14800,
    315. /* audio codecs */
    316. AV_CODEC_ID_MP2 = 0x15000,
    317. AV_CODEC_ID_MP3, ///< preferred ID for decoding MPEG audio layer 1, 2 or 3
    318. AV_CODEC_ID_AAC,
    319. AV_CODEC_ID_AC3,
    320. AV_CODEC_ID_DTS,
    321. AV_CODEC_ID_VORBIS,
    322. AV_CODEC_ID_DVAUDIO,
    323. AV_CODEC_ID_WMAV1,
    324. AV_CODEC_ID_WMAV2,
    325. AV_CODEC_ID_MACE3,
    326. AV_CODEC_ID_MACE6,
    327. AV_CODEC_ID_VMDAUDIO,
    328. AV_CODEC_ID_FLAC,
    329. AV_CODEC_ID_MP3ADU,
    330. AV_CODEC_ID_MP3ON4,
    331. AV_CODEC_ID_SHORTEN,
    332. AV_CODEC_ID_ALAC,
    333. AV_CODEC_ID_WESTWOOD_SND1,
    334. AV_CODEC_ID_GSM, ///< as in Berlin toast format
    335. AV_CODEC_ID_QDM2,
    336. AV_CODEC_ID_COOK,
    337. AV_CODEC_ID_TRUESPEECH,
    338. AV_CODEC_ID_TTA,
    339. AV_CODEC_ID_SMACKAUDIO,
    340. AV_CODEC_ID_QCELP,
    341. AV_CODEC_ID_WAVPACK,
    342. AV_CODEC_ID_DSICINAUDIO,
    343. AV_CODEC_ID_IMC,
    344. AV_CODEC_ID_MUSEPACK7,
    345. AV_CODEC_ID_MLP,
    346. AV_CODEC_ID_GSM_MS, /* as found in WAV */
    347. AV_CODEC_ID_ATRAC3,
    348. #if FF_API_VOXWARE
    349. AV_CODEC_ID_VOXWARE,
    350. #endif
    351. AV_CODEC_ID_APE,
    352. AV_CODEC_ID_NELLYMOSER,
    353. AV_CODEC_ID_MUSEPACK8,
    354. AV_CODEC_ID_SPEEX,
    355. AV_CODEC_ID_WMAVOICE,
    356. AV_CODEC_ID_WMAPRO,
    357. AV_CODEC_ID_WMALOSSLESS,
    358. AV_CODEC_ID_ATRAC3P,
    359. AV_CODEC_ID_EAC3,
    360. AV_CODEC_ID_SIPR,
    361. AV_CODEC_ID_MP1,
    362. AV_CODEC_ID_TWINVQ,
    363. AV_CODEC_ID_TRUEHD,
    364. AV_CODEC_ID_MP4ALS,
    365. AV_CODEC_ID_ATRAC1,
    366. AV_CODEC_ID_BINKAUDIO_RDFT,
    367. AV_CODEC_ID_BINKAUDIO_DCT,
    368. AV_CODEC_ID_AAC_LATM,
    369. AV_CODEC_ID_QDMC,
    370. AV_CODEC_ID_CELT,
    371. AV_CODEC_ID_G723_1,
    372. AV_CODEC_ID_G729,
    373. AV_CODEC_ID_8SVX_EXP,
    374. AV_CODEC_ID_8SVX_FIB,
    375. AV_CODEC_ID_BMV_AUDIO,
    376. AV_CODEC_ID_RALF,
    377. AV_CODEC_ID_IAC,
    378. AV_CODEC_ID_ILBC,
    379. AV_CODEC_ID_OPUS,
    380. AV_CODEC_ID_COMFORT_NOISE,
    381. AV_CODEC_ID_TAK,
    382. AV_CODEC_ID_METASOUND,
    383. AV_CODEC_ID_PAF_AUDIO,
    384. AV_CODEC_ID_ON2AVC,
    385. AV_CODEC_ID_DSS_SP,
    386. AV_CODEC_ID_FFWAVESYNTH = 0x15800,
    387. AV_CODEC_ID_SONIC,
    388. AV_CODEC_ID_SONIC_LS,
    389. AV_CODEC_ID_EVRC,
    390. AV_CODEC_ID_SMV,
    391. AV_CODEC_ID_DSD_LSBF,
    392. AV_CODEC_ID_DSD_MSBF,
    393. AV_CODEC_ID_DSD_LSBF_PLANAR,
    394. AV_CODEC_ID_DSD_MSBF_PLANAR,
    395. AV_CODEC_ID_4GV,
    396. AV_CODEC_ID_INTERPLAY_ACM,
    397. AV_CODEC_ID_XMA1,
    398. AV_CODEC_ID_XMA2,
    399. AV_CODEC_ID_DST,
    400. /* subtitle codecs */
    401. AV_CODEC_ID_FIRST_SUBTITLE = 0x17000, ///< A dummy ID pointing at the start of subtitle codecs.
    402. AV_CODEC_ID_DVD_SUBTITLE = 0x17000,
    403. AV_CODEC_ID_DVB_SUBTITLE,
    404. AV_CODEC_ID_TEXT, ///< raw UTF-8 text
    405. AV_CODEC_ID_XSUB,
    406. AV_CODEC_ID_SSA,
    407. AV_CODEC_ID_MOV_TEXT,
    408. AV_CODEC_ID_HDMV_PGS_SUBTITLE,
    409. AV_CODEC_ID_DVB_TELETEXT,
    410. AV_CODEC_ID_SRT,
    411. AV_CODEC_ID_MICRODVD = 0x17800,
    412. AV_CODEC_ID_EIA_608,
    413. AV_CODEC_ID_JACOSUB,
    414. AV_CODEC_ID_SAMI,
    415. AV_CODEC_ID_REALTEXT,
    416. AV_CODEC_ID_STL,
    417. AV_CODEC_ID_SUBVIEWER1,
    418. AV_CODEC_ID_SUBVIEWER,
    419. AV_CODEC_ID_SUBRIP,
    420. AV_CODEC_ID_WEBVTT,
    421. AV_CODEC_ID_MPL2,
    422. AV_CODEC_ID_VPLAYER,
    423. AV_CODEC_ID_PJS,
    424. AV_CODEC_ID_ASS,
    425. AV_CODEC_ID_HDMV_TEXT_SUBTITLE,
    426. /* other specific kind of codecs (generally used for attachments) */
    427. AV_CODEC_ID_FIRST_UNKNOWN = 0x18000, ///< A dummy ID pointing at the start of various fake codecs.
    428. AV_CODEC_ID_TTF = 0x18000,
    429. AV_CODEC_ID_BINTEXT = 0x18800,
    430. AV_CODEC_ID_XBIN,
    431. AV_CODEC_ID_IDF,
    432. AV_CODEC_ID_OTF,
    433. AV_CODEC_ID_SMPTE_KLV,
    434. AV_CODEC_ID_DVD_NAV,
    435. AV_CODEC_ID_TIMED_ID3,
    436. AV_CODEC_ID_BIN_DATA,
    437. AV_CODEC_ID_PROBE = 0x19000, ///< codec_id is not known (like AV_CODEC_ID_NONE) but lavf should attempt to identify it
    438. AV_CODEC_ID_MPEG2TS = 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS
    439. * stream (only used by libavformat) */
    440. AV_CODEC_ID_MPEG4SYSTEMS = 0x20001, /**< _FAKE_ codec to indicate a MPEG-4 Systems
    441. * stream (only used by libavformat) */
    442. AV_CODEC_ID_FFMETADATA = 0x21000, ///< Dummy codec for streams containing only metadata information.
    443. AV_CODEC_ID_WRAPPED_AVFRAME = 0x21001, ///< Passthrough codec, AVFrames wrapped in AVPacket
    444. };

    如我们找一个标准的h.264+aac的解码,h.264解码器在h264.c中的声明如下,注意id(AV_CODEC_ID_H264)对应我们上面AVCodcID中的AV_CODEC_ID_H264。

    1. AVCodec ff_h264_decoder = {
    2. .name = "h264",
    3. .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
    4. .type = AVMEDIA_TYPE_VIDEO,
    5. .id = AV_CODEC_ID_H264,
    6. .priv_data_size = sizeof(H264Context),
    7. .init = ff_h264_decode_init,
    8. .close = h264_decode_end,
    9. .decode = h264_decode_frame,
    10. .capabilities = /*AV_CODEC_CAP_DRAW_HORIZ_BAND |*/ AV_CODEC_CAP_DR1 |
    11. AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS |
    12. AV_CODEC_CAP_FRAME_THREADS,
    13. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
    14. .flush = flush_dpb,
    15. .init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy),
    16. .update_thread_context = ONLY_IF_THREADS_ENABLED(ff_h264_update_thread_context),
    17. .profiles = NULL_IF_CONFIG_SMALL(ff_h264_profiles),
    18. .priv_class = &h264_class,
    19. };

    aac中解码器声明如下,位于aacdec.c文件中,注意id(AV_CODEC_ID_AAC)与上面上面的AVCodcID中的AV_CODEC_ID_AAC。

    1. AVCodec ff_aac_decoder = {
    2. .name = "aac",
    3. .long_name = NULL_IF_CONFIG_SMALL("AAC (Advanced Audio Coding)"),
    4. .type = AVMEDIA_TYPE_AUDIO,
    5. .id = AV_CODEC_ID_AAC,
    6. .priv_data_size = sizeof(AACContext),
    7. .init = aac_decode_init,
    8. .close = aac_decode_close,
    9. .decode = aac_decode_frame,
    10. .sample_fmts = (const enum AVSampleFormat[]) {
    11. AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE
    12. },
    13. .capabilities = AV_CODEC_CAP_CHANNEL_CONF | AV_CODEC_CAP_DR1,
    14. .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
    15. .channel_layouts = aac_channel_layout,
    16. .flush = flush,
    17. .priv_class = &aac_decoder_class,
    18. .profiles = NULL_IF_CONFIG_SMALL(ff_aac_profiles),
    19. };

    每一个编解码器对应一个结构体AVCodec


    如约智惠.png