[FFmpeg-cvslog] avfilter/*xfade: reduce memory consumption

Paul B Mahol git at videolan.org
Mon May 15 00:36:53 EEST 2023


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sun May 14 22:33:37 2023 +0200| [2a74826b027cb031acdf1f85519ba61cca932509] | committer: Paul B Mahol

avfilter/*xfade: reduce memory consumption

There is no always need for new buffers.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2a74826b027cb031acdf1f85519ba61cca932509
---

 libavfilter/af_afade.c | 13 +++++++++++++
 libavfilter/vf_xfade.c | 11 +++++++++++
 2 files changed, 24 insertions(+)

diff --git a/libavfilter/af_afade.c b/libavfilter/af_afade.c
index 48938384ff..2f45b12904 100644
--- a/libavfilter/af_afade.c
+++ b/libavfilter/af_afade.c
@@ -672,14 +672,27 @@ static int acrossfade_config_output(AVFilterLink *outlink)
     return 0;
 }
 
+static AVFrame *get_audio_buffer(AVFilterLink *inlink, int nb_samples)
+{
+    AVFilterContext *ctx = inlink->dst;
+    AudioFadeContext *s = ctx->priv;
+
+    return (s->crossfade_is_over ||
+            (ff_inlink_queued_samples(inlink) > s->nb_samples)) ?
+        ff_null_get_audio_buffer   (inlink, nb_samples) :
+        ff_default_get_audio_buffer(inlink, nb_samples);
+}
+
 static const AVFilterPad avfilter_af_acrossfade_inputs[] = {
     {
         .name         = "crossfade0",
         .type         = AVMEDIA_TYPE_AUDIO,
+        .get_buffer.audio = get_audio_buffer,
     },
     {
         .name         = "crossfade1",
         .type         = AVMEDIA_TYPE_AUDIO,
+        .get_buffer.audio = get_audio_buffer,
     },
 };
 
diff --git a/libavfilter/vf_xfade.c b/libavfilter/vf_xfade.c
index 9f66927365..5745a24173 100644
--- a/libavfilter/vf_xfade.c
+++ b/libavfilter/vf_xfade.c
@@ -2042,14 +2042,25 @@ static int xfade_activate(AVFilterContext *ctx)
     return FFERROR_NOT_READY;
 }
 
+static AVFrame *get_video_buffer(AVFilterLink *inlink, int w, int h)
+{
+    XFadeContext *s = inlink->dst->priv;
+
+    return s->xfade_is_over || !s->need_second ?
+        ff_null_get_video_buffer   (inlink, w, h) :
+        ff_default_get_video_buffer(inlink, w, h);
+}
+
 static const AVFilterPad xfade_inputs[] = {
     {
         .name          = "main",
         .type          = AVMEDIA_TYPE_VIDEO,
+        .get_buffer.video = get_video_buffer,
     },
     {
         .name          = "xfade",
         .type          = AVMEDIA_TYPE_VIDEO,
+        .get_buffer.video = get_video_buffer,
     },
 };
 



More information about the ffmpeg-cvslog mailing list