sizes, keyframes, default exposure

This commit is contained in:
Brooke Vibber 2023-09-09 18:14:45 -07:00
parent 742238f642
commit 64d494825c
2 changed files with 34 additions and 20 deletions

View file

@ -14,7 +14,8 @@ do
#COMMON="$OPTS"
#COMMON="$OPTS --exposure=-2.5 --peak=141"
COMMON="$OPTS --exposure=-1 --peak=500"
#COMMON="$OPTS --exposure=-1 --peak=500"
COMMON="$OPTS --peak=1000"
SPEED_SMALL="veryslow"
SPEED_LARGE="slow"

View file

@ -30,6 +30,7 @@ $options = [
'dither' => false,
'width' => false,
'height' => false,
'keyframe-int' => 0,
];
while ( count( $args ) > 0 && substr( $args[0], 0, 2 ) == '--' ) {
@ -47,19 +48,20 @@ if ( count ( $args ) < 2 ) {
die(
"Usage: $self [options...] <srcfile.mp4> <destfile.mp4>\n" .
"Options:\n" .
" --crop crop to 16:9\n" .
" --letterbox pad to 16:9\n" .
" --no-audio strip audio\n" .
" --exposure=n adjust exposure\n" .
" --peak=n set HDR peak nits\n" .
" --preset=key set h.264 encoding preset\n" .
" --fps=n frame rate limit\n" .
" --size=n target file size in bytes (default 3.5M)\n" .
" --quality=n fraction of base bitrate to break on (deafult 0.75)\n" .
" --hdr force HDR input processing on\n" .
" --dither enable dithering in 8-bit downconversion\n" .
" --width override frame width in pixels\n" .
" --height override frame height in pixels\n"
" --crop crop to 16:9\n" .
" --letterbox pad to 16:9\n" .
" --no-audio strip audio\n" .
" --exposure=n adjust exposure\n" .
" --peak=n set HDR peak nits\n" .
" --preset=key set h.264 encoding preset\n" .
" --fps=n frame rate limit\n" .
" --size=n target file size in bytes (default 3.5M)\n" .
" --quality=n fraction of base bitrate to break on (deafult 0.75)\n" .
" --hdr force HDR input processing on\n" .
" --dither enable dithering in 8-bit downconversion\n" .
" --width=n override frame width in pixels\n" .
" --height=n override frame height in pixels\n" .
" --keyframe-int=n set keyframe interval (default 0)\n"
);
}
[ $src, $dest ] = $args;
@ -151,14 +153,18 @@ function convert( $src, $dest, $options ) {
}
$track = $videoTracks[0];
$duration = floatval( $track->duration );
$duration = floatval( $probe->format->duration );
$width = $track->width;
$height = $track->height;
// @fixme some files are missing this? trims from qt?
//$hdr = $track->color_primaries === 'bt2020' || $options['hdr'];
// pix_fmt: "yuv420p10le"
$hdr = substr( $track->pix_fmt, -5 ) === 'p10le' || $options['hdr'];
$keyframeInt = ceil( $duration * 60 );
if ( $options['keyframe-int'] ) {
$keyframeInt = intval( $options['keyframe-int'] );
} else {
$keyframeInt = intval( ceil( $duration * 60 ) );
}
$bitrate = floor( $maxBits / $duration );
@ -175,7 +181,6 @@ function convert( $src, $dest, $options ) {
}
$bitrate = max( $bitrate, 16000 );
$mbits = 1000 * 1000;
$base = intval( $mbits * floatval( $options['quality'] ) );
if ( $bitrate < 0.125 * $base || $height < 144 ) {
@ -206,17 +211,25 @@ function convert( $src, $dest, $options ) {
$frameWidth = 1280;
$frameHeight = 720;
$bitrate = min( $bitrate, $base * 4 );
} else {
} elseif ( $bitrate < 8 * $base || $height < 1440) {
$frameWidth = 1920;
$frameHeight = 1080;
$bitrate = min( $bitrate, $base * 8 );
} elseif ( $bitrate < 16 * $base || $height < 2160) {
$frameWidth = 2560;
$frameHeight = 1440;
$bitrate = min( $bitrate, $base * 16 );
} else {
$frameWidth = 3840;
$frameHeight = 2160;
$bitrate = min( $bitrate, $base * 32 );
}
$aspect = $width / $height;
$pixels = $width * $height;
// canonical base rate is 1 megabit at 480p
$bitrate = min( $bitrate, 4 * $base );
// canonical min rate is 0.125 megabit at 144p
$bitrate = max( $bitrate, 0.125 * $base );
/*
$minWidth = 640;