From 7ccc3bd2825971c7f31940fcb409aa0410afa1c4 Mon Sep 17 00:00:00 2001 From: Brooke Vibber Date: Sat, 16 Mar 2024 12:35:04 -0700 Subject: [PATCH] wip --- prep-set | 15 ++----- prep-vid | 120 +++++++++++++++++++++++++++---------------------------- 2 files changed, 61 insertions(+), 74 deletions(-) diff --git a/prep-set b/prep-set index 3522348..3265e0d 100755 --- a/prep-set +++ b/prep-set @@ -13,19 +13,10 @@ do else echo "FILE: $INFILE" - MAPPED="prep-set-${INFILE%.mp4}.2160p.sdr.h264.mp4" - prep-vid $OPTS "$INFILE" "$MAPPED" - - prep-vid $OPTS "$MAPPED" "${INFILE%.mp4}.360p.sdr.thumb.jpg" - prep-vid $OPTS "$INFILE" "${INFILE%.mp4}.360p.hdr.thumb.avif" - - prep-vid $OPTS "$MAPPED" "${INFILE%.mp4}.720p.sdr.h264.mp4" - prep-vid $OPTS "$INFILE" "${INFILE%.mp4}.720p.hdr.hevc.mp4" - - prep-vid $OPTS "$MAPPED" "${INFILE%.mp4}.1080p.sdr.av1.webm" + prep-vid $OPTS "$INFILE" "${INFILE%.mp4}.480p.sdr.thumb.jpg" + prep-vid $OPTS "$INFILE" "${INFILE%.mp4}.1080p.sdr.h264.mp4" + prep-vid $OPTS "$INFILE" "${INFILE%.mp4}.1080p.hdr.vp9.webm" prep-vid $OPTS "$INFILE" "${INFILE%.mp4}.1080p.hdr.av1.webm" - - prep-vid $OPTS "$MAPPED" "${INFILE%.mp4}.2160p.sdr.av1.webm" prep-vid $OPTS "$INFILE" "${INFILE%.mp4}.2160p.hdr.av1.webm" fi done diff --git a/prep-vid b/prep-vid index 2c127bf..aba5038 100755 --- a/prep-vid +++ b/prep-vid @@ -14,20 +14,31 @@ $args = $_SERVER['argv']; $self = array_shift( $args ); $profiles = [ - '360p.sdr.thumb.jpg' => [ - 'width' => 640, - 'height' => 360, + '480p.sdr.thumb.jpg' => [ + 'width' => 854, + 'height' => 480, 'codec' => 'mjpeg', - 'bitrate' => '4000k', 'still' => true, ], - '360p.hdr.thumb.avif' => [ - 'width' => 640, - 'height' => 360, - 'codec' => 'libsvtav1', - 'bitrate' => '2000k', + '1080p.sdr.h264.mp4' => [ + 'width' => 1920, + 'height' => 1080, + 'codec' => 'libx264', + 'bitrate' => '5000k', + ], + '1080p.hdr.vp9.webm' => [ + 'width' => 1920, + 'height' => 1080, + 'codec' => 'libvpx-vp9', + 'bitrate' => '5000k', + 'hdr' => true, + ], + '1080p.hdr.av1.webm' => [ + 'width' => 1920, + 'height' => 1080, + 'codec' => 'libsvtav1', + 'bitrate' => '4000k', 'hdr' => true, - 'still' => true, ], '2160p.hdr.av1.webm' => [ 'width' => 3840, @@ -36,44 +47,6 @@ $profiles = [ 'bitrate' => '25000k', 'hdr' => true, ], - '2160p.sdr.av1.webm' => [ - 'width' => 3840, - 'height' => 2160, - 'codec' => 'libsvtav1', - 'bitrate' => '20000k', - ], - '2160p.sdr.h264.mp4' => [ - 'width' => 3840, - 'height' => 2160, - 'codec' => 'libx264', - 'bitrate' => '50000k', - ], - '1080p.hdr.av1.webm' => [ - 'width' => 1920, - 'height' => 1080, - 'codec' => 'libsvtav1', - 'bitrate' => '6000k', - 'hdr' => true, - ], - '1080p.sdr.av1.webm' => [ - 'width' => 1920, - 'height' => 1080, - 'codec' => 'libsvtav1', - 'bitrate' => '4800k', - ], - '720p.hdr.hevc.mp4' => [ - 'width' => 1280, - 'height' => 720, - 'codec' => 'libx265', - 'bitrate' => '4800k', - 'hdr' => true, - ], - '720p.sdr.h264.mp4' => [ - 'width' => 1280, - 'height' => 720, - 'codec' => 'libx264', - 'bitrate' => '4800k', - ], ]; $options = [ @@ -191,7 +164,8 @@ function convert( $src, $dest, $options ) { //$hdr = $track->color_primaries === 'bt2020' || $options['hdr']; // pix_fmt: "yuv420p10le" $hdr = substr( $track->pix_fmt, -5 ) === 'p10le' || $options['hdr']; - $keyframeInt = intval( ceil( $duration * 60 ) ); + //$keyframeInt = intval( ceil( $duration * 60 ) ); + $keyframeInt = 5 * 60; if (!preg_match( '/(\d+p)\.(.*?)$/', $dest, $matches ) ) { @@ -239,17 +213,40 @@ function convert( $src, $dest, $options ) { } $vf = implode( ',', $filters ); + if ( $codec === 'libvpx-vp9' ) { + $codecOptions = [ + //'-speed', 4, + '-row-mt', 1, + '-tile-columns', 2, + '-cues_to_front', 1, + ]; + } else if ( $codec === 'libsvtav1' ) { + $codecOptions = [ + //'-preset', 4, + '-svtav1-params', 'tile_columns=2', + '-cues_to_front', 1, + ]; + } else if ( $codec === 'libx264' ) { + $codecOptions = [ + '-movflags', '+faststart', + ]; + } else { + $codecOptions = []; + } + if ( $still ) { - run( 'ffmpeg', [ - '-i', $src, - '-vf', $vf, - '-c:v', $codec, - '-b:v', $bitrate, - '-update', 1, - '-frames:v', 1, - '-an', - '-y', $dest - ] ); + run( 'ffmpeg', + array_merge( [ + '-i', $src, + '-vf', $vf, + '-c:v', $codec, + '-q:v', 0.95, + '-update', 1, + '-frames:v', 1, + '-an', + '-y', $dest + ], $codecOptions ) + ); } else { $tempPrefix = 'pack-vid-passlog' . rand(0,1 << 31); $passlog = tempnam( '.', $tempPrefix ); @@ -264,7 +261,7 @@ function convert( $src, $dest, $options ) { '-pass', '1', '-passlogfile', $passlog, '-g', $keyframeInt, - ], $audio, [ + ], $audio, $codecOptions, [ '-y', '/dev/null' ] ) ); @@ -277,8 +274,7 @@ function convert( $src, $dest, $options ) { '-pass', '2', '-passlogfile', $passlog, '-g', $keyframeInt, - ], $audio, [ - '-movflags', '+faststart', + ], $audio, $codecOptions, [ '-y', $dest ] ) );