[FFmpeg-cvslog] lavfi/avf_showwaves: fix extra gaps at end of waveform

Paul B Mahol git at videolan.org
Sun Apr 21 22:14:29 EEST 2019


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sun Apr 21 21:06:25 2019 +0200| [dafcdeb258235b65b212f52f63cf23d19bd8af0f] | committer: Paul B Mahol

lavfi/avf_showwaves: fix extra gaps at end of waveform

Fixes #5931.

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

 libavfilter/avf_showwaves.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/libavfilter/avf_showwaves.c b/libavfilter/avf_showwaves.c
index bb7f4ea87e..0e683cf42d 100644
--- a/libavfilter/avf_showwaves.c
+++ b/libavfilter/avf_showwaves.c
@@ -559,7 +559,9 @@ static int push_single_pic(AVFilterLink *outlink)
     AVFilterContext *ctx = outlink->src;
     AVFilterLink *inlink = ctx->inputs[0];
     ShowWavesContext *showwaves = ctx->priv;
-    int64_t n = 0, max_samples = showwaves->total_samples / outlink->w;
+    int64_t n = 0, column_max_samples = showwaves->total_samples / outlink->w;
+    int64_t remaining_samples = showwaves->total_samples - (column_max_samples * outlink->w);
+    int64_t last_column_samples = column_max_samples + remaining_samples;
     AVFrame *out = showwaves->outpicref;
     struct frame_node *node;
     const int nb_channels = inlink->channels;
@@ -569,12 +571,12 @@ static int push_single_pic(AVFilterLink *outlink)
     int col = 0;
     int64_t *sum = showwaves->sum;
 
-    if (max_samples == 0) {
+    if (column_max_samples == 0) {
         av_log(ctx, AV_LOG_ERROR, "Too few samples\n");
         return AVERROR(EINVAL);
     }
 
-    av_log(ctx, AV_LOG_DEBUG, "Create frame averaging %"PRId64" samples per column\n", max_samples);
+    av_log(ctx, AV_LOG_DEBUG, "Create frame averaging %"PRId64" samples per column\n", column_max_samples);
 
     memset(sum, 0, nb_channels);
 
@@ -584,11 +586,13 @@ static int push_single_pic(AVFilterLink *outlink)
         const int16_t *p = (const int16_t *)frame->data[0];
 
         for (i = 0; i < frame->nb_samples; i++) {
+            int64_t max_samples = col == outlink->w - 1 ? last_column_samples: column_max_samples;
             int ch;
 
             for (ch = 0; ch < nb_channels; ch++)
                 sum[ch] += abs(p[ch + i*nb_channels]) << 1;
-            if (n++ == max_samples) {
+            n++;
+            if (n == max_samples) {
                 for (ch = 0; ch < nb_channels; ch++) {
                     int16_t sample = sum[ch] / max_samples;
                     uint8_t *buf = out->data[0] + col * pixstep;



More information about the ffmpeg-cvslog mailing list