“Codec study notes”的版本间的差异

来自个人维基
跳转至: 导航搜索
第1行: 第1行:
 
*FFMPEG
 
*FFMPEG
 
<u>*h264dec</u>
 
<u>*h264dec</u>
 +
<source lang="c">
 +
AVCodec {
 +
    const char *name; //codec name
 +
    const char *long_name;
 +
    enum AVMediaType type;
 +
    enum AVCodecID id;
 +
    int capabilities;
 +
    const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
 +
    const enum AVPixelFormat *pix_fmts;    ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
 +
    const int *supported_samplerates;      ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
 +
    const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
 +
    const uint64_t *channel_layouts;        ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
 +
    uint8_t max_lowres;                    ///< maximum value for lowres supported by the decoder
 +
    const AVClass *priv_class;              ///< AVClass for the private context
 +
    const AVProfile *profiles;              ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}
 +
 +
    const char *wrapper_name; //usually AVCodec.name will be of the form "<codec_name>_<wrapper_name>").
 +
 +
    /*** No fields below this line are part of the public API. */
 +
    int priv_data_size;
 +
    struct AVCodec *next;
 +
    /**
 +
    int (*init_thread_copy)(AVCodecContext *);
 +
    int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src);
 +
    /*  Private codec-specific defaults.*/
 +
    const AVCodecDefault *defaults;
 +
    void (*init_static_data)(struct AVCodec *codec);
 +
    int (*init)(AVCodecContext *);
 +
    int (*encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size,
 +
                      const struct AVSubtitle *sub);
 +
    int (*encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame,
 +
                  int *got_packet_ptr);
 +
    int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt);
 +
    int (*close)(AVCodecContext *);
 +
    int (*send_frame)(AVCodecContext *avctx, const AVFrame *frame);
 +
    int (*receive_packet)(AVCodecContext *avctx, AVPacket *avpkt);
 +
    int (*receive_frame)(AVCodecContext *avctx, AVFrame *frame);
 +
    void (*flush)(AVCodecContext *);
 +
    int caps_internal;
 +
 +
    /**
 +
    * Decoding only, a comma-separated list of bitstream filters to apply to
 +
    * packets before decoding.
 +
    */
 +
    const char *bsfs;
 +
 +
    /**
 +
    * Array of pointers to hardware configurations supported by the codec,
 +
    * or NULL if no hardware supported.  The array is terminated by a NULL
 +
    * pointer.
 +
    *
 +
    * The user can only access this field via avcodec_get_hw_config().
 +
    */
 +
    const struct AVCodecHWConfigInternal **hw_configs;
 +
 +
    /**
 +
    * List of supported codec_tags, terminated by FF_CODEC_TAGS_END.
 +
    */
 +
    const uint32_t *codec_tags;
 +
}
 +
</source>
 +
hw accelator configure
 +
<source lang="c">
 +
const struct AVCodecHWConfigInternal **hw_configs = {
 +
      AVCodecHWConfig public {
 +
          enum AVPixelFormat pix_fmt {
 +
            #defined in pixfmt.h in libavutil, AV_PIX_FMT_YUV420P
 +
          }
 +
          int methods;
 +
          enum AVHWDeviceType device_type {
 +
          }
 +
      };
 +
 +
      const AVHWAccel *hwaccel {
 +
      }
 +
 
 +
}
 +
</source>
 +
 +
example: h264
 
<source lang="c">
 
<source lang="c">
 
