From: Paul B Mahol <onemda@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 2/3] avfilter/af_loudnorm: stop rewritting pts Date: Tue, 22 Feb 2022 17:46:15 +0100 Message-ID: <20220222164616.511012-2-onemda@gmail.com> (raw) In-Reply-To: <20220222164616.511012-1-onemda@gmail.com> Signed-off-by: Paul B Mahol <onemda@gmail.com> --- libavfilter/af_loudnorm.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/libavfilter/af_loudnorm.c b/libavfilter/af_loudnorm.c index 5b4b6e8548..7c8ac3a39d 100644 --- a/libavfilter/af_loudnorm.c +++ b/libavfilter/af_loudnorm.c @@ -86,7 +86,7 @@ typedef struct LoudNormContext { int attack_length; int release_length; - int64_t pts; + int64_t pts[30]; enum FrameType frame_type; int above_threshold; int prev_nb_samples; @@ -432,10 +432,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) av_frame_copy_props(out, in); } - if (s->pts == AV_NOPTS_VALUE) - s->pts = in->pts; + out->pts = s->pts[0]; + memmove(s->pts, &s->pts[1], (FF_ARRAY_ELEMS(s->pts) - 1) * sizeof(s->pts[0])); - out->pts = s->pts; src = (const double *)in->data[0]; dst = (double *)out->data[0]; buf = s->buf; @@ -502,7 +501,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) true_peak_limiter(s, dst, subframe_length, inlink->channels); ff_ebur128_add_frames_double(s->r128_out, dst, subframe_length); - s->pts += out->nb_samples = subframe_length; s->frame_type = INNER_FRAME; @@ -567,7 +565,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) if (s->index >= 30) s->index -= 30; s->prev_nb_samples = in->nb_samples; - s->pts += in->nb_samples; break; case FINAL_FRAME: @@ -625,13 +622,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) dst = (double *)out->data[0]; ff_ebur128_add_frames_double(s->r128_out, dst, in->nb_samples); - s->pts += in->nb_samples; break; } if (in != out) av_frame_free(&in); - return ff_filter_frame(outlink, out); } @@ -706,8 +701,17 @@ static int activate(AVFilterContext *ctx) if (ret < 0) return ret; - if (ret > 0) + if (ret > 0) { + if (s->frame_type == FIRST_FRAME) { + const int nb_samples = frame_size(inlink->sample_rate, 100); + + for (int i = 0; i < FF_ARRAY_ELEMS(s->pts); i++) + s->pts[i] = in->pts + i * nb_samples; + } else { + s->pts[29] = in->pts; + } ret = filter_frame(inlink, in); + } if (ret < 0) return ret; @@ -789,7 +793,6 @@ static int config_input(AVFilterLink *inlink) init_gaussian_filter(s); - s->pts = AV_NOPTS_VALUE; s->buf_index = s->prev_buf_index = s->limiter_buf_index = 0; -- 2.33.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-02-22 16:45 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-02-22 16:46 [FFmpeg-devel] [PATCH 1/3] avfilter/af_loudnorm: switch to activate Paul B Mahol 2022-02-22 16:46 ` Paul B Mahol [this message] 2022-02-22 16:46 ` [FFmpeg-devel] [PATCH 3/3] avfilter/af_loudnorm: remove hard clipping of samples Paul B Mahol
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220222164616.511012-2-onemda@gmail.com \ --to=onemda@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git