Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Marton Balint <cus@passwd.hu>
To: ffmpeg-devel@ffmpeg.org
Cc: Marton Balint <cus@passwd.hu>
Subject: [FFmpeg-devel] [PATCH 1/4] avfilter/trim: consume all available frames and avoid activate reschedule
Date: Thu, 24 Jul 2025 01:35:57 +0200
Message-ID: <20250723233604.29380-1-cus@passwd.hu> (raw)

There is no benefit in delaying processing all available frames.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 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".

             reply	other threads:[~2025-07-23 23:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-23 23:35 Marton Balint [this message]
2025-07-23 23:35 ` [FFmpeg-devel] [PATCH 2/4] avfilter/af_afade: factorize functions generating frames Marton Balint
2025-07-23 23:35 ` [FFmpeg-devel] [PATCH 3/4] avfilter/af_afade: fix check_input for empty streams Marton Balint
2025-07-23 23:36 ` [FFmpeg-devel] [PATCH 4/4] avfilter/af_afade: rework crossfade activate logic Marton Balint

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=20250723233604.29380-1-cus@passwd.hu \
    --to=cus@passwd.hu \
    --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