Compare commits

..

4 commits

Author SHA1 Message Date
9c0e598ce2 use the old logic for sizing 2023-05-17 09:53:50 -07:00
5181d41f91 Merge branch 'alt' into work 2023-05-17 09:16:34 -07:00
552a81499c hack 2023-05-17 09:16:30 -07:00
bb4b9f89d5 alternate size stuff 2023-05-16 12:14:49 -07:00
2 changed files with 49 additions and 5 deletions

View file

@ -11,11 +11,11 @@ for INFILE in "$@"
do
echo "$INFILE"
COMMON="$OPTS --exposure=-2.5 --peak=141 --fps=60000/1001"
COMMON="$OPTS --hdr --exposure=-2.5 --peak=141 --fps=60000/1001"
SPEED_SMALL="veryslow"
SPEED_LARGE="medium"
SMALL="$COMMON --size=4m --preset=$SPEED_SMALL --quality=0.75"
SMALL="$COMMON --size=4m --preset=$SPEED_SMALL"
LARGE="$COMMON --size=25m --preset=$SPEED_LARGE"
pack-vid $SMALL "$INFILE" "${INFILE%.mp4}-small.mp4"

View file

@ -26,6 +26,7 @@ $options = [
'fps' => '60000/1001',
'size' => $maxBytes,
'quality' => 1.0,
'hdr' => false,
];
while ( count( $args ) > 0 && substr( $args[0], 0, 2 ) == '--' ) {
@ -51,7 +52,8 @@ if ( count ( $args ) < 2 ) {
" --preset=key set h.264 encoding preset\n" .
" --fps=n frame rate limit\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"
" --quality=n fraction of base bitrate to break on (deafult 0.75)\n" .
" --hdr force HDR input processing on\n"
);
}
[ $src, $dest ] = $args;
@ -97,7 +99,7 @@ function ffprobe( $path ) {
}
function evenize( $n ) {
$n = ceil( $n );
$n = round( $n );
if ( $n & 1 ) {
$n++;
}
@ -146,7 +148,7 @@ function convert( $src, $dest, $options ) {
$duration = floatval( $track->duration );
$width = $track->width;
$height = $track->height;
$hdr = $track->color_primaries === 'bt2020';
$hdr = $track->color_primaries === 'bt2020' || $options['hdr'];
$keyframeInt = ceil( $duration * 60 );
$bitrate = floor( $maxBits / $duration );
@ -190,6 +192,48 @@ function convert( $src, $dest, $options ) {
}
$aspect = $width / $height;
$pixels = $width * $height;
// canonical base rate is 1 megabit at 480p
$bitrate = min( $bitrate, 4 * $base );
/*
$minWidth = 640;
$minHeight = 360;
$baseWidth = 854;
$baseHeight = 480;
$pixelsPerBit = ( $baseWidth * $baseHeight ) / $base;
$maxWidth = 1920;
$maxHeight = 1080;
$maxrate = $base * ( $maxWidth * $maxHeight ) / ( $baseWidth * $baseHeight );
$pixels = $bitrate * $pixelsPerBit;
$frameHeight = evenize( sqrt( $pixels / $aspect ) );
$frameWidth = evenize( $frameHeight * $aspect );
if ( $aspect > 16 / 9 ) {
if ( $frameWidth < $minWidth ) {
$frameWidth = $minWidth;
$frameHeight = evenize( $frameWidth / $aspect );
} elseif ( $frameWidth > $maxWidth ) {
$frameWidth = $maxWidth;
$frameHeight = evenize( $frameWidth / $aspect );
$bitrate = min( $bitrate, $maxrate );
}
} else {
if ( $frameHeight < $minHeight ) {
$frameHeight = $minHeight;
$frameWidth = evenize( $frameHeight * $aspect );
} elseif ( $frameWidth > $maxWidth ) {
$frameHeight = $maxHeight;
$frameWidth = evenize( $frameHeight * $aspect );
$bitrate = min( $bitrate, $maxrate );
}
}
*/
$wide = $aspect > ( $frameWidth / $frameHeight );
$crop = boolval( $options['crop'] );
$letterbox = boolval( $options['letterbox'] );