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