Skip to content

Commit

Permalink
avfilter/*xfade: reduce memory consumption
Browse files Browse the repository at this point in the history
There is no always need for new buffers.
  • Loading branch information
richardpl committed May 14, 2023
1 parent 6759983 commit 2a74826
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions libavfilter/af_afade.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};

Expand Down
11 changes: 11 additions & 0 deletions libavfilter/vf_xfade.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};

Expand Down

0 comments on commit 2a74826

Please sign in to comment.