This commit is contained in:
Brooke Vibber 2023-04-24 21:24:51 -07:00
commit 19223d8288
2 changed files with 8 additions and 10 deletions

View file

@ -17,6 +17,7 @@ $maxBytes = $maxBytes * 15 / 16; // leave some headroom
$options = [
'crop' => false,
'letterbox' => false,
'no-audio' => false,
'exposure' => '0', // stops
'peak' => '1000', // '10000' is max
@ -41,7 +42,8 @@ if ( count ( $args ) < 2 ) {
die(
"Usage: $self [options...] <srcfile.mp4> <destfile.mp4>\n" .
"Options:\n" .
" --crop crop instead of padding\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" .
@ -177,6 +179,7 @@ function convert( $src, $dest, $options ) {
$aspect = $width / $height;
$wide = $aspect > ( $frameWidth / $frameHeight );
$crop = boolval( $options['crop'] );
$letterbox = boolval( $options['letterbox'] );
if ( $crop ) {
if ( $wide ) {
$scaleHeight = $frameHeight;
@ -213,7 +216,7 @@ function convert( $src, $dest, $options ) {
$filters[] = "format=yuv420p";
if ( $crop ) {
$filters[] = "crop=w=$frameWidth:h=$frameHeight";
} else {
} elseif ( $letterbox ) {
$offsetX = round( ( $frameWidth - $scaleWidth) / 2 );
$offsetY = round( ( $frameHeight - $scaleHeight) / 2 );
$filters[] = "pad=w=$frameWidth:h=$frameHeight:x=$offsetX:y=$offsetY";