ffmpeg中filter_query_formats函数解析

这篇具有很好参考价值的文章主要介绍了ffmpeg中filter_query_formats函数解析。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

ffmpeg中filter_query_formats主要起一个pix fmt引用指定的功能。
下下结论:
ffmpeg中filter_query_formats函数解析,ffmpeg

先看几个结构体定义:

//删除了一些与本次分析不必要的成员
struct AVFilterLink {
    AVFilterContext *src;       ///< source filter
    AVFilterPad *srcpad;        ///< output pad on the source filter

    AVFilterContext *dst;       ///< dest filter
    AVFilterPad *dstpad;        ///< input pad on the dest filter

    enum AVMediaType type;      ///< filter media type

    /* These parameters apply only to video */
    int w;                      ///< agreed upon image width
    int h;                      ///< agreed upon image height
    AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
    /* These parameters apply only to audio */
    uint64_t channel_layout;    ///< channel layout of current buffer (see libavutil/channel_layout.h)
    int sample_rate;            ///< samples per second

    int format;                 ///< agreed upon media format

    /*****************************************************************
     * All fields below this line are not part of the public API. They
     * may not be used outside of libavfilter and can be changed and
     * removed at will.
     * New public fields should be added right above.
     *****************************************************************
     */

    /**
     * Lists of supported formats / etc. supported by the input filter.
     */
    AVFilterFormatsConfig incfg;

    /**
     * Graph the filter belongs to.
     */
    struct AVFilterGraph *graph;
    ...
};

结构体:AVFilterFormatsConfig

typedef struct AVFilterFormatsConfig {

    /**
     * List of supported formats (pixel or sample).
     */
    AVFilterFormats *formats;

    /**
     * Lists of supported sample rates, only for audio.
     */
    AVFilterFormats  *samplerates;

    /**
     * Lists of supported channel layouts, only for audio.
     */
    AVFilterChannelLayouts  *channel_layouts;

} AVFilterFormatsConfig;

再来看函数:

static int filter_query_formats(AVFilterContext *ctx)
{
    int ret, i;
    AVFilterFormats *formats;
    AVFilterChannelLayouts *chlayouts;
    AVFilterFormats *samplerates;
    enum AVMediaType type = ctx->inputs  && ctx->inputs [0] ? ctx->inputs [0]->type :
                            ctx->outputs && ctx->outputs[0] ? ctx->outputs[0]->type :
                            AVMEDIA_TYPE_VIDEO;

    if ((ret = ctx->filter->query_formats(ctx)) < 0) {
        if (ret != AVERROR(EAGAIN))
            av_log(ctx, AV_LOG_ERROR, "Query format failed for '%s': %s\n",
                   ctx->name, av_err2str(ret));
        return ret;
    }
    ret = filter_check_formats(ctx);
    if (ret < 0)
        return ret;

    for (i = 0; i < ctx->nb_inputs; i++)
        sanitize_channel_layouts(ctx, ctx->inputs[i]->outcfg.channel_layouts);
    for (i = 0; i < ctx->nb_outputs; i++)
        sanitize_channel_layouts(ctx, ctx->outputs[i]->incfg.channel_layouts);
//如果query_formats函数有,那么这里其实什么也不做
    formats = ff_all_formats(type);
    if ((ret = ff_set_common_formats(ctx, formats)) < 0)
        return ret;
    if (type == AVMEDIA_TYPE_AUDIO) {
        samplerates = ff_all_samplerates();
        if ((ret = ff_set_common_samplerates(ctx, samplerates)) < 0)
            return ret;
        chlayouts = ff_all_channel_layouts();
        if ((ret = ff_set_common_channel_layouts(ctx, chlayouts)) < 0)
            return ret;
    }
    return 0;
}

核心函数:ff_set_common_formats

int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
{
    SET_COMMON_FORMATS(ctx, formats,
                       ff_formats_ref, ff_formats_unref);
}

看宏定义:

#define SET_COMMON_FORMATS(ctx, fmts, ref_fn, unref_fn)             \
    int count = 0, i;                                               \
                                                                    \
    if (!fmts)                                                      \
        return AVERROR(ENOMEM);                                     \
                                                                    \
    for (i = 0; i < ctx->nb_inputs; i++) {                          \
        if (ctx->inputs[i] && !ctx->inputs[i]->outcfg.fmts) {       \
            int ret = ref_fn(fmts, &ctx->inputs[i]->outcfg.fmts);   \
            if (ret < 0) {                                          \
                return ret;                                         \
            }                                                       \
            count++;                                                \
        }                                                           \
    }                                                               \
    for (i = 0; i < ctx->nb_outputs; i++) {                         \
        if (ctx->outputs[i] && !ctx->outputs[i]->incfg.fmts) {      \
            int ret = ref_fn(fmts, &ctx->outputs[i]->incfg.fmts);   \
            if (ret < 0) {                                          \
                return ret;                                         \
            }                                                       \
            count++;                                                \
        }                                                           \
    }                                                               \
                                                                    \
    if (!count) {                                                   \
        unref_fn(&fmts);                                            \
    }                                                               \
                                                                    \
    return 0;

接着看ref

int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
{
    FORMATS_REF(f, ref, ff_formats_unref);
}

#define FORMATS_REF(f, ref, unref_fn)                                           \
    void *tmp;                                                                  \
                                                                                \
    if (!f)                                                                     \
        return AVERROR(ENOMEM);                                                 \
                                                                                \
    tmp = av_realloc_array(f->refs, sizeof(*f->refs), f->refcount + 1);         \
    if (!tmp) {                                                                 \
        unref_fn(&f);                                                           \
        return AVERROR(ENOMEM);                                                 \
    }                                                                           \
    f->refs = tmp;                                                              \
    f->refs[f->refcount++] = ref;                                               \
    *ref = f;                                                                   \
    return 0

