Make quality level adjustable

this bumps the bitrate baseline up and down
set the default to 0.75 vs the original 1MB=480p baseline
to allow more wiggle room
This commit is contained in:
Brooke Vibber 2023-04-09 14:25:23 -07:00
parent 3d05a27527
commit b4832db888

View file

@ -22,6 +22,7 @@ $options = [
'peak' => '10000',
'fps' => '60',
'size' => $maxBytes,
'quality' => 0.75,
];
while ( count( $args ) > 0 && substr( $args[0], 0, 2 ) == '--' ) {
@ -44,7 +45,8 @@ if ( count ( $args ) < 2 ) {
" --exposure=n adjust exposure\n" .
" --peak=n set HDR peak nits\n" .
" --fps=n frame rate limit\n" .
" --size=n target file size in bytes (default 3.5M)\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"
);
}
[ $src, $dest ] = $args;
@ -148,13 +150,14 @@ function convert( $src, $dest, $options ) {
}
$mbits = 1000 * 1000;
if ( $bitrate < 1 * $mbits || $height < 480 ) {
$base = intval( $mbits * $options['quality'] );
if ( $bitrate < 1 * $base || $height < 480 ) {
$frameWidth = 640;
$frameHeight = 360;
} elseif ( $bitrate < 2 * $mbits || $height < 720) {
} elseif ( $bitrate < 2 * $base || $height < 720) {
$frameWidth = 854;
$frameHeight = 480;
} elseif ( $bitrate < 4 * $mbits || $height < 1080) {
} elseif ( $bitrate < 4 * $base || $height < 1080) {
$frameWidth = 1280;
$frameHeight = 720;
} else {