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
4747 int force_divisible_by;
4848 int normalize_sar;
4949 int apply_filmgrain;
50+ int apply_dovi;
5051 int colorspace;
5152 int color_range;
5253 int color_primaries;
@@ -281,8 +282,16 @@ static int process_frames(AVFilterContext *avctx, AVFrame *out, AVFrame *in) · 228 unmodified lines
281282 LibplaceboContext *s = avctx->priv;
282283 struct pl_render_params params;
283284 struct pl_frame image, target;
284− ok = pl_map_avframe(s->gpu, &image, NULL, in);
285− ok &= pl_map_avframe(s->gpu, &target, NULL, out);
285+ ok = pl_map_avframe_ex(s->gpu, &image, pl_avframe_params(
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+
286295 if (!ok) {
287296 err = AVERROR_EXTERNAL;
288297 goto fail;
@@ -381,7 +390,7 @@ fail: · 92 unmodified lines
381390
382391 static int filter_frame(AVFilterLink *link, AVFrame *in)
383392 {
384− int err;
393+ int err, changed;
385394 AVFilterContext *ctx = link->dst;
386395 LibplaceboContext *s = ctx->priv;
387396 AVFilterLink *outlink = ctx->outputs[0];
@@ -400,6 +409,14 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) · 12 unmodified lines
400409 out->width = outlink->w;
401410 out->height = outlink->h;
402411
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+
403420 if (s->colorspace >= 0)
404421 out->colorspace = s->colorspace;
405422 if (s->color_range >= 0)
@@ -411,6 +428,17 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) · 5 unmodified lines
411428
412429 RET(process_frames(ctx, out, in));
413430
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+
414442 if (s->apply_filmgrain)
415443 av_frame_remove_side_data(out, AV_FRAME_DATA_FILM_GRAIN_PARAMS);
416444
@@ -559,6 +587,7 @@ static const AVOption libplacebo_options[] = { · 142 unmodified lines
559587 { "antiringing", "Antiringing strength (for non-EWA filters)", OFFSET(antiringing), AV_OPT_TYPE_FLOAT, {.dbl = 0.0}, 0.0, 1.0, DYNAMIC },
560588 { "sigmoid", "Enable sigmoid upscaling", OFFSET(sigmoid), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, DYNAMIC },
561589 { "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 },
562591
563592 { "deband", "Enable debanding", OFFSET(deband), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DYNAMIC },
564593 { "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