[Libav-user] audio filter chain clicks
Ian Holbrough
ian at yospace.com
Wed Oct 24 13:24:57 CEST 2012
Found it, of course the problem is memory management.
It would seem that avfilter_copy_buf_props reuses the buffer, allocating
it to the target frame rather than copying it. Unfortunately if you then
call avfilter_unref_buffer before encoding frame the front of the buffer
gets trampled on, introducing the clicks.
Ian
On 10/23/12 12:18, Ian Holbrough wrote:
> Hi,
>
> I'm in the process of migrating to libavfilter based resampling using
> ffmpeg/libav 1.0 and the audio filter chain seems to be introducing
> audio clicks. Setting up a passthrough chain with...
>
> AVFilterContext* last = NULL;
> filterAudGraph = avfilter_graph_alloc();
>
> char args[255];
> snprintf(args, 255,
> "time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=0x%llx",
> 1, inpAudioCodec->sample_rate, inpAudioCodec->sample_rate,
> av_get_sample_fmt_name(inpAudioCodec->sample_fmt),
> inpAudioCodec->channel_layout);
>
> filterAudInp = tsUtilsInitFilter("abuffer", "audInput", args,
> NULL, filterAudGraph);
> last = filterAudInp;
>
> const enum AVSampleFormat formats[] = { AV_SAMPLE_FMT_S16, -1 };
> AVABufferSinkParams* params = av_abuffersink_params_alloc();
> params->sample_fmts = formats;
>
> filterAudOut = tsUtilsInitFilter("ffabuffersink", "audOutput",
> NULL, params, filterAudGraph);
> av_free(params);
>
> avfilter_link(last, 0, filterAudOut, 0);
>
> avfilter_graph_config(filterAudGraph, NULL);
>
> ...where...
>
> AVFilterContext* tsUtilsInitFilter(const char * filterName, const
> char* name,
> const char* arguments, void* opaque, AVFilterGraph* graph) {
>
> AVFilter* filter = avfilter_get_by_name(filterName);
>
> AVFilterContext* context = NULL;
> int ret = avfilter_graph_create_filter(&context, filter, name,
> arguments, opaque, graph);
> if (ret < 0) {
> die("tsUtilsInitFilter - failed to create filter context
> <%s>", name);
> }
>
> return context;
>
> }
>
> ...however, when a frame is added (I believe the input sample format,
> rate and channel layout is compatible with the required output) who's
> first few samples look like this...
>
> 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> 00000000 00000000
> 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> 00000000 ffffffff 00000000 00000000 00000000 00000000 00000000
> 00000000 00000000
> 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> 00000000 00000001 00000000 00000001 00000000 00000000 00000000
> 00000000 00000000
> 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> ffffffff 00000000
> ffffffff 00000000 00000000 00000000 00000000 00000000 00000000
> 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> 00000000 00000000
> 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> 00000000 00000000
>
> ...upon retrieving the same frame from the chain the first 4 samples
> look somewhat different...
>
> *000063f0 ffffb628 00002ff8 000008d9* 00000000 00000000 00000000
> 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> 00000000 00000000
> 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> 00000000 ffffffff 00000000 00000000 00000000 00000000 00000000
> 00000000 00000000
> 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> 00000000 00000001 00000000 00000001 00000000 00000000 00000000
> 00000000 00000000
> 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> ffffffff 00000000
> ffffffff 00000000 00000000 00000000 00000000 00000000 00000000
> 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> 00000000 00000000
> 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> 00000000 00000000 00000000 00000000 00000000 00000000 00000000
> 00000000 00000000
>
> ...the remainder of the frame is identical. These sample dumps are
> produced by...
>
> short* a = frame->data[0];
> for (int i = 0; i != frame->nb_samples; i++) {
> printf("%08x ", *(a++));
> if ((i % 16) == 15) printf("\n");
> }
>
> ....removing the filter chain and passing the decoded frames straight
> through to the encoder does not produce clicking. Any suggestions as
> to the cause would be gratefully received.
>
>
> Regards
>
> Ian
--
Ian Holbrough, Software Engineer
Yospace - Mobile Video Made Easy
Centurion House, London Road, Staines TW18 4AX
Switchboard: +44 (0)1784 466388
Fax: +44 (0)1784 466387
http://www.yospace.com
This email and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed.
Any unauthorised dissemination or copying of this email or its attachments,
and any use or disclosure of any information contained in them, is strictly
prohibited and may be illegal. If you have received the email in error
please notify contracts at yospace.com <mailto:contracts at yospace.com> and
delete it from your system.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20121024/86511408/attachment.html>
More information about the Libav-user
mailing list