Compare commits

...

2 commits

Author SHA1 Message Date
Brooke Vibber 869251fb65 crop option 2023-10-26 11:28:51 -07:00
Brooke Vibber 5ba048b8c8 fixes for options 2023-10-26 11:10:59 -07:00
2 changed files with 38 additions and 11 deletions

View file

@ -12,17 +12,17 @@ do
else
echo "FILE: $INFILE"
#COMMON="$OPTS"
#COMMON="$OPTS --exposure=-2.5 --peak=141"
#COMMON="$OPTS --exposure=-1 --peak=500"
COMMON="$OPTS --peak=1000"
#COMMON=""
#COMMON="--exposure=-2.5 --peak=141"
#COMMON="--exposure=-1 --peak=500"
COMMON="--peak=1000"
SPEED_SMALL="veryslow"
SPEED_LARGE="slow"
SMALL="$COMMON --size=4m --quality=0.75 --preset=$SPEED_SMALL"
LARGE="$COMMON --size=25m --preset=$SPEED_LARGE"
pack-vid $SMALL "$INFILE" "${INFILE%.mp4}-small.mp4"
pack-vid $LARGE "$INFILE" "${INFILE%.mp4}-large.mp4"
pack-vid $SMALL $OPTS "$INFILE" "${INFILE%.mp4}-small.mp4"
pack-vid $LARGE $OPTS "$INFILE" "${INFILE%.mp4}-large.mp4"
fi
done

View file

@ -31,6 +31,9 @@ $options = [
'width' => false,
'height' => false,
'keyframe-int' => 0,
'vibrance' => 0,
'crop-width' => false,
'crop-height' => false,
];
while ( count( $args ) > 0 && substr( $args[0], 0, 2 ) == '--' ) {
@ -156,6 +159,25 @@ function convert( $src, $dest, $options ) {
$duration = floatval( $probe->format->duration );
$width = $track->width;
$height = $track->height;
$cropLeft = 0;
$cropTop = 0;
if ( $options['crop-width'] ) {
$cropWidth = intval( $options['crop-width'] );
$cropLeft = intval( ( $width - $cropWidth ) / 2 );
$width = $cropWidth;
}
if ( $options['crop-height'] ) {
$cropHeight = intval( $options['crop-height'] );
$cropTop = intval( ( $height - $cropHeight ) / 2 );
$height = $cropHeight;
}
if ( $options['crop-top'] ) {
$cropTop = intval( $options['crop-top'] );
}
if ( $options['crop-left'] ) {
$cropLeft = intval( $options['crop-left'] );
}
// @fixme some files are missing this? trims from qt?
//$hdr = $track->color_primaries === 'bt2020' || $options['hdr'];
// pix_fmt: "yuv420p10le"
@ -300,8 +322,13 @@ function convert( $src, $dest, $options ) {
$peakNits = floatval( $options['peak'] );
$sdrNits = 80;
$peak = $peakNits / $sdrNits;
$vibrance = floatval( $options['vibrance'] );
$filters = [ "scale=w=$scaleWidth:h=$scaleHeight" ];
$filters = [];
if ( $options['crop-width'] || $options['crop-height'] ) {
$filters[] = "crop=w=$width:x=$cropLeft:h=$height:y=$cropTop";
}
$filters[] = "scale=w=$scaleWidth:h=$scaleHeight";
if ( $hdr ) {
$filters[] = "zscale=t=linear";
if ( $exposure ) {
@ -313,8 +340,10 @@ function convert( $src, $dest, $options ) {
} else {
$dither = "";
}
$filters[] = "zscale=t=bt709:p=bt709:m=bt709:r=full$dither";
$filters[] = "vibrance=0.2";
$filters[] = "zscale=tin=linear:t=709:p=709:m=709:r=full$dither";
if ( $vibrance ) {
$filters[] = "vibrance=$vibrance";
}
}
$filters[] = "format=yuv420p";
if ( $crop ) {
@ -337,7 +366,6 @@ function convert( $src, $dest, $options ) {
'-i', $src,
'-f', 'mp4',
'-fpsmax', $fps,
//'-r', $fps,
'-vf', $vf,
'-c:v', 'libx264',
'-b:v', $bitrate,
@ -354,7 +382,6 @@ function convert( $src, $dest, $options ) {
'-i', $src,
'-vf', $vf,
'-fpsmax', $fps,
//'-r', $fps,
'-c:v', 'libx264',
'-b:v', $bitrate,
'-preset', $preset,