diff options
author | Niklas Haas <git@haasn.dev> | 2023-06-15 15:41:57 +0200 |
---|---|---|
committer | Niklas Haas <git@haasn.dev> | 2023-06-20 17:09:57 +0200 |
commit | 93c7e8c0ae2948ba68d1b9ef7d939f96d06cbc50 (patch) | |
tree | be1019bc614c7f316c90bc7af84ce68523398258 | |
parent | 666c8aa4d7d302c15bed862b9c183f057b133e3a (diff) | |
download | ffmpeg-93c7e8c0ae2948ba68d1b9ef7d939f96d06cbc50.tar.gz |
lavfi/vf_libplacebo: factor out ref frame logic
Instead of finding the ref frame in output_frame() and then passing its
signature to update_crops(), pull out the logic and invoke it a second
time inside update_crops().
This may seem wasteful at present, but will actually become required in
the future, since update_crops() runs on *every* input, and needs values
specific to that input (which the signature isn't), while output_frame()
is only interested in a single input. It's much easier to just split the
logic cleanly.
-rw-r--r-- | libavfilter/vf_libplacebo.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index 0289187b46..b83df24a84 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -706,11 +706,21 @@ fail: return err; } +static const AVFrame *ref_frame(const struct pl_frame_mix *mix) +{ + for (int i = 0; i < mix->num_frames; i++) { + if (i+1 == mix->num_frames || mix->timestamps[i+1] > 0) + return pl_get_mapped_avframe(mix->frames[i]); + } + return NULL; +} + static void update_crops(AVFilterContext *ctx, struct pl_frame_mix *mix, struct pl_frame *target, - uint64_t ref_sig, double target_pts) + double target_pts) { LibplaceboContext *s = ctx->priv; + const AVFrame *ref = ref_frame(mix); for (int i = 0; i < mix->num_frames; i++) { // Mutate the `pl_frame.crop` fields in-place. This is fine because we @@ -745,7 +755,7 @@ static void update_crops(AVFilterContext *ctx, image->crop.x1 = image->crop.x0 + s->var_values[VAR_CROP_W]; image->crop.y1 = image->crop.y0 + s->var_values[VAR_CROP_H]; - if (mix->signatures[i] == ref_sig) { + if (src == ref) { /* Only update the target crop once, for the 'reference' frame */ target->crop.x0 = av_expr_eval(s->pos_x_pexpr, s->var_values, NULL); target->crop.y0 = av_expr_eval(s->pos_y_pexpr, s->var_values, NULL); @@ -768,25 +778,16 @@ static int output_frame(AVFilterContext *ctx, int64_t pts) LibplaceboInput *in = &s->input; AVFilterLink *outlink = ctx->outputs[0]; const AVPixFmtDescriptor *outdesc = av_pix_fmt_desc_get(outlink->format); + const AVFrame *ref = ref_frame(&in->mix); struct pl_frame target; - const AVFrame *ref; AVFrame *out; - uint64_t ref_sig; - if (!in->mix.num_frames) + if (!ref) return 0; out = ff_get_video_buffer(outlink, outlink->w, outlink->h); if (!out) return AVERROR(ENOMEM); - /* Use the last frame before current PTS value as reference */ - for (int i = 0; i < in->mix.num_frames; i++) { - if (i && in->mix.timestamps[i] > 0.0f) - break; - ref = pl_get_mapped_avframe(in->mix.frames[i]); - ref_sig = in->mix.signatures[i]; - } - RET(av_frame_copy_props(out, ref)); out->pts = pts; out->width = outlink->w; @@ -850,7 +851,7 @@ static int output_frame(AVFilterContext *ctx, int64_t pts) goto fail; } - update_crops(ctx, &in->mix, &target, ref_sig, out->pts * av_q2d(outlink->time_base)); + update_crops(ctx, &in->mix, &target, out->pts * av_q2d(outlink->time_base)); pl_render_image_mix(in->renderer, &in->mix, &target, &s->params); if (outdesc->flags & AV_PIX_FMT_FLAG_HWACCEL) { |