<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Found it, of course the problem is
      memory management.<br>
      <br>
      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.<br>
      <br>
      <br>
      Ian<br>
      <br>
      On 10/23/12 12:18, Ian Holbrough wrote:<br>
    </div>
    <blockquote cite="mid:50867CF8.4040205@yospace.com" type="cite">
      <meta http-equiv="content-type" content="text/html;
        charset=ISO-8859-1">
      Hi,<br>
      <br>
      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...<br>
      <br>
          AVFilterContext* last = NULL;<br>
          filterAudGraph = avfilter_graph_alloc();<br>
          <br>
          char args[255];    <br>
          snprintf(args, 255,
      "time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=0x%llx",
      <br>
              1, inpAudioCodec->sample_rate,
      inpAudioCodec->sample_rate, <br>
              av_get_sample_fmt_name(inpAudioCodec->sample_fmt),
      inpAudioCodec->channel_layout);<br>
              <br>
          filterAudInp = tsUtilsInitFilter("abuffer", "audInput", args,
      NULL, filterAudGraph);<br>
          last = filterAudInp;<br>
          <br>
          const enum AVSampleFormat formats[] = { AV_SAMPLE_FMT_S16, -1
      };<br>
          AVABufferSinkParams* params = av_abuffersink_params_alloc();<br>
          params->sample_fmts = formats;<br>
      <br>
          filterAudOut = tsUtilsInitFilter("ffabuffersink", "audOutput",
      NULL, params, filterAudGraph);<br>
          av_free(params);<br>
          <br>
          avfilter_link(last, 0, filterAudOut, 0);<br>
          <br>
          avfilter_graph_config(filterAudGraph, NULL);<br>
      <br>
      ...where...<br>
      <br>
      AVFilterContext* tsUtilsInitFilter(const char * filterName, const
      char* name, <br>
          const char* arguments, void* opaque, AVFilterGraph* graph)  {<br>
      <br>
          AVFilter* filter = avfilter_get_by_name(filterName);<br>
      <br>
          AVFilterContext* context = NULL;<br>
          int ret = avfilter_graph_create_filter(&context, filter,
      name, arguments, opaque, graph);<br>
          if (ret < 0) {<br>
              die("tsUtilsInitFilter - failed to create filter context
      <%s>", name);<br>
          }<br>
      <br>
          return context;<br>
      <br>
      }<br>
      <br>
      ...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...<br>
      <br>
      00000000 00000000 00000000 00000000 00000000 00000000 00000000
      00000000 00000000 00000000 00000000 00000000 00000000 00000000
      00000000 00000000 <br>
      00000000 00000000 00000000 00000000 00000000 00000000 00000000
      00000000 ffffffff 00000000 00000000 00000000 00000000 00000000
      00000000 00000000 <br>
      00000000 00000000 00000000 00000000 00000000 00000000 00000000
      00000000 00000001 00000000 00000001 00000000 00000000 00000000
      00000000 00000000 <br>
      00000000 00000000 00000000 00000000 00000000 00000000 00000000
      00000000 00000000 00000000 00000000 00000000 00000000 00000000
      ffffffff 00000000 <br>
      ffffffff 00000000 00000000 00000000 00000000 00000000 00000000
      00000000 00000000 00000000 00000000 00000000 00000000 00000000
      00000000 00000000 <br>
      00000000 00000000 00000000 00000000 00000000 00000000 00000000
      00000000 00000000 00000000 00000000 00000000 00000000 00000000
      00000000 00000000 <br>
      <br>
      ...upon retrieving the same frame from the chain the first 4
      samples look somewhat different...<br>
      <br>
      <b>000063f0 ffffb628 00002ff8 000008d9</b> 00000000 00000000
      00000000 00000000 00000000 00000000 00000000 00000000 00000000
      00000000 00000000 00000000 <br>
      00000000 00000000 00000000 00000000 00000000 00000000 00000000
      00000000 ffffffff 00000000 00000000 00000000 00000000 00000000
      00000000 00000000 <br>
      00000000 00000000 00000000 00000000 00000000 00000000 00000000
      00000000 00000001 00000000 00000001 00000000 00000000 00000000
      00000000 00000000 <br>
      00000000 00000000 00000000 00000000 00000000 00000000 00000000
      00000000 00000000 00000000 00000000 00000000 00000000 00000000
      ffffffff 00000000 <br>
      ffffffff 00000000 00000000 00000000 00000000 00000000 00000000
      00000000 00000000 00000000 00000000 00000000 00000000 00000000
      00000000 00000000 <br>
      00000000 00000000 00000000 00000000 00000000 00000000 00000000
      00000000 00000000 00000000 00000000 00000000 00000000 00000000
      00000000 00000000 <br>
      <br>
      ...the remainder of the frame is identical.  These sample dumps
      are produced by...<br>
      <br>
          short* a = frame->data[0];<br>
          for (int i = 0; i != frame->nb_samples; i++) {<br>
              printf("%08x ", *(a++));<br>
              if ((i % 16) == 15) printf("\n");        <br>
          }<br>
      <br>
      ....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.<br>
      <br>
      <br>
      Regards<br>
      <br>
      Ian <br>
    </blockquote>
    <br>
    <br>
    <div class="moz-signature">-- <br>
      <p>Ian Holbrough, Software Engineer<br>
        Yospace - Mobile Video Made Easy</p>
      <p>Centurion House, London Road, Staines TW18 4AX<br>
        Switchboard: +44 (0)1784 466388<br>
        Fax: +44 (0)1784 466387<br>
        <a href="http://www.yospace.com">http://www.yospace.com</a></p>
      <p>This email and any files transmitted with it are confidential
        and intended<br>
        solely for the use of the individual or entity to whom they are
        addressed.<br>
        Any unauthorised dissemination or copying of this email or its
        attachments,<br>
        and any use or disclosure of any information contained in them,
        is strictly<br>
        prohibited and may be illegal. If you have received the email in
        error<br>
        please notify <a href="mailto:contracts@yospace.com">contracts@yospace.com</a>
        and delete it from your system.</p>
    </div>
  </body>
</html>