af_aresample: fix properties setting in the output buffer
authorStefano Sabatini <stefasab@gmail.com>
Fri, 16 Sep 2011 23:30:15 +0000 (01:30 +0200)
committerStefano Sabatini <stefasab@gmail.com>
Sat, 15 Oct 2011 22:52:23 +0000 (00:52 +0200)
In particular: set output timebase to 1/output_sample_rate, fix output
PTS computation, and do not forget to copy properties values from the
input buffer.

libavfilter/af_aresample.c

index 9af50cf..4cf6936 100644 (file)
@@ -83,6 +83,7 @@ static int config_output(AVFilterLink *outlink)
         aresample->out_rate = outlink->sample_rate;
     else
         outlink->sample_rate = aresample->out_rate;
+    outlink->time_base = (AVRational) {1, aresample->out_rate};
 
     //TODO: make the resampling parameters configurable
     aresample->resample = av_resample_init(aresample->out_rate, inlink->sample_rate,
@@ -270,13 +271,14 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref
 
         aresample->outsamplesref =
             avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, requested_out_nb_samples);
-        avfilter_copy_buffer_ref_props(aresample->outsamplesref, insamplesref);
-        aresample->outsamplesref->pts =
-            insamplesref->pts / inlink->sample_rate * outlink->sample_rate;
-        aresample->outsamplesref->audio->sample_rate = outlink->sample_rate;
         outlink->out_buf = aresample->outsamplesref;
     }
 
+    avfilter_copy_buffer_ref_props(aresample->outsamplesref, insamplesref);
+    aresample->outsamplesref->audio->sample_rate = outlink->sample_rate;
+    aresample->outsamplesref->pts =
+        av_rescale(outlink->sample_rate, insamplesref->pts, inlink->sample_rate);
+
     /* av_resample() works with planar audio buffers */
     if (!inlink->planar && nb_channels > 1) {
         int16_t *out[8];