主要看关键的三行代码:

    f->refs = tmp;                                                              \
    f->refs[f->refcount++] = ref;                                               \
    *ref = f;  

这就是最开始图片指示的互相引用。文章来源地址https://www.toymoban.com/news/detail-600930.html

到了这里,关于ffmpeg中filter_query_formats函数解析的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 关于FFMPEG中的filter滤镜的简单介绍

    滤镜的作用主要是对原始的音视频数据进行处理以实现各种各样的效果。比如叠加水印,翻转缩放视频等。 下图表示的正常转码流程,滤镜在解码和编码中间,虚线表示可有可无。 使用命令查看ffmpeg支持的滤镜 ffmpeg -filters  查看某个滤镜的详细参数 ffmpeg -h filter=pad  上图显

    2024年02月14日
    浏览(28)
  • FFmpeg Option设置各子Filter参数方法

    又折腾了一把! Option方法是ffmpeg提供的设置各子模块的参数的接口。 折腾很久,主要还是这个接口的使用规则没有明朗,资料比较杂,一直没有找到,经过看代码分析搞定的,这里记录下,有需要的童鞋可以参考参考!

    2024年02月12日
    浏览(26)
  • ffmpeg全景视频转普通视角视频的filter开发

    环境macos12.6 brew install glfw ffmpeg编译脚本 ./configure --cc=clang --prefix=$PWD/build --enable-libx264 --enable-filter=genericshader --enable-gpl --enable-opengl --extra-libs=\\\'-lglfw -ldl\\\'  --extra-cflags=\\\"-I/Users/taio/Downloads/x264-snapshot-20170521-2245/build/include \\\" --extra-ldflags=\\\"-L/Users/taio/Downloads/x264-snapshot-20170521-2245/build/

    2024年01月22日
    浏览(27)
  • FFmpeg AVFilter的原理(三)- filter是如何被驱动的

    首先上官方filter的链接:https://ffmpeg.org/ffmpeg-filters.html 关于filter命令行:FFmpeg-4.0 的filter机制的架构与实现.之一 Filter原理 1、下面是一个avfilter的graph 上图是ffmpeg中doc/examples中filtering_video.c案例的示意图。 特别注意上面蓝色方块箭头,其就是query_format()后的结果,也是filter协商

    2024年02月15日
    浏览(29)
  • FFmpeg报错:Specified pixel format yuvj420p is invalid or not supported(用ffmpeg程序查看编码器支持像素格式命令)

    这是因为我们把海康rtsp视频流packet解封装后,它frame的像素格式是 yuvj420p(AV_PIX_FMT_YUVJ420P) 的,然后我们又指定编码器上下文的像素格式 pix_fmt = AV_PIX_FMT_YUVJ420P ,指定编码器为 AV_CODEC_ID_MPEG4 ,但是 AV_CODEC_ID_MPEG4 不支持 AV_PIX_FMT_YUVJ420P 像素格式,所以报了上述错误 用 ffmpe

    2023年04月13日
    浏览(76)
  • format()函数的用法

    Python中的 format() 函数用于格式化字符串。它可以将不同类型的数据格式化为字符串中指定的格式。以下是 format() 函数的各种用法及示例: \\\"{参数序号:格式控制标记}\\\".format() 格式内容: .精度-后面可以加类型 类型 整数类型:b--2进制、c--Unicode、d--十进制、o--八进制、x/X--十

    2024年02月07日
    浏览(40)
  • python中format格式化函数(全)

    格式化字符串的函数 str.format() 它增强了字符串格式化的功能。 通过用{} 和: 来代替 编程语言输出中的% 1.默认输出代码方式 输出hello world \\\" { } “输出{}内的内容以及” \\\"内的内容,空格也会跟着输出 2.指定位置的输出 输出hello,world 3.指定多个位置输出 输出world hello world 4.字

    2023年04月08日
    浏览(102)
  • FFmpeg h.265 MP4编码告警:deprecated pixel format used, make sure you did set range correctly

    “使用了不赞成使用的像素格式,请确保您已使用ffmpeg正确设置了范围\\\" 直接忽略这个警告就可以了,我们取的海康摄像头的rtsp流的像素格式是yuv j420p,估计这种像素格式现在不太那啥,所以不赞成使用 但是x264和x265编码器目前都支持这种像素类型,我们平时只用到x264和x2

    2024年02月16日
    浏览(41)
  • 【Java】【SQL】DATE_FORMAT函数详解

    引言:实际上在使用Java开发过程中,有很多业务场景下,都有时间类型的参数参与。前后端进行交互的时候,针对时间类型的格式都会做一个业务上的统一,方便开发且增加效率。关于后端的逻辑有两个层面可以进行优化,一个是底层sql方面,一个是业务层方面,这两者之间

    2024年03月17日
    浏览(39)
  • MySQL 对日期使用 DATE_FORMAT()函数

    前面使用日期时间函数,获取到的要么是 yyyy-mm-dd 形式的日期,要么是 hh:MM:ss 形式的时间,或者是 yyyy-mm-dd hh:mm:ss 形式的日期及时间,其输出格式都已经确定。但在日常生活中,而每次提及日期时间信息都有不同的关注侧面,如:我只想知道今天是几号,或者是星期几,或者

    2024年02月15日
    浏览(31)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包