[FFmpeg-cvslog] avfilter/avf_showfreqs: properly handle pts

Paul B Mahol git at videolan.org
Sun Jan 31 22:18:36 CET 2016


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sun Jan 31 21:38:49 2016 +0100| [4ab4793c155e66ce7845831a5761c2bc0d04b035] | committer: Paul B Mahol

avfilter/avf_showfreqs: properly handle pts

Signed-off-by: Paul B Mahol <onemda at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4ab4793c155e66ce7845831a5761c2bc0d04b035
---

 libavfilter/avf_showfreqs.c |   19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/libavfilter/avf_showfreqs.c b/libavfilter/avf_showfreqs.c
index 6323887..af6e4c2 100644
--- a/libavfilter/avf_showfreqs.c
+++ b/libavfilter/avf_showfreqs.c
@@ -154,6 +154,15 @@ static int query_formats(AVFilterContext *ctx)
     return 0;
 }
 
+static av_cold int init(AVFilterContext *ctx)
+{
+    ShowFreqsContext *s = ctx->priv;
+
+    s->pts = AV_NOPTS_VALUE;
+
+    return 0;
+}
+
 static int config_output(AVFilterLink *outlink)
 {
     AVFilterContext *ctx = outlink->src;
@@ -423,8 +432,12 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     AVFilterContext *ctx = inlink->dst;
     ShowFreqsContext *s = ctx->priv;
     AVFrame *fin = NULL;
+    int consumed = 0;
     int ret = 0;
 
+    if (s->pts == AV_NOPTS_VALUE)
+        s->pts = in->pts - av_audio_fifo_size(s->fifo);
+
     av_audio_fifo_write(s->fifo, (void **)in->extended_data, in->nb_samples);
     while (av_audio_fifo_size(s->fifo) >= s->win_size) {
         fin = ff_get_audio_buffer(inlink, s->win_size);
@@ -433,8 +446,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
             goto fail;
         }
 
-        fin->pts = s->pts;
-        s->pts += s->hop_size;
+        fin->pts = s->pts + consumed;
+        consumed += s->hop_size;
         ret = av_audio_fifo_peek(s->fifo, (void **)fin->extended_data, s->win_size);
         if (ret < 0)
             goto fail;
@@ -447,6 +460,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     }
 
 fail:
+    s->pts = AV_NOPTS_VALUE;
     av_frame_free(&fin);
     av_frame_free(&in);
     return ret;
@@ -491,6 +505,7 @@ static const AVFilterPad showfreqs_outputs[] = {
 AVFilter ff_avf_showfreqs = {
     .name          = "showfreqs",
     .description   = NULL_IF_CONFIG_SMALL("Convert input audio to a frequencies video output."),
+    .init          = init,
     .uninit        = uninit,
     .query_formats = query_formats,
     .priv_size     = sizeof(ShowFreqsContext),



More information about the ffmpeg-cvslog mailing list