diff --git a/pack-vid b/pack-vid index ce71466..96ff723 100755 --- a/pack-vid +++ b/pack-vid @@ -122,12 +122,25 @@ function convert( $src, $dest, $options ) { $frameHeight = 1080; } - if ( $options['letterbox'] ) { - $scaleWidth = $frameWidth; - $scaleHeight = evenize( $height * $frameWidth / $width ); + $aspect = $width / $height; + $wide = $aspect > ( $frameWidth / $frameHeight ); + $pad = boolval( $options['letterbox'] ); + if ( $pad ) { + if ( $wide ) { + $scaleWidth = $frameWidth; + $scaleHeight = evenize( $frameWidth / $aspect ); + } else { + $scaleHeight = $frameHeight; + $scaleWidth = evenize( $frameHeight * $aspect ); + } } else { - $scaleHeight = $frameHeight; - $scaleWidth = evenize( $width * $frameHeight / $height ); + 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 );