在ffmpeg中创建缓冲源

问题描述 投票:0回答:1

我想为视频创建一个AVFilter缓冲区。

我的源代码是

     AVFilterContext *buffersrc_ctx= nullptr;
     AVFilterContext *buffersink_ctx = nullptr;
     const AVFilter *buffersrc  = avfilter_get_by_name("buffer");
     const AVFilter *buffersink = avfilter_get_by_name("buffersink");
     AVFilterInOut *outputs = avfilter_inout_alloc();
     AVFilterInOut *inputs  = avfilter_inout_alloc();
     data->graph = avfilter_graph_alloc();

 snprintf(args, sizeof(args),
             "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
             data->codec_ctx->width,  data->codec_ctx->height,  data->codec_ctx->pix_fmt,
             data->codec_ctx->time_base.num, data->codec_ctx->time_base.den,
             data->codec_ctx->sample_aspect_ratio.num, data->codec_ctx->sample_aspect_ratio.den);

    ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in",
                                       args, NULL, filter_graph);
    if (ret < 0) {
        av_log(NULL, AV_LOG_ERROR, "Cannot create buffer source\n");
        goto end;
    }

我得到了以下错误信息

[in @ 0x1cdd9c0] 提供无效参数。不能创建一个缓冲区源

在源代码的开始部分,也删除了avfilter_register_all(); 。我想知道为什么会出现这个错误?

c++ ffmpeg video-processing
1个回答
0
投票

我在打开视频帧的地方添加了以下几行代码。按照这个链接来解决。https:/www.ffmpeg.orgdoxygen2.7filtering_video_8c-example.html

    /* select the video stream */
    ret = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, &dec, 0);
    if (ret < 0) {
        av_log(NULL, AV_LOG_ERROR, "Cannot find a video stream in the input file\n");
        return ret;
    }
    video_stream_index = ret;
    dec_ctx = fmt_ctx->streams[video_stream_index]->codec;
    av_opt_set_int(dec_ctx, "refcounted_frames", 1, 0);
© www.soinside.com 2019 - 2024. All rights reserved.