Last active
February 13, 2023 17:57
-
-
Save quietvoid/a3ef15d8556c3f346aca5c4e304f0b04 to your computer and use it in GitHub Desktop.
libplacebo Dolby Vision dynamic brightness support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 1aecda5d8ca32ec350fce095b7a8a773300ce45a Mon Sep 17 00:00:00 2001 | |
From: quietvoid <[email protected]> | |
Date: Mon, 13 Feb 2023 09:36:57 -0500 | |
Subject: [PATCH] utils/libav: derive scene brightness info from DOVI RPU | |
Using `libdovi` to parse the RPU, as `AVDOVIMetadata` | |
does not yet parse the extension metadata blocks. | |
--- | |
src/include/libplacebo/utils/libav_internal.h | 26 +++++++++++++++++++ | |
src/meson.build | 6 +++++ | |
2 files changed, 32 insertions(+) | |
diff --git a/src/include/libplacebo/utils/libav_internal.h b/src/include/libplacebo/utils/libav_internal.h | |
index f8ded127..c3f29cab 100644 | |
--- a/src/include/libplacebo/utils/libav_internal.h | |
+++ b/src/include/libplacebo/utils/libav_internal.h | |
@@ -41,6 +41,10 @@ | |
# include <libplacebo/vulkan.h> | |
#endif | |
+#ifdef PL_HAVE_DOVI | |
+#include <libdovi/rpu_parser.h> | |
+#endif | |
+ | |
static inline enum pl_color_system pl_system_from_av(enum AVColorSpace spc) | |
{ | |
switch (spc) { | |
@@ -1093,6 +1097,28 @@ static inline bool pl_map_avframe_internal(pl_gpu gpu, struct pl_frame *out, | |
pl_hdr_rescale(PL_HDR_PQ, PL_HDR_NITS, color->source_max_pq / 4095.0f); | |
} | |
} | |
+ | |
+#ifdef PL_HAVE_DOVI | |
+ if ((sd = av_frame_get_side_data(frame, AV_FRAME_DATA_DOVI_RPU_BUFFER))) { | |
+ DoviRpuOpaque *rpu_in = dovi_parse_unspec62_nalu(sd->data, sd->size); | |
+ const DoviRpuDataHeader *header = dovi_rpu_get_header(rpu_in); | |
+ if (header && header->vdr_dm_metadata_present_flag) { | |
+ const DoviVdrDmData *vdr_dm_data = dovi_rpu_get_vdr_dm_data(rpu_in); | |
+ if (vdr_dm_data->dm_data.level1) { | |
+ const DoviExtMetadataBlockLevel1 *l1 = vdr_dm_data->dm_data.level1; | |
+ const float max_luma = pl_hdr_rescale(PL_HDR_PQ, PL_HDR_NITS, l1->max_pq / 4095.0f); | |
+ | |
+ out->color.hdr.scene_max[0] = out->color.hdr.scene_max[1] = out->color.hdr.scene_max[2] = max_luma; | |
+ out->color.hdr.scene_avg = pl_hdr_rescale(PL_HDR_PQ, PL_HDR_NITS, l1->avg_pq / 4095.0f); | |
+ } | |
+ | |
+ } | |
+ | |
+ if (header) | |
+ dovi_rpu_free_header(header); | |
+ dovi_rpu_free(rpu_in); | |
+ } | |
+#endif | |
} | |
#endif | |
diff --git a/src/meson.build b/src/meson.build | |
index 0c31ae0f..6b54d8fb 100644 | |
--- a/src/meson.build | |
+++ b/src/meson.build | |
@@ -126,6 +126,12 @@ if lcms.found() | |
tests += 'icc.c' | |
endif | |
+dovi = dependency('dovi', required: false) | |
+components.set('dovi', dovi.found()) | |
+if dovi.found() | |
+ build_deps += dovi | |
+endif | |
+ | |
# Check to see if libplacebo built this way is sane | |
if not (components.get('vulkan') or components.get('opengl') or components.get('d3d11')) | |
warning('Building without any graphics API. libplacebo built this way still ' + | |
-- | |
2.39.1 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Maintainer: Gustavo Alvarez <[email protected]> | |
# Contributor: Levente Polyak <anthraxx[at]archlinux[dot]org> | |
pkgname=libplacebo-custom | |
pkgver=v5.229.1.179.g1f1d708e2 | |
pkgrel=1 | |
pkgdesc='Reusable library for GPU-accelerated video/image rendering primitives. (GIT version)' | |
url='https://code.videolan.org/videolan/libplacebo' | |
arch=('x86_64') | |
license=('LGPL2.1') | |
depends=('libvulkan.so' | |
'liblcms2.so' | |
'libshaderc_shared.so' | |
'glslang' | |
'libavcodec.so' | |
'libavutil.so' | |
'libavformat.so' | |
) | |
makedepends=('git' | |
'meson' | |
'ninja' | |
'vulkan-headers' | |
'vulkan-icd-loader' | |
'python-mako' | |
'python-jinja' | |
'python-markupsafe' | |
'ffmpeg' | |
'lcms2' | |
'shaderc' | |
'dav1d' | |
) | |
provides=('libplacebo' | |
'libplacebo.so' | |
) | |
conflicts=('libplacebo') | |
source=('git+https://code.videolan.org/videolan/libplacebo.git') | |
options=(!emptydirs debug !strip) | |
#add patch numbers from github here | |
_gitlab_patches=() | |
for patch in ${_gitlab_patches[@]} | |
do | |
source+=("https://code.videolan.org/videolan/libplacebo/-/merge_requests/${patch}.patch") | |
done | |
#other patches | |
source+=('https://gist.githubusercontent.com/quietvoid/a3ef15d8556c3f346aca5c4e304f0b04/raw/0001-utils-libav-derive-scene-brightness-info-from-DOVI-R.patch') | |
#all sources should have sha256sums skipped | |
for i in ${source[@]} | |
do | |
sha256sums+=('SKIP') | |
done | |
pkgver() { | |
cd libplacebo | |
echo "$(git describe --long --tags | tr - .)" | |
} | |
prepare() { | |
cd libplacebo | |
for i in "${srcdir}"/*.patch | |
do | |
[[ -e "$i" ]] || continue | |
echo "Applying $i" | |
git apply "$i" | |
done | |
git submodule update --init | |
cd .. | |
mkdir -p build | |
} | |
build() { | |
cd build | |
arch-meson --buildtype=debugoptimized ../libplacebo \ | |
-D vulkan=enabled \ | |
-D glslang=enabled \ | |
-D shaderc=enabled \ | |
-D lcms=enabled \ | |
-D d3d11=disabled \ | |
-D tests=true \ | |
-D demos=true | |
ninja | |
} | |
check() { | |
ninja -C build # test | |
} | |
package() { | |
DESTDIR="$pkgdir" ninja -C build install | |
install -Dm644 libplacebo/README.md "${pkgdir}/usr/share/doc/${pkgname}/README.md" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment