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 4F4D54BCA3 for ; Wed, 23 Jul 2025 23:36:18 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 6628468D219; Thu, 24 Jul 2025 02:36:15 +0300 (EEST) Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 49A0A68D0EC for ; Thu, 24 Jul 2025 02:36:08 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 9ACD6EBA8B; Thu, 24 Jul 2025 01:33:44 +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 aKLl3IRofjw6; Thu, 24 Jul 2025 01:33:41 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 9A2D7EBA7C; Thu, 24 Jul 2025 01:33:41 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Thu, 24 Jul 2025 01:35:57 +0200 Message-ID: <20250723233604.29380-1-cus@passwd.hu> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [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 Cc: Marton Balint Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: There is no benefit in delaying processing all available frames. 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".