handle narrower than 16:9 input

This commit is contained in:
Brooke Vibber 2023-02-12 14:04:46 -08:00
parent bed9ce149b
commit bb2af76233

View file

@ -122,12 +122,25 @@ function convert( $src, $dest, $options ) {
$frameHeight = 1080; $frameHeight = 1080;
} }
if ( $options['letterbox'] ) { $aspect = $width / $height;
$scaleWidth = $frameWidth; $wide = $aspect > ( $frameWidth / $frameHeight );
$scaleHeight = evenize( $height * $frameWidth / $width ); $pad = boolval( $options['letterbox'] );
if ( $pad ) {
if ( $wide ) {
$scaleWidth = $frameWidth;
$scaleHeight = evenize( $frameWidth / $aspect );
} else {
$scaleHeight = $frameHeight;
$scaleWidth = evenize( $frameHeight * $aspect );
}
} else { } else {
$scaleHeight = $frameHeight; if ( $wide ) {
$scaleWidth = evenize( $width * $frameHeight / $height ); $scaleHeight = $frameHeight;
$scaleWidth = evenize( $frameHeight * $aspect );
} else {
$scaleWidth = $frameWidth;
$scaleHeight = evenize( $frameWidth / $aspect );
}
} }
$peakNits = 2000; $peakNits = 2000;
@ -142,10 +155,11 @@ function convert( $src, $dest, $options ) {
} }
$filters[] = "format=yuv420p"; $filters[] = "format=yuv420p";
if ( $options['letterbox'] ) { if ( $options['letterbox'] ) {
$offset = round( ( $frameHeight - $scaleHeight) / 2 ); $offsetX = round( ( $frameWidth - $scaleWidth) / 2 );
$filters[] = "pad=h=$frameHeight:y=$offset"; $offsetY = round( ( $frameHeight - $scaleHeight) / 2 );
$filters[] = "pad=w=$frameWidth:h=$frameHeight:x=$offsetX:y=$offsetY";
} else { } else {
$filters[] = "crop=w=$frameWidth"; $filters[] = "crop=w=$frameWidth:h=$frameHeight";
} }
$vf = implode( ',', $filters ); $vf = implode( ',', $filters );