vo_gpu_next: parse Dolby Vision metadata for dynamic scene brightness

Improves playback for Dolby Vision video files as the metadata can be
used instead of requiring `hdr-compute-peak=yes`.
This commit is contained in:
quietvoid 2023-02-13 21:28:40 -05:00 committed by Niklas Haas
parent 0d82afbc7f
commit 41ad51bda2
3 changed files with 53 additions and 16 deletions

View File

@ -1,6 +1,10 @@
#include "common/common.h"
#include "utils.h"
#if PL_API_VER >= 251
#include <libplacebo/utils/dolbyvision.h>
#endif
static const int pl_log_to_msg_lev[PL_LOG_ALL+1] = {
[PL_LOG_FATAL] = MSGL_FATAL,
[PL_LOG_ERR] = MSGL_ERR,
@ -165,3 +169,41 @@ enum pl_chroma_location mp_chroma_to_pl(enum mp_chroma_location chroma)
MP_ASSERT_UNREACHABLE();
}
void mp_map_dovi_metadata_to_pl(struct mp_image *mpi,
struct pl_frame *frame)
{
#ifdef PL_HAVE_LAV_DOLBY_VISION
if (mpi->dovi) {
const AVDOVIMetadata *metadata = (AVDOVIMetadata *) mpi->dovi->data;
const AVDOVIRpuDataHeader *header = av_dovi_get_header(metadata);
if (header->disable_residual_flag) {
// Only automatically map DoVi RPUs that don't require an EL
struct pl_dovi_metadata *dovi = talloc_ptrtype(mpi, dovi);
#if PL_API_VER >= 250
pl_frame_map_avdovi_metadata(frame, dovi, metadata);
#else // back-compat fallback for older libplacebo
const AVDOVIColorMetadata *color = av_dovi_get_color(metadata);
pl_map_dovi_metadata(dovi, metadata);
frame->repr.dovi = dovi;
frame->repr.sys = PL_COLOR_SYSTEM_DOLBYVISION;
frame->color.primaries = PL_COLOR_PRIM_BT_2020;
frame->color.transfer = PL_COLOR_TRC_PQ;
frame->color.hdr.min_luma =
pl_hdr_rescale(PL_HDR_PQ, PL_HDR_NITS, color->source_min_pq / 4095.0f);
frame->color.hdr.max_luma =
pl_hdr_rescale(PL_HDR_PQ, PL_HDR_NITS, color->source_max_pq / 4095.0f);
#endif
}
}
#if PL_API_VER >= 251 && defined(PL_HAVE_LIBDOVI)
if (mpi->dovi_buf)
pl_hdr_metadata_from_dovi_rpu(&frame->color.hdr, mpi->dovi_buf->data,
mpi->dovi_buf->size);
#endif
#endif // PL_HAVE_LAV_DOLBY_VISION
}

View File

@ -1,12 +1,18 @@
#pragma once
#include "config.h"
#include "common/common.h"
#include "common/msg.h"
#include "video/csputils.h"
#include "video/mp_image.h"
#include <libavutil/buffer.h>
#include <libplacebo/common.h>
#include <libplacebo/log.h>
#include <libplacebo/colorspace.h>
#include <libplacebo/renderer.h>
#include <libplacebo/utils/libav.h>
pl_log mppl_log_create(void *tactx, struct mp_log *log);
void mppl_log_set_probing(pl_log log, bool probing);
@ -27,3 +33,6 @@ enum pl_color_system mp_csp_to_pl(enum mp_csp csp);
enum pl_color_levels mp_levels_to_pl(enum mp_csp_levels levels);
enum pl_alpha_mode mp_alpha_to_pl(enum mp_alpha_type alpha);
enum pl_chroma_location mp_chroma_to_pl(enum mp_chroma_location chroma);
void mp_map_dovi_metadata_to_pl(struct mp_image *mpi,
struct pl_frame *frame);

View File

@ -699,22 +699,8 @@ static bool map_frame(pl_gpu gpu, pl_tex *tex, const struct pl_source_frame *src
// Update chroma location, must be done after initializing planes
pl_frame_set_chroma_location(frame, mp_chroma_to_pl(par->chroma_location));
#ifdef PL_HAVE_LAV_DOLBY_VISION
if (mpi->dovi) {
const AVDOVIMetadata *metadata = (AVDOVIMetadata *) mpi->dovi->data;
struct pl_dovi_metadata *dovi = talloc_ptrtype(mpi, dovi);
const AVDOVIColorMetadata *color = av_dovi_get_color(metadata);
pl_map_dovi_metadata(dovi, metadata);
frame->repr.dovi = dovi;
frame->repr.sys = PL_COLOR_SYSTEM_DOLBYVISION;
frame->color.primaries = PL_COLOR_PRIM_BT_2020;
frame->color.transfer = PL_COLOR_TRC_PQ;
frame->color.hdr.min_luma =
pl_hdr_rescale(PL_HDR_PQ, PL_HDR_NITS, color->source_min_pq / 4095.0f);
frame->color.hdr.max_luma =
pl_hdr_rescale(PL_HDR_PQ, PL_HDR_NITS, color->source_max_pq / 4095.0f);
}
#endif
// Set the frame DOVI metadata
mp_map_dovi_metadata_to_pl(mpi, frame);
#ifdef PL_HAVE_LAV_FILM_GRAIN
if (mpi->film_grain)