[ffmpeg] AVOption 解析

背景

AVOption 可能用到很多地方,本文只解析编码器设置其支持的编码器参数的 options。

正文

AVOption 结构

cpp 复制代码
typedef struct AVOption {
    const char *name;  // 名字

    /**
     * short English help text
     * @todo What about other languages?
     */
    const char *help; // 简介

    /**
     * The offset relative to the context structure where the option
     * value is stored. It should be 0 for named constants.
     */
    int offset; // 偏移量,如果该 option 是常量则为0
    enum AVOptionType type; // 

    /**
     * the default value for scalar options
     */
    union {
        int64_t i64;
        double dbl;
        const char *str;
        /* TODO those are unused now */
        AVRational q;
    } default_val;
    double min;                 ///< minimum valid value for the option
    double max;                 ///< maximum valid value for the option

    int flags;
#define AV_OPT_FLAG_ENCODING_PARAM  1   ///< a generic parameter which can be set by the user for muxing or encoding
#define AV_OPT_FLAG_DECODING_PARAM  2   ///< a generic parameter which can be set by the user for demuxing or decoding
#define AV_OPT_FLAG_AUDIO_PARAM     8
#define AV_OPT_FLAG_VIDEO_PARAM     16
#define AV_OPT_FLAG_SUBTITLE_PARAM  32
/**
 * The option is intended for exporting values to the caller.
 */
#define AV_OPT_FLAG_EXPORT          64
/**
 * The option may not be set through the AVOptions API, only read.
 * This flag only makes sense when AV_OPT_FLAG_EXPORT is also set.
 */
#define AV_OPT_FLAG_READONLY        128
#define AV_OPT_FLAG_BSF_PARAM       (1<<8) ///< a generic parameter which can be set by the user for bit stream filtering
#define AV_OPT_FLAG_RUNTIME_PARAM   (1<<15) ///< a generic parameter which can be set by the user at runtime
#define AV_OPT_FLAG_FILTERING_PARAM (1<<16) ///< a generic parameter which can be set by the user for filtering
#define AV_OPT_FLAG_DEPRECATED      (1<<17) ///< set if option is deprecated, users should refer to AVOption.help text for more information
#define AV_OPT_FLAG_CHILD_CONSTS    (1<<18) ///< set if option constants can also reside in child objects
//FIXME think about enc-audio, ... style flags

    /**
     * The logical unit to which the option belongs. Non-constant
     * options and corresponding named constants share the same
     * unit. May be NULL.
     */
    const char *unit;
} AVOption;

进一步解析

  1. 目前感觉 AVOption 主要可以分成两类,一类是常量 option,一类是变量 option。
    a. 常量 option
    type 为 AV_OPT_TYPE_CONST
    offset 为 0
    作为变量 option
    b.举例
    使用 x264 部分代码举例
cpp 复制代码
{ "stats",         "Filename for 2 pass stats",                       OFFSET(stats),         AV_OPT_TYPE_STRING, { 0 },  0,       0, VE },
{ "nal-hrd",       "Signal HRD information (requires vbv-bufsize; "
                       "cbr not allowed in .mp4)",                        OFFSET(nal_hrd),       AV_OPT_TYPE_INT,    { .i64 = -1 }, -1, INT_MAX, VE, "nal-hrd" },
{ "none",          NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_NONE}, INT_MIN, INT_MAX, VE, "nal-hrd" },
{ "vbr",           NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_VBR},  INT_MIN, INT_MAX, VE, "nal-hrd" },
{ "cbr",           NULL, 0, AV_OPT_TYPE_CONST, {.i64 = X264_NAL_HRD_CBR},  INT_MIN, INT_MAX, VE, "nal-hrd" },

可以发现 nal-hrd 类型是 AV_OPT_TYPE_INT, unit 为 "nal-hrd",说明这个变量需要用其他 unit 为 "nal-hrd" 的常量 AVOption 作为参数。

"none"、"vbr"、"cbr" 这些类型是是AV_OPT_TYPE_CONST, unit 为 "nal-hrd",可以作为 nal-hrd 具体的值传入。

"stats" 这个变量,不需要通过其他 AVOption 作为参数,所以其 unit 没有设置。

P.S.

上面的结论只是个人看法不一定对。

相关推荐
努力还债的学术吗喽2 天前
ffmpeg离线安装到服务器:解决conda/sudo/无法安装的通用方案
服务器·ffmpeg·conda
zymill3 天前
hysAnalyser --- UDP实时流分析使用指南
ffmpeg·ts流分析·mpegts·音视频分析·数字电视流录制·audio vivid·视频分析工具
Everbrilliant893 天前
FFmpeg解码音频数据AudioTrack/OpenSL播放
ffmpeg·音视频·audiotrack·opensl·ffmpeg音频解码播放·decodethread·opensl播放与解码同步
海南java第二人6 天前
数据库范式详解:从冗余到规范的升华之旅
数据库·oracle·ffmpeg
mortimer6 天前
只需三步,动手搭建一个本地免费【实时语音转录】工具WhisperLiveKit
ffmpeg·github·openai
Hi202402178 天前
消除FFmpeg库的SONAME依赖
linux·ffmpeg
mortimer10 天前
使用阿里AI模型去除背景噪音:单文件40行代码实现
python·ffmpeg·阿里巴巴
今天也想MK代码10 天前
WebRtc语音通话前置铃声处理
ffmpeg·webrtc
撬动未来的支点10 天前
解读ffmpeg控制台输出
ffmpeg
戴草帽的大z10 天前
使用V4L2工具验证RK3588平台视频设备节点数据有效性
ffmpeg·音视频·rk3588·nv12·v4l2-ctl