美文网首页
ffmpeg 中 结构体初始化 的那些花样

ffmpeg 中 结构体初始化 的那些花样

作者: FlyingPenguin | 来源:发表于2019-03-24 22:18 被阅读0次
    https://blog.csdn.net/ericbar/article/details/79567108
    https://blog.csdn.net/ericbar/article/details/79567108

    花样1:
    AVRational 是一个表示有理数的结构体。

    /**
     * Rational number (pair of numerator and denominator).
     */
    typedef struct AVRational{
        int num; ///< Numerator
        int den; ///< Denominator
    } AVRational;
    

    其实当num=1,den=1000的时候pts的时间单位就相当于毫秒 1/1000秒
    其实当num=1,den=1000000的时候pts的时间单位就相当于微秒 1/1000000秒

    AVRational 最常用的初始化套路是这样的:

        enc_ctx->time_base = (AVRational){1,25};  // meaningless
    

    这种方式的特例:

    /**
     * Internal time base represented as integer
     */
    
    #define AV_TIME_BASE            1000000
    
    /**
     * Internal time base represented as fractional value
     */
    
    #define AV_TIME_BASE_Q          (AVRational){1, AV_TIME_BASE}
    
    

    花样2 (清晰):

                            fs->time_base.num = 1;
                            fs->time_base.den = AV_TIME_BASE;
    
    

    花样3:

    static const AVRational avf_time_base_q = {
        .num = 1,
        .den = avf_time_base
    };
    
    AVPacket packet = { .data = NULL, .size = 0 };
    

    再比如:

    AVFilter的定义是这样的:

    /**
     * Filter definition. This defines the pads a filter contains, and all the
     * callback functions used to interact with the filter.
     */
    typedef struct AVFilter {
        /**
         * Filter name. Must be non-NULL and unique among filters.
         */
        const char *name;
    
        /**
         * A description of the filter. May be NULL.
         *
         * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
         */
        const char *description;
    
        /**
         * List of inputs, terminated by a zeroed element.
         *
         * NULL if there are no (static) inputs. Instances of filters with
         * AVFILTER_FLAG_DYNAMIC_INPUTS set may have more inputs than present in
         * this list.
         */
        const AVFilterPad *inputs;
        /**
         * List of outputs, terminated by a zeroed element.
         *
         * NULL if there are no (static) outputs. Instances of filters with
         * AVFILTER_FLAG_DYNAMIC_OUTPUTS set may have more outputs than present in
         * this list.
         */
        const AVFilterPad *outputs;
    
        /**
         * A class for the private data, used to declare filter private AVOptions.
         * This field is NULL for filters that do not declare any options.
         *
         * If this field is non-NULL, the first member of the filter private data
         * must be a pointer to AVClass, which will be set by libavfilter generic
         * code to this class.
         */
        const AVClass *priv_class;
    
        /**
         * A combination of AVFILTER_FLAG_*
         */
        int flags;
    
        ...
    
        int (*activate)(AVFilterContext *ctx);
    } AVFilter;
    

    初始化的套路是这样的,这也是最具c风格的初始化:

    AVFilter ff_vf_fps = {
        .name        = "fps",
        .description = NULL_IF_CONFIG_SMALL("Force constant framerate."),
        .init        = init,
        .uninit      = uninit,
        .priv_size   = sizeof(FPSContext),
        .priv_class  = &fps_class,
        .activate    = activate,
        .inputs      = avfilter_vf_fps_inputs,
        .outputs     = avfilter_vf_fps_outputs,
    };
    

    References:

    https://blog.csdn.net/ericbar/article/details/79567108
    https://blog.51cto.com/xiacaojun/1958680

    相关文章

      网友评论

          本文标题:ffmpeg 中 结构体初始化 的那些花样

          本文链接:https://www.haomeiwen.com/subject/xobpvqtx.html