AVCodec ff_h264_decoder = {
 
AVCodec ff_h264_decoder = {

2020年4月9日 (四) 11:55的版本

  • FFMPEG

*h264dec

AVCodec {
    const char *name; //codec name
    const char *long_name;
    enum AVMediaType type;
    enum AVCodecID id;
    int capabilities;
    const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
    const enum AVPixelFormat *pix_fmts;     ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
    const int *supported_samplerates;       ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
    const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
    const uint64_t *channel_layouts;         ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
    uint8_t max_lowres;                     ///< maximum value for lowres supported by the decoder
    const AVClass *priv_class;              ///< AVClass for the private context
    const AVProfile *profiles;              ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}
 
    const char *wrapper_name; //usually AVCodec.name will be of the form "<codec_name>_<wrapper_name>").
 
    /*** No fields below this line are part of the public API. */
    int priv_data_size;
    struct AVCodec *next;
    /**
    int (*init_thread_copy)(AVCodecContext *);
    int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src);
    /*  Private codec-specific defaults.*/
    const AVCodecDefault *defaults;
    void (*init_static_data)(struct AVCodec *codec);
    int (*init)(AVCodecContext *);
    int (*encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size,
                      const struct AVSubtitle *sub);
    int (*encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame,
                   int *got_packet_ptr);
    int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt);
    int (*close)(AVCodecContext *);
    int (*send_frame)(AVCodecContext *avctx, const AVFrame *frame);
    int (*receive_packet)(AVCodecContext *avctx, AVPacket *avpkt);
    int (*receive_frame)(AVCodecContext *avctx, AVFrame *frame);
    void (*flush)(AVCodecContext *);
    int caps_internal;
 
    /**
     * Decoding only, a comma-separated list of bitstream filters to apply to
     * packets before decoding.
     */
    const char *bsfs;
 
    /**
     * Array of pointers to hardware configurations supported by the codec,
     * or NULL if no hardware supported.  The array is terminated by a NULL
     * pointer.
     *
     * The user can only access this field via avcodec_get_hw_config().
     */
    const struct AVCodecHWConfigInternal **hw_configs;
 
    /**
     * List of supported codec_tags, terminated by FF_CODEC_TAGS_END.
     */
    const uint32_t *codec_tags;
}

hw accelator configure

const struct AVCodecHWConfigInternal **hw_configs = {
      AVCodecHWConfig public {
          enum AVPixelFormat pix_fmt {
             #defined in pixfmt.h in libavutil, AV_PIX_FMT_YUV420P
          }
          int methods;
          enum AVHWDeviceType device_type {
          }
      };
 
      const AVHWAccel *hwaccel {
      }
 
}

example: h264

AVCodec ff_h264_decoder = {
    .name                  = "h264",
    .long_name             = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
    .type                  = AVMEDIA_TYPE_VIDEO,
    .id                    = AV_CODEC_ID_H264,
    .priv_data_size        = sizeof(H264Context),
    .init                  = h264_decode_init,
    .close                 = h264_decode_end,
    .decode                = h264_decode_frame,
    .capabilities          = /*AV_CODEC_CAP_DRAW_HORIZ_BAND |*/ AV_CODEC_CAP_DR1 |
                             AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS |
                             AV_CODEC_CAP_FRAME_THREADS,
    .hw_configs            = (const AVCodecHWConfigInternal*[]) {
#if CONFIG_H264_DXVA2_HWACCEL
                               HWACCEL_DXVA2(h264),
#endif
#if CONFIG_H264_D3D11VA_HWACCEL
                               HWACCEL_D3D11VA(h264),
#endif
#if CONFIG_H264_D3D11VA2_HWACCEL
                               HWACCEL_D3D11VA2(h264),
#endif
#if CONFIG_H264_NVDEC_HWACCEL
                               HWACCEL_NVDEC(h264),
#endif
#if CONFIG_H264_VAAPI_HWACCEL
                               HWACCEL_VAAPI(h264),
#endif
#if CONFIG_H264_VDPAU_HWACCEL
                               HWACCEL_VDPAU(h264),
#endif
#if CONFIG_H264_VIDEOTOOLBOX_HWACCEL
                               HWACCEL_VIDEOTOOLBOX(h264),
#endif
                               NULL
                           },
    .caps_internal         = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_EXPORTS_CROPPING,
    .flush                 = flush_dpb,
    .init_thread_copy      = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy),
    .update_thread_context = ONLY_IF_THREADS_ENABLED(ff_h264_update_thread_context),
    .profiles              = NULL_IF_CONFIG_SMALL(ff_h264_profiles),
    .priv_class            = &h264_class,
};