History

lavfi/libplacebo: support dovi metadata application

libplacebo supports automatic dolby vision application, but it requires us to switch to a new API. Also add some logic to strip the dolby vision metadata from the output frames in any case where we end up changing the colorimetry. The libplacebo dependency bump is justified because neither 184 nor 192 are part of any stable libplacebo release, so users have to build from git anyways for this filter to exist.

Niklas Haas committed 4 years ago

Commit db28bb81 parent da928652 files · +33 −4Browse files

Showing the changes to libavfilter (1 of 2 files). Show all

Unified · Split

libavfilter/vf_libplacebo.c+32−3
@@ -47,6 +47,7 @@ typedef struct LibplaceboContext { · 46 unmodified lines
47 int force_divisible_by;47 int force_divisible_by;
48 int normalize_sar;48 int normalize_sar;
49 int apply_filmgrain;49 int apply_filmgrain;
50 int apply_dovi;
50 int colorspace;51 int colorspace;
51 int color_range;52 int color_range;
52 int color_primaries;53 int color_primaries;
@@ -281,8 +282,16 @@ static int process_frames(AVFilterContext *avctx, AVFrame *out, AVFrame *in) · 228 unmodified lines
281 LibplaceboContext *s = avctx->priv;282 LibplaceboContext *s = avctx->priv;
282 struct pl_render_params params;283 struct pl_render_params params;
283 struct pl_frame image, target;284 struct pl_frame image, target;
284 ok = pl_map_avframe(s->gpu, &image, NULL, in);285 ok = pl_map_avframe_ex(s->gpu, &image, pl_avframe_params(
285 ok &= pl_map_avframe(s->gpu, &target, NULL, out);286 .frame = in,
287 .map_dovi = s->apply_dovi,
288 ));
289
290 ok &= pl_map_avframe_ex(s->gpu, &target, pl_avframe_params(
291 .frame = out,
292 .map_dovi = false,
293 ));
294
286 if (!ok) {295 if (!ok) {
287 err = AVERROR_EXTERNAL;296 err = AVERROR_EXTERNAL;
288 goto fail;297 goto fail;
@@ -381,7 +390,7 @@ fail: · 92 unmodified lines
381 390
382static int filter_frame(AVFilterLink *link, AVFrame *in)391static int filter_frame(AVFilterLink *link, AVFrame *in)
383{392{
384 int err;393 int err, changed;
385 AVFilterContext *ctx = link->dst;394 AVFilterContext *ctx = link->dst;
386 LibplaceboContext *s = ctx->priv;395 LibplaceboContext *s = ctx->priv;
387 AVFilterLink *outlink = ctx->outputs[0];396 AVFilterLink *outlink = ctx->outputs[0];
@@ -400,6 +409,14 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) · 12 unmodified lines
400 out->width = outlink->w;409 out->width = outlink->w;
401 out->height = outlink->h;410 out->height = outlink->h;
402 411
412 if (s->apply_dovi && av_frame_get_side_data(in, AV_FRAME_DATA_DOVI_METADATA)) {
413 /* Output of dovi reshaping is always BT.2020+PQ, so infer the correct
414 * output colorspace defaults */
415 out->colorspace = AVCOL_SPC_BT2020_NCL;
416 out->color_primaries = AVCOL_PRI_BT2020;
417 out->color_trc = AVCOL_TRC_SMPTE2084;
418 }
419
403 if (s->colorspace >= 0)420 if (s->colorspace >= 0)
404 out->colorspace = s->colorspace;421 out->colorspace = s->colorspace;
405 if (s->color_range >= 0)422 if (s->color_range >= 0)
@@ -411,6 +428,17 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) · 5 unmodified lines
411 428
412 RET(process_frames(ctx, out, in));429 RET(process_frames(ctx, out, in));
413 430
431 int changed_csp = s->colorspace != out->colorspace ||
432 s->color_range != out->color_range ||
433 s->color_trc != out->color_trc ||
434 s->color_primaries != out->color_primaries;
435
436 if (s->apply_dovi || changed_csp) {
437 /* Strip side data if no longer relevant */
438 av_frame_remove_side_data(out, AV_FRAME_DATA_DOVI_RPU_BUFFER);
439 av_frame_remove_side_data(out, AV_FRAME_DATA_DOVI_METADATA);
440 }
441
414 if (s->apply_filmgrain)442 if (s->apply_filmgrain)
415 av_frame_remove_side_data(out, AV_FRAME_DATA_FILM_GRAIN_PARAMS);443 av_frame_remove_side_data(out, AV_FRAME_DATA_FILM_GRAIN_PARAMS);
416 444
@@ -559,6 +587,7 @@ static const AVOption libplacebo_options[] = { · 142 unmodified lines
559 { "antiringing", "Antiringing strength (for non-EWA filters)", OFFSET(antiringing), AV_OPT_TYPE_FLOAT, {.dbl = 0.0}, 0.0, 1.0, DYNAMIC },587 { "antiringing", "Antiringing strength (for non-EWA filters)", OFFSET(antiringing), AV_OPT_TYPE_FLOAT, {.dbl = 0.0}, 0.0, 1.0, DYNAMIC },
560 { "sigmoid", "Enable sigmoid upscaling", OFFSET(sigmoid), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DYNAMIC },588 { "sigmoid", "Enable sigmoid upscaling", OFFSET(sigmoid), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DYNAMIC },
561 { "apply_filmgrain", "Apply film grain metadata", OFFSET(apply_filmgrain), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DYNAMIC },589 { "apply_filmgrain", "Apply film grain metadata", OFFSET(apply_filmgrain), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DYNAMIC },
590 { "apply_dolbyvision", "Apply Dolby Vision metadata", OFFSET(apply_dovi), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DYNAMIC },
562 591
563 { "deband", "Enable debanding", OFFSET(deband), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC },592 { "deband", "Enable debanding", OFFSET(deband), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC },
564 { "deband_iterations", "Deband iterations", OFFSET(deband_iterations), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 16, DYNAMIC },593 { "deband_iterations", "Deband iterations", OFFSET(deband_iterations), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 16, DYNAMIC },

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t