[PATCH 1/5] configure: align libplacebo version check with reality
From: Niklas Haas <git@haasn.dev> This filter already failed to compile on older versions, because of an unconditional use of an API introduced in API version 220. Nobody noticed this, so I conclude that it's safe to bump the required version by now. --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index ed6cd97f6f..1433a5a6ac 100755 --- a/configure +++ b/configure @@ -7017,7 +7017,7 @@ enabled libopus && { require_pkg_config libopus opus opus_multistream.h opus_multistream_surround_encoder_create } } -enabled libplacebo && require_pkg_config libplacebo "libplacebo >= 4.192.0" libplacebo/vulkan.h pl_vulkan_create +enabled libplacebo && require_pkg_config libplacebo "libplacebo >= 5.229.0" libplacebo/vulkan.h pl_vulkan_create enabled libpulse && require_pkg_config libpulse libpulse pulse/pulseaudio.h pa_context_new enabled libqrencode && require_pkg_config libqrencode libqrencode qrencode.h QRcode_encodeString enabled libquirc && require libquirc quirc.h quirc_decode -lquirc -- 2.47.0
From: Niklas Haas <git@haasn.dev> These were introduced in libplacebo API version 220. We actually already map the field by default, but deinterlacing was never enabled unless the user explicitly forced it using extra_ops. --- doc/filters.texi | 19 +++++++++++++++++++ libavfilter/vf_libplacebo.c | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/doc/filters.texi b/doc/filters.texi index 4cefef6cbc..c7c8a5668e 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -16615,6 +16615,25 @@ Enable sigmoidal compression during upscaling. Reduces ringing slightly. Enabled by default. @end table +@subsubsection Deinterlacing +Deinterlacing is automatically supported when frames are tagged as interlaced, +however frames are not deinterlaced unless a deinterlacing algorithm is chosen. +@table @option +@item deinterlace +The the deinterlacing algorithm to use. +@table @samp +@item weave +No deinterlacing, weave fields together into a single frame. This is the default. +@item bob +Naive bob deinterlacing, simply repeat each field line twice. +@item yadif +Yet another deinterlacing filter. See the @ref{yadif} filter for more details. +@end table + +@item skip_spatial_check +Skip the spatial deinterlacing check when using @code{yadif} deinterlacing. +@end table + @subsubsection Debanding Libplacebo comes with a built-in debanding filter that is good at counteracting many common sources of banding and blocking. Turning this on is highly diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index e1c6629f6d..fbbc9d5cb7 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -49,6 +49,7 @@ static inline AVFrame *pl_get_mapped_avframe(const struct pl_frame *frame) typedef struct pl_options_t { // Backwards compatibility shim of this struct struct pl_render_params params; + struct pl_deinterlace_params deinterlace_params; struct pl_deband_params deband_params; struct pl_sigmoid_params sigmoid_params; struct pl_color_adjustment color_adjustment; @@ -211,6 +212,10 @@ typedef struct LibplaceboContext { int force_dither; int disable_fbos; + /* pl_deinterlace_params */ + int deinterlace; + int skip_spatial_check; + /* pl_deband_params */ int deband; int deband_iterations; @@ -372,6 +377,11 @@ static int update_settings(AVFilterContext *ctx) RET(av_parse_color(color_rgba, s->fillcolor, -1, s)); + opts->deinterlace_params = *pl_deinterlace_params( + .algo = s->deinterlace, + .skip_spatial_check = s->skip_spatial_check, + ); + opts->deband_params = *pl_deband_params( .iterations = s->deband_iterations, .threshold = s->deband_threshold, @@ -436,6 +446,7 @@ static int update_settings(AVFilterContext *ctx) .corner_rounding = s->corner_rounding, #endif + .deinterlace_params = &opts->deinterlace_params, .deband_params = s->deband ? &opts->deband_params : NULL, .sigmoid_params = s->sigmoid ? &opts->sigmoid_params : NULL, .color_adjustment = &opts->color_adjustment, @@ -1358,6 +1369,12 @@ static const AVOption libplacebo_options[] = { { "apply_filmgrain", "Apply film grain metadata", OFFSET(apply_filmgrain), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DYNAMIC }, { "apply_dolbyvision", "Apply Dolby Vision metadata", OFFSET(apply_dovi), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DYNAMIC }, + { "deinterlace", "Deinterlacing mode", OFFSET(deinterlace), AV_OPT_TYPE_INT, {.i64 = PL_DEINTERLACE_WEAVE}, 0, PL_DEINTERLACE_ALGORITHM_COUNT - 1, DYNAMIC, .unit = "deinterlace" }, + { "weave", "Weave fields together (no-op)", 0, AV_OPT_TYPE_CONST, {.i64 = PL_DEINTERLACE_WEAVE}, 0, 0, STATIC, .unit = "deinterlace" }, + { "bob", "Naive bob deinterlacing", 0, AV_OPT_TYPE_CONST, {.i64 = PL_DEINTERLACE_BOB}, 0, 0, STATIC, .unit = "deinterlace" }, + { "yadif", "Yet another deinterlacing filter", 0, AV_OPT_TYPE_CONST, {.i64 = PL_DEINTERLACE_YADIF}, 0, 0, STATIC, .unit = "deinterlace" }, + { "skip_spatial_check", "Skip yadif spatial check", OFFSET(skip_spatial_check), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC }, + { "deband", "Enable debanding", OFFSET(deband), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC }, { "deband_iterations", "Deband iterations", OFFSET(deband_iterations), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 16, DYNAMIC }, { "deband_threshold", "Deband threshold", OFFSET(deband_threshold), AV_OPT_TYPE_FLOAT, {.dbl = 4.0}, 0.0, 1024.0, DYNAMIC }, -- 2.47.0
From: Niklas Haas <git@haasn.dev> Avoids an unnecessary copy of the frame in the frame queue when not deinterlacing anyways. --- libavfilter/vf_libplacebo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index fbbc9d5cb7..933b086b69 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -972,7 +972,7 @@ static int handle_input(AVFilterContext *ctx, LibplaceboInput *input) pl_queue_push(input->queue, &(struct pl_source_frame) { .pts = in->pts * av_q2d(inlink->time_base), .duration = in->duration * av_q2d(inlink->time_base), - .first_field = pl_field_from_avframe(in), + .first_field = s->deinterlace ? pl_field_from_avframe(in) : PL_FIELD_NONE, .frame_data = in, .map = map_frame, .unmap = unmap_frame, -- 2.47.0
From: Niklas Haas <git@haasn.dev> --- libavfilter/vf_libplacebo.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index 933b086b69..7dc275f565 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -859,6 +859,8 @@ static int output_frame(AVFilterContext *ctx, int64_t pts) out->color_range = outlink->color_range; if (s->fps.num) out->duration = 1; + if (s->deinterlace) + out->flags &= ~(AV_FRAME_FLAG_INTERLACED | AV_FRAME_FLAG_TOP_FIELD_FIRST); if (s->apply_dovi && av_frame_get_side_data(ref, AV_FRAME_DATA_DOVI_METADATA)) { /* Output of dovi reshaping is always BT.2020+PQ, so infer the correct -- 2.47.0
From: Niklas Haas <git@haasn.dev> cf. the other deinterlacing-aware filters. --- doc/filters.texi | 5 +++++ libavfilter/vf_libplacebo.c | 23 ++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index c7c8a5668e..6f0c89489e 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -16632,6 +16632,11 @@ Yet another deinterlacing filter. See the @ref{yadif} filter for more details. @item skip_spatial_check Skip the spatial deinterlacing check when using @code{yadif} deinterlacing. + +@item send_fields +Output a frame for each field, rather than for each frame. Note that this will +always double the tagged output frame rate, even if the input does not contain +any interlaced frames. Disabled by default. @end table @subsubsection Debanding diff --git a/libavfilter/vf_libplacebo.c b/libavfilter/vf_libplacebo.c index 7dc275f565..528eabd6d0 100644 --- a/libavfilter/vf_libplacebo.c +++ b/libavfilter/vf_libplacebo.c @@ -215,6 +215,7 @@ typedef struct LibplaceboContext { /* pl_deinterlace_params */ int deinterlace; int skip_spatial_check; + int send_fields; /* pl_deband_params */ int deband; @@ -970,8 +971,7 @@ static int handle_input(AVFilterContext *ctx, LibplaceboInput *input) int64_t pts; while ((ret = ff_inlink_consume_frame(inlink, &in)) > 0) { - in->opaque = s; - pl_queue_push(input->queue, &(struct pl_source_frame) { + struct pl_source_frame src = { .pts = in->pts * av_q2d(inlink->time_base), .duration = in->duration * av_q2d(inlink->time_base), .first_field = s->deinterlace ? pl_field_from_avframe(in) : PL_FIELD_NONE, @@ -979,12 +979,21 @@ static int handle_input(AVFilterContext *ctx, LibplaceboInput *input) .map = map_frame, .unmap = unmap_frame, .discard = discard_frame, - }); + }; + + in->opaque = s; + pl_queue_push(input->queue, &src); if (!s->fps.num) { /* Internally queue an output frame for the same PTS */ pts = av_rescale_q(in->pts, inlink->time_base, outlink->time_base); av_fifo_write(input->out_pts, &pts, 1); + + if (s->send_fields && src.first_field != PL_FIELD_NONE) { + /* Queue the second field for interlaced content */ + pts += av_rescale_q(in->duration, inlink->time_base, outlink->time_base) / 2; + av_fifo_write(input->out_pts, &pts, 1); + } } } @@ -1242,6 +1251,13 @@ static int libplacebo_config_output(AVFilterLink *outlink) avctx->inputs[i]->time_base, AV_TIME_BASE / 2, AV_TIME_BASE_Q); } + + if (s->deinterlace && s->send_fields) { + const AVRational q2 = { 2, 1 }; + ol->frame_rate = av_mul_q(ol->frame_rate, q2); + /* Ensure output frame timestamps are divisible by two */ + outlink->time_base = av_div_q(outlink->time_base, q2); + } } /* Static variables */ @@ -1376,6 +1392,7 @@ static const AVOption libplacebo_options[] = { { "bob", "Naive bob deinterlacing", 0, AV_OPT_TYPE_CONST, {.i64 = PL_DEINTERLACE_BOB}, 0, 0, STATIC, .unit = "deinterlace" }, { "yadif", "Yet another deinterlacing filter", 0, AV_OPT_TYPE_CONST, {.i64 = PL_DEINTERLACE_YADIF}, 0, 0, STATIC, .unit = "deinterlace" }, { "skip_spatial_check", "Skip yadif spatial check", OFFSET(skip_spatial_check), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC }, + { "send_fields", "Output a frame for each field", OFFSET(send_fields), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC }, { "deband", "Enable debanding", OFFSET(deband), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC }, { "deband_iterations", "Deband iterations", OFFSET(deband_iterations), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 16, DYNAMIC }, -- 2.47.0
participants (1)
-
Niklas Haas