<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<style>
font{
line-height: 1.5;
}
</style>
<div style="font-family:"微软雅黑"; font-size: 16px; color:#000000; line-height:1.5;">
<div>
This is my code which copy from doc/examples/filter_audio.c</div><div>---------------------------------------<br><div>//===============================================filter===========</div><div>//audio : abuffer -> volume -> aformat -> abuffersink</div><div>int init_filter_graph(AVFilterGraph **graph, AVFilterContext **src, AVFilterContext **sink){</div><div> AVFilterGraph *filter_graph;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div> AVFilterContext *abuffer_ctx;</div><div> AVFilter *abuffer;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div> AVFilterContext *volume_ctx;</div><div> AVFilter *volume;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div> AVFilterContext *aformat_ctx;</div><div> AVFilter *aformat;</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div> AVFilterContext *abuffersink_ctx;</div><div> AVFilter *abuffersink;</div><div><br></div><div> AVDictionary *options_dict = NULL;</div><div> uint8_t options_str[1024];</div><div> uint8_t ch_layout[64];</div><div><br></div><div> int err;</div><div><br></div><div> /* Create a new filtergraph, which will contain all the filters. */</div><div> filter_graph = avfilter_graph_alloc();</div><div> if (!filter_graph) {</div><div> loge("Unable to create filter graph.");</div><div> return AVERROR(ENOMEM);</div><div> }</div><div><br></div><div> /* Create the abuffer filter;</div><div> * it will be used for feeding the data into the graph. */</div><div> abuffer = avfilter_get_by_name("abuffer");</div><div> if (!abuffer) {</div><div> loge("Could not find the abuffer filter.");</div><div> return AVERROR_FILTER_NOT_FOUND;</div><div> }else{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>logd("find abuffer filter.");</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div> abuffer_ctx = avfilter_graph_alloc_filter(filter_graph, abuffer, "src");</div><div> if (!abuffer_ctx) {</div><div> loge("Could not allocate the abuffer instance.");</div><div> return AVERROR(ENOMEM);</div><div> }</div><div><br></div><div> /* Set the filter options through the AVOptions API. */</div><div> av_get_channel_layout_string(ch_layout, sizeof(ch_layout), 0, AV_CH_LAYOUT_MONO); //TODO</div><div> av_opt_set (abuffer_ctx, "channel_layout", ch_layout, AV_OPT_SEARCH_CHILDREN);</div><div> av_opt_set (abuffer_ctx, "sample_fmt", av_get_sample_fmt_name(AV_SAMPLE_FMT_S16), AV_OPT_SEARCH_CHILDREN);//TODO</div><div> av_opt_set_q (abuffer_ctx, "time_base", (AVRational){ 1, 16000 }, AV_OPT_SEARCH_CHILDREN);//TODO</div><div> av_opt_set_int(abuffer_ctx, "sample_rate", 16000, AV_OPT_SEARCH_CHILDREN);//TODO</div><div><br></div><div> /* Now initialize the filter; we pass NULL options, since we have already set all the options above. */</div><div> err = avfilter_init_str(abuffer_ctx, NULL);</div><div> if (err < 0) {</div><div> loge("Could not initialize the abuffer filter.");</div><div> return err;</div><div> }</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div> /* Create volume filter. */</div><div> volume = avfilter_get_by_name("volume");</div><div> if (!volume) {</div><div> loge("Could not find the volume filter.");</div><div> return AVERROR_FILTER_NOT_FOUND;</div><div> }else{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>logd("find volume filter.");</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div> volume_ctx = avfilter_graph_alloc_filter(filter_graph, volume, "volume");</div><div> if (!volume_ctx) {</div><div> loge("Could not allocate the volume instance.");</div><div> return AVERROR(ENOMEM);</div><div> }</div><div><br></div><div> /* A different way of passing the options is as key/value pairs in a dictionary. */</div><div> //av_dict_set(&options_dict, "volume", AV_STRINGIFY(1.5), 0);//150% of current volume</div><div> av_dict_set(&options_dict, "volume", AV_STRINGIFY(0.90), 0);</div><div> err = avfilter_init_dict(volume_ctx, &options_dict);</div><div> av_dict_free(&options_dict);</div><div> if (err < 0) {</div><div> loge("Could not initialize the volume filter.");</div><div> return err;</div><div> }</div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><span class="Apple-tab-span" style="white-space:pre"> </span></div><div><br></div><div> /* Create the aformat filter; it ensures that the output is of the format we want. */</div><div> aformat = avfilter_get_by_name("aformat");</div><div> if (!aformat) {</div><div> loge("Could not find the aformat filter.");</div><div> return AVERROR_FILTER_NOT_FOUND;</div><div> }else{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>logd("find aformat filter.");</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div> aformat_ctx = avfilter_graph_alloc_filter(filter_graph, aformat, "aformat");</div><div> if (!aformat_ctx) {</div><div> loge("Could not allocate the aformat instance.");</div><div> return AVERROR(ENOMEM);</div><div> }</div><div><br></div><div> /* A third way of passing the options is in a string of the form key1=value1:key2=value2.... */</div><div> snprintf(options_str, sizeof(options_str),</div><div> "sample_fmts=%s:sample_rates=%d:channel_layouts=0x%"PRIx64,</div><div> av_get_sample_fmt_name(AV_SAMPLE_FMT_S16), 16000,</div><div> (uint64_t)AV_CH_LAYOUT_MONO);</div><div> err = avfilter_init_str(aformat_ctx, options_str);</div><div> if (err < 0) {</div><div> //av_log(NULL, AV_LOG_ERROR, "Could not initialize the aformat filter.\n");</div><div> loge("Could not initialize the aformat filter.");</div><div> return err;</div><div> }</div><div><br></div><div> /* Finally create the abuffersink filter; it will be used to get the filtered data out of the graph. */</div><div> abuffersink = avfilter_get_by_name("abuffersink");</div><div> if (!abuffersink) {</div><div> loge("Could not find the abuffersink filter.");</div><div> return AVERROR_FILTER_NOT_FOUND;</div><div> }else{</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>logd("find abuffersink filter.");</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div><br></div><div> abuffersink_ctx = avfilter_graph_alloc_filter(filter_graph, abuffersink, "sink");</div><div> if (!abuffersink_ctx) {</div><div> loge("Could not allocate the abuffersink instance.");</div><div> return AVERROR(ENOMEM);</div><div> }</div><div><br></div><div> /* This filter takes no options. */</div><div> err = avfilter_init_str(abuffersink_ctx, NULL);</div><div> if (err < 0) {</div><div> loge("Could not initialize the abuffersink instance.");</div><div> return err;</div><div> }</div><div><br></div><div> /* Connect the filters;</div><div> * in this simple case the filters just form a linear chain. */</div><div> err = avfilter_link(abuffer_ctx, 0, volume_ctx, 0);</div><div> if (err >= 0)//zero on success</div><div> err = avfilter_link(volume_ctx, 0, aformat_ctx, 0);</div><div> if (err >= 0)</div><div> err = avfilter_link(aformat_ctx, 0, abuffersink_ctx, 0);</div><div> if (err < 0) {</div><div> loge("Error connecting filters");</div><div> return err;</div><div> }</div><div><br></div><div> /* Configure the graph. */</div><div> err = avfilter_graph_config(filter_graph, NULL);</div><div> if (err < 0) {</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>uint8_t errstr[1024];</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>av_strerror(err, errstr, sizeof(errstr));<span class="Apple-tab-span" style="white-space:pre"> </span></div><div> //av_log(NULL, AV_LOG_ERROR, "Error configuring the filter graph\n");</div><div> loge("Error configuring the filter graph:%d,%s", err, errstr);</div><div> return err;</div><div> }</div><div><br></div><div> *graph = filter_graph;</div><div> *src = abuffer_ctx;</div><div> *sink = abuffersink_ctx;</div><div> return 0;</div><div>}</div>
--------------------------------------<br>
<div id="ntes-pcmail-signature" style="font-family:'微软雅黑'">
<style type="text/css">
a#ntes-pcmail-signature-default:hover {
text-decoration: underline;
color: #3593db;
cursor: pointer;
}
</style>
<font style="padding: 0; margin:0;">
<div id="ntes-pcmail-signature-default" style="font-size:14px; color:#000; text-decoration: none;">the output log is:</div><div id="ntes-pcmail-signature-default" style="font-size:14px; color:#000; text-decoration: none;"><div id="ntes-pcmail-signature-default"> :find abuffer filter.</div><div id="ntes-pcmail-signature-default">: find volume filter.</div><div id="ntes-pcmail-signature-default">: find aformat filter.</div><div id="ntes-pcmail-signature-default">: find abuffersink filter.</div><div id="ntes-pcmail-signature-default">: Error configuring the filter graph:-22,Invalid argument</div><div id="ntes-pcmail-signature-default"><br></div><div id="ntes-pcmail-signature-default">can any friends help me?thanks so much for your help.</div></div><div id="ntes-pcmail-signature-default" style="font-size:14px; color:#000; text-decoration: none;"><br></div> </font>
</div><br>
</div>
</div>
</body>
</html>