From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id A164B4B0F7 for ; Tue, 29 Jul 2025 20:00:15 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id B8B9368BA25; Tue, 29 Jul 2025 23:00:10 +0300 (EEST) Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id B5620689F22 for ; Tue, 29 Jul 2025 23:00:02 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 9C3DAEA7B6 for ; Tue, 29 Jul 2025 21:57:43 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bzg-uHpsn326 for ; Tue, 29 Jul 2025 21:57:34 +0200 (CEST) Received: from iq (iq [217.27.212.140]) by iq.passwd.hu (Postfix) with ESMTPS id 5B065EA6C9 for ; Tue, 29 Jul 2025 21:57:34 +0200 (CEST) Date: Tue, 29 Jul 2025 21:57:34 +0200 (CEST) From: Marton Balint To: FFmpeg development discussions and patches In-Reply-To: <20250723233604.29380-1-cus@passwd.hu> Message-ID: <9fac858a-aa92-e122-5ee8-fff2790d95d7@passwd.hu> References: <20250723233604.29380-1-cus@passwd.hu> MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH 1/4] avfilter/trim: consume all available frames and avoid activate reschedule X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Thu, 24 Jul 2025, Marton Balint wrote: > There is no benefit in delaying processing all available frames. Will apply the series. Regards, Marton > > Signed-off-by: Marton Balint > --- > libavfilter/trim.c | 42 +++++++++++++++++------------------------- > 1 file changed, 17 insertions(+), 25 deletions(-) > > diff --git a/libavfilter/trim.c b/libavfilter/trim.c > index 7200680716..6d1016ac81 100644 > --- a/libavfilter/trim.c > +++ b/libavfilter/trim.c > @@ -90,10 +90,8 @@ static int trim_filter_frame(AVFilterLink *inlink, AVFrame *frame) > int drop; > > /* drop everything if EOF has already been returned */ > - if (s->eof) { > - av_frame_free(&frame); > + if (s->eof) > return 0; > - } > > if (s->start_frame >= 0 || s->start_pts != AV_NOPTS_VALUE) { > drop = 1; > @@ -131,13 +129,10 @@ static int trim_filter_frame(AVFilterLink *inlink, AVFrame *frame) > > s->nb_frames++; > > - return ff_filter_frame(ctx->outputs[0], frame); > + return 1; > > drop: > - if (!s->eof) > - ff_filter_set_ready(ctx, 100); > s->nb_frames++; > - av_frame_free(&frame); > return 0; > } > #endif // CONFIG_TRIM_FILTER > @@ -152,10 +147,8 @@ static int atrim_filter_frame(AVFilterLink *inlink, AVFrame *frame) > int drop; > > /* drop everything if EOF has already been returned */ > - if (s->eof) { > - av_frame_free(&frame); > + if (s->eof) > return 0; > - } > > if (frame->pts != AV_NOPTS_VALUE) > pts = av_rescale_q(frame->pts, inlink->time_base, > @@ -230,10 +223,8 @@ static int atrim_filter_frame(AVFilterLink *inlink, AVFrame *frame) > > if (start_sample) { > AVFrame *out = ff_get_audio_buffer(ctx->outputs[0], end_sample - start_sample); > - if (!out) { > - av_frame_free(&frame); > + if (!out) > return AVERROR(ENOMEM); > - } > > av_frame_copy_props(out, frame); > av_samples_copy(out->extended_data, frame->extended_data, 0, start_sample, > @@ -243,18 +234,16 @@ static int atrim_filter_frame(AVFilterLink *inlink, AVFrame *frame) > out->pts += av_rescale_q(start_sample, (AVRational){ 1, out->sample_rate }, > inlink->time_base); > > - av_frame_free(&frame); > - frame = out; > + av_frame_unref(frame); > + av_frame_move_ref(frame, out); > + av_frame_free(&out); > } else > frame->nb_samples = end_sample; > > - return ff_filter_frame(ctx->outputs[0], frame); > + return 1; > > drop: > - if (!s->eof) > - ff_filter_set_ready(ctx, 100); > s->nb_samples += frame->nb_samples; > - av_frame_free(&frame); > return 0; > } > #endif // CONFIG_ATRIM_FILTER > @@ -295,18 +284,21 @@ static int activate(AVFilterContext *ctx) > TrimContext *s = ctx->priv; > AVFilterLink *inlink = ctx->inputs[0]; > AVFilterLink *outlink = ctx->outputs[0]; > + AVFrame *frame = NULL; > + int ret; > > FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink); > > - if (!s->eof && ff_inlink_queued_frames(inlink)) { > - AVFrame *frame = NULL; > - int ret; > - > - ret = ff_inlink_consume_frame(inlink, &frame); > + while ((ret = ff_inlink_consume_frame(inlink, &frame))) { > if (ret < 0) > return ret; > + > + ret = s->filter_frame(inlink, frame); > if (ret > 0) > - return s->filter_frame(inlink, frame); > + return ff_filter_frame(outlink, frame); > + av_frame_free(&frame); > + if (ret < 0) > + return ret; > } > > FF_FILTER_FORWARD_STATUS(inlink, outlink); > -- > 2.43.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". > _______________________________________________ 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".