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;