gpt4 book ai didi

c++ - 带有 aecho 的 FFmpeg 过滤器配置无法配置所有链接和格式 - avfilter_graph_config

转载 作者:行者123 更新时间:2023-12-04 22:54:31 32 4
gpt4 key购买 nike

我正在按照 FFMpeg 的官方教程来创建过滤器链。 This教程展示了如何通过链传递数据:

The filter chain it uses is: * (input) -> abuffer -> volume ->aformat -> abuffersink -> (output)


这是我的代码 - 对不起锅炉代码,它只是 ffmpeg 方式:(
    frame = av_frame_alloc();
filterGraph = avfilter_graph_alloc();

if (!frame) {
*mediaLoadPointer = FAILED_TO_LOAD;
LOGE("FXProcessor::FXProcessor Could not allocate memory for frame");
return;
}

if (!filterGraph) {
*mediaLoadPointer = FAILED_TO_LOAD;
LOGE("FXProcessor::FXProcessor FXProcessor! %s", av_err2str(AVERROR(ENOMEM)));
return;
}

const AVFilter *abuffer;
const AVFilter *abuffersink;
AVFilterContext *aformat_ctx;
const AVFilter *aformat;
AVFilterContext *choisen_beat_fx_ctx;
const AVFilter *choisen_beat_fx;

/* Create the abuffer filter;
* it will be used for feeding the data into the graph. */
abuffer = avfilter_get_by_name("abuffer");
if (!abuffer) {
*mediaLoadPointer = FAILED_TO_LOAD;
LOGE("FXProcessor::FXProcessor Could not find the abuffer filter!");
return;
}
abuffer_ctx = avfilter_graph_alloc_filter(filterGraph, abuffer, "src");
if (!abuffer_ctx) {
*mediaLoadPointer = FAILED_TO_LOAD;
LOGE("FXProcessor::FXProcessor Could not allocate the abuffer_ctx instance! %s",
av_err2str(AVERROR(ENOMEM)));
return;
}

char ch_layout[64];
/* Set the filter options through the AVOptions API. */
av_get_channel_layout_string(ch_layout, sizeof(ch_layout), 0, AV_CH_LAYOUT_STEREO);
av_opt_set(abuffer_ctx, "channel_layout", ch_layout, AV_OPT_SEARCH_CHILDREN);
av_opt_set(abuffer_ctx, "sample_fmt", av_get_sample_fmt_name(AV_SAMPLE_FMT_FLT),
AV_OPT_SEARCH_CHILDREN);
av_opt_set_q(abuffer_ctx, "time_base", (AVRational) {1, defaultSampleRate},
AV_OPT_SEARCH_CHILDREN);
av_opt_set_int(abuffer_ctx, "sample_rate", defaultSampleRate, AV_OPT_SEARCH_CHILDREN);
/* Now initialize the filter; we pass NULL options, since we have already
* set all the options above. */

if (avfilter_init_str(abuffer_ctx, nullptr) < 0) {
*mediaLoadPointer = FAILED_TO_LOAD;
LOGE("FXProcessor::FXProcessor Could not initialize the abuffer filter!");
return;
}

// TODO: select FX's dynamically
/* Create aecho filter. */
if (true) {

choisen_beat_fx = avfilter_get_by_name("volume");
if (!choisen_beat_fx) {
*mediaLoadPointer = FAILED_TO_LOAD;
LOGE("FXProcessor::FXProcessor Could not find the aecho filter!");
return;
}

choisen_beat_fx_ctx = avfilter_graph_alloc_filter(filterGraph, choisen_beat_fx, "echo");
if (!choisen_beat_fx_ctx) {
*mediaLoadPointer = FAILED_TO_LOAD;
LOGE("FXProcessor::FXProcessor Could not allocate the choisen_beat_fx_ctx instance! %s",
av_err2str(AVERROR(ENOMEM)));
return;
}

av_opt_set (choisen_beat_fx_ctx, "volume", AV_STRINGIFY(0.5), AV_OPT_SEARCH_CHILDREN);

if (avfilter_init_str(choisen_beat_fx_ctx, nullptr) < 0) {
*mediaLoadPointer = FAILED_TO_LOAD;
LOGE("FXProcessor::FXProcessor Could not initialize the choisen_beat_fx_ctx filter!");
return;
}
}

/* Create the aformat filter;
* it ensures that the output is of the format we want. */
aformat = avfilter_get_by_name("aformat");
if (!aformat) {
*mediaLoadPointer = FAILED_TO_LOAD;
LOGE("FXProcessor::FXProcessor Could not find the aformat filter!");
return;
}
aformat_ctx = avfilter_graph_alloc_filter(filterGraph, aformat, "aformat");
if (!aformat_ctx) {
*mediaLoadPointer = FAILED_TO_LOAD;
LOGE("FXProcessor::FXProcessor Could not allocate the aformat instance!");
return;
}

av_opt_set(aformat_ctx, "sample_fmts", av_get_sample_fmt_name(AV_SAMPLE_FMT_FLT),
AV_OPT_SEARCH_CHILDREN);
av_opt_set_int(aformat_ctx, "sample_rates", defaultSampleRate, AV_OPT_SEARCH_CHILDREN);
av_get_channel_layout_string(ch_layout, sizeof(ch_layout), 0, AV_CH_LAYOUT_STEREO);
av_opt_set(aformat_ctx, "channel_layouts", ch_layout, AV_OPT_SEARCH_CHILDREN);

if (avfilter_init_str(aformat_ctx, nullptr) < 0) {
*mediaLoadPointer = FAILED_TO_LOAD;
LOGE("FXProcessor::FXProcessor Could not initialize the aformat filter!");
return;
}

/* Finally create the abuffersink filter;
* it will be used to get the filtered data out of the graph. */
abuffersink = avfilter_get_by_name("abuffersink");
if (!abuffersink) {
*mediaLoadPointer = FAILED_TO_LOAD;
LOGE("FXProcessor::FXProcessor Could not find the abuffersink filter!");
return;
}

abuffersink_ctx = avfilter_graph_alloc_filter(filterGraph, abuffersink, "sink");
if (!abuffersink_ctx) {
*mediaLoadPointer = FAILED_TO_LOAD;
LOGE("FXProcessor::FXProcessor Could not allocate the abuffersink instance!");
return;
}

/* This filter takes no options. */
if (avfilter_init_str(abuffersink_ctx, nullptr) < 0) {
*mediaLoadPointer = FAILED_TO_LOAD;
LOGE("FXProcessor::FXProcessor Could not initialize the abuffersink instance.!");
return;
}

/* Connect the filters;
* in this simple case the filters just form a linear chain. */
if (avfilter_link(abuffer_ctx, 0, choisen_beat_fx_ctx, 0) != 0) {
*mediaLoadPointer = FAILED_TO_LOAD;
LOGE("FXProcessor::FXProcessor Error connecting filters.!");
return;
}
if (avfilter_link(choisen_beat_fx_ctx, 0, aformat_ctx, 0) != 0) {
*mediaLoadPointer = FAILED_TO_LOAD;
LOGE("FXProcessor::FXProcessor Error connecting filters.!");
return;
}
if (avfilter_link(aformat_ctx, 0, abuffersink_ctx, 0) != 0) {
*mediaLoadPointer = FAILED_TO_LOAD;
LOGE("FXProcessor::FXProcessor Error connecting filters.!");
return;
}

/* Configure the graph. */
if (avfilter_graph_config(filterGraph, nullptr) < 0) {
*mediaLoadPointer = FAILED_TO_LOAD;
LOGE("FXProcessor::FXProcessor Error configuring the filter graph!");
return;
}
当链是时,此代码工作正常
  • (input) -> abuffer -> aecho-> aformat -> abuffersink -> (output)

但是,我想使用 adelay而不是 volume筛选。所以我想要:

The filter chain it uses is: * (input) -> abuffer -> volume ->aformat -> abuffersink -> (output)


我将代码更改为
choisen_beat_fx = avfilter_get_by_name("volume");
choisen_beat_fx = avfilter_get_by_name("aecho");
并删除了该行
av_opt_set    (choisen_beat_fx_ctx, "volume",     AV_STRINGIFY(0.5), AV_OPT_SEARCH_CHILDREN);
一切都很顺利,直到最后一行。 avfilter_graph_config失败并返回负值。函数文档:

avfilter_graph_config: Check validity and configure all the links andformats in the graph.


所以我的猜测是我需要额外的链接来将 aecho 插入到我的链中?如何将 aecho 插入我的过滤器链中?

最佳答案

好的,问题是,我需要使用 aresample 进行编译过滤这个工作。我重新编译并神奇地现在它可以工作了。
这是我发现问题的方法。创建一个通用日志回调:

void ffmpegErrorCallback(void *ptr, int level, const char *fmt, va_list vargs) {
LOGE("ffmpegErrorCallback Error Occurred! Err: %s", fmt);
}

av_log_set_level(AV_LOG_ERROR);
av_log_set_callback(ffmpegErrorCallback);
FFmpeg 现在会将错误记录为人类可读的消息。它告诉我它找不到 aresample筛选。这就是我解决问题的方法。

关于c++ - 带有 aecho 的 FFmpeg 过滤器配置无法配置所有链接和格式 - avfilter_graph_config,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65819704/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com