-
-
Save khaosx/4b00d4b245d70125516b4f7ddf821f43 to your computer and use it in GitHub Desktop.
Script to set HDR10 properties in a transcoded video file.
This file contains 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
# hdr-copy-metadata.ps1 | |
# | |
# Version: 1.0 | |
# Reads HDR metadata from source file and applies it to a transcoded output file. | |
param( | |
[Parameter(Mandatory)] | |
[string]$fsource, | |
[Parameter(Mandatory)] | |
[string]$fdest | |
) | |
# Pre-defined RGB & WP values for BT.2020 | |
$BT2020_xW = 0.3127 | |
$BT2020_yW = 0.3290 | |
$BT2020_xR = 0.708 | |
$BT2020_yR = 0.292 | |
$BT2020_xG = 0.17 | |
$BT2020_yG = 0.797 | |
$BT2020_xB = 0.131 | |
$BT2020_yB = 0.046 | |
# Pre-defined RGB & WP values for P3-D65 | |
$P3D65_xW = 0.3127 | |
$P3D65_yW = 0.3290 | |
$P3D65_xR = 0.680 | |
$P3D65_yR = 0.320 | |
$P3D65_xG = 0.265 | |
$P3D65_yG = 0.690 | |
$P3D65_xB = 0.150 | |
$P3D65_yB = 0.060 | |
# Extract values from source video | |
$colourSpace = mediainfo --Inform="Video;%MasteringDisplay_ColorPrimaries%" "$fSource" | |
$luminance = mediainfo --Inform="Video;%MasteringDisplay_Luminance%" "$fSource" | |
$maxCLL = mediainfo --Inform="Video;%MaxCLL%" "$fSource" | |
$maxFALL = mediainfo --Inform="Video;%MaxFALL%" "$fSource" | |
if ( $maxCLL -eq "" ) { | |
$maxCLL = "0 cd/m2" | |
} | |
if ( $maxFALL -eq "" ) { | |
$maxFALL = "0 cd/m2" | |
} | |
# Print results from MediaInfo | |
write-host "Colour Space: $colourSpace" | |
write-host "Luminance: $luminance" | |
write-host "MaxCLL: $maxCLL" | |
write-host "MaxFALL: $maxFALL" | |
# Extract max and min lumanances | |
$minLuminance = $luminance.split( )[1] | |
$maxLuminance = $luminance.split( )[4] | |
# Extract MaxCLL | |
$maxCLL_noUnit = $maxCLL.split( )[0] | |
# Extract MaxFALL | |
$maxFALL_noUnit = $maxFALL.split( )[0] | |
# Print extracted values | |
write-host "Minimum luminance: $minLuminance" | |
write-host "Maximum luminance: $maxLuminance" | |
write-host "MaxCLL: $maxCLL_noUnit" | |
write-host "MaxFALL: $maxFALL_noUnit" | |
# Edit second input based on values extracted from MediaInfo | |
switch ($colourSpace) { | |
"BT.2020" { | |
mkvpropedit "$fDest" --edit track:v1 --set chromaticity-coordinates-red-x="$BT2020_xR" ` | |
--set chromaticity-coordinates-red-y=$BT2020_yR ` | |
--set chromaticity-coordinates-green-x=$BT2020_xG ` | |
--set chromaticity-coordinates-green-y=$BT2020_yG ` | |
--set chromaticity-coordinates-blue-x=$BT2020_xB ` | |
--set chromaticity-coordinates-blue-y=$BT2020_yB ` | |
--set white-coordinates-x=$BT2020_xW ` | |
--set white-coordinates-y=$BT2020_yW ` | |
--set max-luminance=$maxLuminance ` | |
--set min-luminance=$minLuminance ` | |
--set max-content-light=$maxCLL_noUnit ` | |
--set max-frame-light=$maxFALL_noUnit | |
} | |
"Display P3" { | |
mkvpropedit "$fDest" --edit track:v1 --set chromaticity-coordinates-red-x="$P3D65_xR" ` | |
--set chromaticity-coordinates-red-y=$P3D65_yR ` | |
--set chromaticity-coordinates-green-x=$P3D65_xG ` | |
--set chromaticity-coordinates-green-y=$P3D65_yG ` | |
--set chromaticity-coordinates-blue-x=$P3D65_xB ` | |
--set chromaticity-coordinates-blue-y=$P3D65_yB ` | |
--set white-coordinates-x=$P3D65_xW ` | |
--set white-coordinates-y=$P3D65_yW ` | |
--set max-luminance=$maxLuminance ` | |
--set min-luminance=$minLuminance ` | |
--set max-content-light=$maxCLL_noUnit ` | |
--set max-frame-light=$maxFALL_noUnit | |
} | |
default { write-warning "Unknown Colourspace" } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment