Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparing SDR and HDR Videos #74

Closed
jonfryd opened this issue Jul 2, 2024 · 1 comment
Closed

Comparing SDR and HDR Videos #74

jonfryd opened this issue Jul 2, 2024 · 1 comment
Labels
contribution Useful contributions from others

Comments

@jonfryd
Copy link
Member

jonfryd commented Jul 2, 2024

Here is a small bash script that can be used to compare SDR and HDR videos on an sRGB display:

#!/bin/bash

usage() {
    echo "Usage: $0 [OPTIONS]...  <SDR FILE> <HDR FILE>"
    echo ""
    echo "Note: SDR video should be in Rec. 709 and HDR video should be in e.g. Rec. 2020 + SMPTE ST 2084 (HDR10)."
    exit 1
}

if [ "$#" -lt 2 ]; then
    usage
fi

# If HDR_PEAK_NITS is not set in the environment, use 850 peak nits as the default
HDR_PEAK_NITS=${HDR_PEAK_NITS:-850}

# Calculate SDR tone-mapping adjustment via awk; for HDR content mastered at 850 peak nits, the value becomes ~0.118
SDR_TM_ADJUSTMENT=$(LC_ALL=C awk -v n="$HDR_PEAK_NITS" 'BEGIN {print (100 / n)}')

# Use Rec. 709 + sRGB for display color primaries / transfer characteristics by default
DISPLAY_PRIMARIES=${DISPLAY_PRIMARIES:-bt709}
DISPLAY_TC=${DISPLAY_TC:-iec61966-2-1}

video-compare --left-decoder :colorspace=bt709,color_primaries=bt709,color_trc=bt709 \
  -l format=rgb48,zscale=t=linear,tonemap=clip:param=$SDR_TM_ADJUSTMENT,zscale=p=$DISPLAY_PRIMARIES:t=$DISPLAY_TC \
  -r format=rgb48,zscale=p=$DISPLAY_PRIMARIES:t=$DISPLAY_TC:npl=$HDR_PEAK_NITS \
  "$@"

This script ensures that HDR content mapped correctly for an SDR display and adjusts the SDR video accordingly to simulate the relative difference in appearance between the two videos on an HDR display. This makes the comparison between the SDR and HDR videos more accurate.

Please note:

  • Requires the zscale libavfilter and awk to compute the SDR tone-mapping adjustment parameter
  • The SDR video is assumed to be in Rec. 709 (if metadata is missing)
  • The HDR video must be in a format such as Rec. 2020 + SMPTE ST 2084 (PQ10/HDR10)

In the future, I am going to explore how we can have proper HDR support in video-compare.

You are welcome to suggest improvements to the approach above, and/or adapt this script into a Windows Batch file and share the outcome here.

@jonfryd jonfryd added the contribution Useful contributions from others label Jul 2, 2024
@jonfryd
Copy link
Member Author

jonfryd commented Aug 15, 2024

I've introduced support for the above in video-compare on the master branch today, and a couple of command-line examples have been added to the project's README.md.

Besides the HDR display relative tone-matching approach described above, video-compare now supports color space conversion to sRGB and basic tone mapping for comparing videos at the display's full light level. For this to work, zscale and valid color space metadata (which can be set via video filter options, e.g. setparams=colorspace=bt709:color_primaries=bt709:color_trc=bt709) are required. The peak content luminance in nits must be provided for HDR videos on the command line; otherwise, SDR content at 100 nits is assumed. Tested with HDR10, PQ10, and HLG.

Two HDR videos can be compared if desired, and I’ve added the option to boost the luminance of both videos via tone mapping. The latter is useful when comparing videos with vastly different dynamic ranges, and some clipping can be tolerated.

This issue will be closed when the next release is made.

P.S. Can't wait for SDL3 to be released... HDR display support here we come!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution Useful contributions from others
Projects
None yet
Development

No branches or pull requests

1 participant