FFmpeg結(jié)構(gòu)體:AVCodec

1.描述

AVCodec是存儲(chǔ)編解碼器信息的結(jié)構(gòu)體,位于avcodec.h文件中。

2.結(jié)構(gòu)體定義

/**
 * AVCodec.
 */
typedef struct AVCodec {
    /**
     * Name of the codec implementation.
     * The name is globally unique among encoders and among decoders (but an
     * encoder and a decoder can share the same name).
     * This is the primary way to find a codec from the user perspective.
     */
    const char *name;
    /**
     * Descriptive name for the codec, meant to be more human readable than name.
     * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
     */
    const char *long_name;
    enum AVMediaType type;
    enum AVCodecID id;
    /**
     * Codec capabilities.
     * see AV_CODEC_CAP_*
     */
    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, no direct access, use av_codec_get_max_lowres()
    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}

    /*****************************************************************
     * No fields below this line are part of the public API. They
     * may not be used outside of libavcodec and can be changed and
     * removed at will.
     * New public fields should be added right above.
     *****************************************************************
     */
    int priv_data_size;
    struct AVCodec *next;
    /**
     * @name Frame-level threading support functions
     * @{
     */
    /**
     * If defined, called on thread contexts when they are created.
     * If the codec allocates writable tables in init(), re-allocate them here.
     * priv_data will be set to a copy of the original.
     */
    int (*init_thread_copy)(AVCodecContext *);
    /**
     * Copy necessary context variables from a previous thread context to the current one.
     * If not defined, the next thread will start automatically; otherwise, the codec
     * must call ff_thread_finish_setup().
     *
     * dst and src will (rarely) point to the same context, in which case memcpy should be skipped.
     */
    int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src);
    /** @} */

    /**
     * Private codec-specific defaults.
     */
    const AVCodecDefault *defaults;

    /**
     * Initialize codec static data, called from avcodec_register().
     */
    void (*init_static_data)(struct AVCodec *codec);

    int (*init)(AVCodecContext *);
    int (*encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size,
                      const struct AVSubtitle *sub);
    /**
     * Encode data to an AVPacket.
     *
     * @param      avctx          codec context
     * @param      avpkt          output AVPacket (may contain a user-provided buffer)
     * @param[in]  frame          AVFrame containing the raw data to be encoded
     * @param[out] got_packet_ptr encoder sets to 0 or 1 to indicate that a
     *                            non-empty packet was returned in avpkt.
     * @return 0 on success, negative error code on failure
     */
    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 *);
    /**
     * Decode/encode API with decoupled packet/frame dataflow. The API is the
     * same as the avcodec_ prefixed APIs (avcodec_send_frame() etc.), except
     * that:
     * - never called if the codec is closed or the wrong type,
     * - AVPacket parameter change side data is applied right before calling
     *   AVCodec->send_packet,
     * - if AV_CODEC_CAP_DELAY is not set, drain packets or frames are never sent,
     * - only one drain packet is ever passed down (until the next flush()),
     * - a drain AVPacket is always NULL (no need to check for avpkt->size).
     */
    int (*send_frame)(AVCodecContext *avctx, const AVFrame *frame);
    int (*send_packet)(AVCodecContext *avctx, const AVPacket *avpkt);
    int (*receive_frame)(AVCodecContext *avctx, AVFrame *frame);
    int (*receive_packet)(AVCodecContext *avctx, AVPacket *avpkt);
    /**
     * Flush buffers.
     * Will be called when seeking
     */
    void (*flush)(AVCodecContext *);
    /**
     * Internal codec capabilities.
     * See FF_CODEC_CAP_* in internal.h
     */
    int caps_internal;
} AVCodec;

3.常見(jiàn)變量及其作用

const char *name;//編解碼器的名字,比較短。在編碼器和解碼器之間是全局唯一的。 這是用戶查找編解碼器的主要方式。
const char *long_name;//編解碼器的名字,全稱,比較長(zhǎng)。
enum AVMediaType type;//指明了類型,是視頻,音頻,還是字幕
enum AVCodecID id;
const AVRational *supported_framerates;//支持的幀率(僅視頻)
const enum AVPixelFormat *pix_fmts;//支持的像素格式(僅視頻)
const int *supported_samplerates;//支持的采樣率(僅音頻)
const enum AVSampleFormat *sample_fmts;//支持的采樣格式(僅音頻)
const uint64_t *channel_layouts;//支持的聲道數(shù)(僅音頻)
int priv_data_size;//私有數(shù)據(jù)的大小

4.常用函數(shù)作用

void (*init_static_data)(struct AVCodec *codec);//初始化編解碼器靜態(tài)數(shù)據(jù),從avcodec_register()調(diào)用。
int (*encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr);//將數(shù)據(jù)編碼到AVPacket。
int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt);//解碼數(shù)據(jù)到AVPacket。
int (*close)(AVCodecContext *);//關(guān)閉編解碼器。
void (*flush)(AVCodecContext *);//刷新緩沖區(qū)。當(dāng)seek時(shí)會(huì)被調(diào)用。

每一個(gè)編解碼器對(duì)應(yīng)一個(gè)該結(jié)構(gòu)體。程序運(yùn)行時(shí),上述函數(shù)指針會(huì)賦值為對(duì)應(yīng)的編解碼器的函數(shù)。

參考:
http://blog.csdn.net/leixiaohua1020/article/details/14215833

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • 原文地址:http://blog.csdn.net/yipie/article/details/7912291 摘...
    冬的天閱讀 7,227評(píng)論 1 6
  • 教程一:視頻截圖(Tutorial 01: Making Screencaps) 首先我們需要了解視頻文件的一些基...
    90后的思維閱讀 4,795評(píng)論 0 3
  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 173,556評(píng)論 25 708
  • 我不知道憂愁是不是每個(gè)青春都要經(jīng)歷的,有時(shí)候心情莫名的不好,感覺(jué)自己很孤獨(dú),有時(shí)也很敏感,每天都在為了自己的目標(biāo)往...
    瞧ni閱讀 239評(píng)論 1 1
  • 凌亂的房間、糾結(jié)的思緒、舍不得卻用不上的東西占滿整個(gè)空間。住酒店的人真開心,每天有人打掃每天都是新房間。每次住酒店...
    Gwenduly_W2016閱讀 186評(píng)論 0 0