peak to 10k and allow setting exposure and peak

This commit is contained in:
Brooke Vibber 2023-02-19 15:36:41 -08:00
parent bb2af76233
commit 930518f046

View file

@ -14,19 +14,29 @@ $self = array_shift( $args );
$options = [
'letterbox' => false,
'audio' => false,
'exposure' => '0',
'peak' => '10000'
];
while ( count( $args ) > 0 && substr( $args[0], 0, 2 ) == '--' ) {
$option = substr( array_shift( $args ), 2 );
$parts = explode( '=', $option, 2 );
if ( count( $parts ) == 2 ) {
[ $key, $val ] = $parts;
$options[$key] = $val;
} else {
$options[$option] = true;
}
}
if ( count ( $args ) < 2 ) {
die(
"Usage: $self [options...] <srcfile.mp4> <destfile.mp4>\n" .
"Options:\n" .
" --letterbox pad instead of cropping\n" .
" --audio include audio\n"
" --audio include audio\n" .
" --exposure=n adjust exposure\n" .
" --peak=n set HDR peak nits\n"
);
}
[ $src, $dest ] = $args;
@ -143,13 +153,17 @@ function convert( $src, $dest, $options ) {
}
}
$peakNits = 2000;
$exposure = floatval( $options['exposure'] );
$peakNits = floatval( $options['peakNits'] );
$sdrNits = 80;
$peak = $peakNits / $sdrNits;
$filters = [ "scale=w=$scaleWidth:h=$scaleHeight" ];
if ( $hdr ) {
$filters[] = "zscale=t=linear:p=bt709";
if ( $exposure ) {
$filters[] = "exposure=$exposure";
}
$filters[] = "tonemap=hable:peak=$peak";
$filters[] = "zscale=t=bt709:m=bt709:r=full";
}