Compare commits

..

No commits in common. "fbde3670d7679edc1215306d12a0a8217a999f9a" and "7b47c441fb8ce78872d0380b3c3ac307de100b0c" have entirely different histories.

3 changed files with 75 additions and 70 deletions

View file

@ -36,8 +36,6 @@ $options = [
'crop-height' => false, 'crop-height' => false,
'crop-left' => false, 'crop-left' => false,
'crop-top' => false, 'crop-top' => false,
'tonemap' => 'hable',
'colortemperature' => false,
]; ];
while ( count( $args ) > 0 && substr( $args[0], 0, 2 ) == '--' ) { while ( count( $args ) > 0 && substr( $args[0], 0, 2 ) == '--' ) {
@ -68,8 +66,7 @@ if ( count ( $args ) < 2 ) {
" --dither enable dithering in 8-bit downconversion\n" . " --dither enable dithering in 8-bit downconversion\n" .
" --width=n override frame width in pixels\n" . " --width=n override frame width in pixels\n" .
" --height=n override frame height in pixels\n" . " --height=n override frame height in pixels\n" .
" --keyframe-int=n set keyframe interval (default 0)\n" . " --keyframe-int=n set keyframe interval (default 0)\n"
" --tonemap=mode set HDR tone mapping mode (hable, clip, etc)\n"
); );
} }
[ $src, $dest ] = $args; [ $src, $dest ] = $args;
@ -328,7 +325,6 @@ function convert( $src, $dest, $options ) {
$sdrNits = 80; $sdrNits = 80;
$peak = $peakNits / $sdrNits; $peak = $peakNits / $sdrNits;
$vibrance = floatval( $options['vibrance'] ); $vibrance = floatval( $options['vibrance'] );
$tonemap = $options['tonemap'];
$filters = []; $filters = [];
if ( $options['crop-width'] || $options['crop-height'] ) { if ( $options['crop-width'] || $options['crop-height'] ) {
@ -340,11 +336,7 @@ function convert( $src, $dest, $options ) {
if ( $exposure ) { if ( $exposure ) {
$filters[] = "exposure=$exposure"; $filters[] = "exposure=$exposure";
} }
$colortemperature = $options['colortemperature']; $filters[] = "tonemap=hable:peak=$peak:desat=0.0";
if ( $colortemperature ) {
$filters[] = "colortemperature=$colortemperature";
}
$filters[] = "tonemap=$tonemap:peak=$peak:desat=0.0";
if ( $options['dither'] ) { if ( $options['dither'] ) {
$dither = ":dither=ordered"; $dither = ":dither=ordered";
} else { } else {

View file

@ -13,10 +13,19 @@ do
else else
echo "FILE: $INFILE" echo "FILE: $INFILE"
prep-vid $OPTS "$INFILE" "${INFILE%.mp4}.480p.sdr.thumb.jpg" MAPPED="prep-set-${INFILE%.mp4}.2160p.sdr.h264.mp4"
prep-vid $OPTS "$INFILE" "${INFILE%.mp4}.1080p.sdr.h264.mp4" prep-vid $OPTS "$INFILE" "$MAPPED"
prep-vid $OPTS "$INFILE" "${INFILE%.mp4}.1080p.hdr.vp9.webm"
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}.1080p.hdr.av1.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" prep-vid $OPTS "$INFILE" "${INFILE%.mp4}.2160p.hdr.av1.webm"
fi fi
done done

104
prep-vid
View file

@ -14,31 +14,20 @@ $args = $_SERVER['argv'];
$self = array_shift( $args ); $self = array_shift( $args );
$profiles = [ $profiles = [
'480p.sdr.thumb.jpg' => [ '360p.sdr.thumb.jpg' => [
'width' => 854, 'width' => 640,
'height' => 480, 'height' => 360,
'codec' => 'mjpeg', 'codec' => 'mjpeg',
'bitrate' => '4000k',
'still' => true, 'still' => true,
], ],
'1080p.sdr.h264.mp4' => [ '360p.hdr.thumb.avif' => [
'width' => 1920, 'width' => 640,
'height' => 1080, 'height' => 360,
'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', 'codec' => 'libsvtav1',
'bitrate' => '4000k', 'bitrate' => '2000k',
'hdr' => true, 'hdr' => true,
'still' => true,
], ],
'2160p.hdr.av1.webm' => [ '2160p.hdr.av1.webm' => [
'width' => 3840, 'width' => 3840,
@ -47,6 +36,44 @@ $profiles = [
'bitrate' => '25000k', 'bitrate' => '25000k',
'hdr' => true, '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 = [ $options = [
@ -164,8 +191,7 @@ function convert( $src, $dest, $options ) {
//$hdr = $track->color_primaries === 'bt2020' || $options['hdr']; //$hdr = $track->color_primaries === 'bt2020' || $options['hdr'];
// pix_fmt: "yuv420p10le" // pix_fmt: "yuv420p10le"
$hdr = substr( $track->pix_fmt, -5 ) === 'p10le' || $options['hdr']; $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 ) ) { if (!preg_match( '/(\d+p)\.(.*?)$/', $dest, $matches ) ) {
@ -213,40 +239,17 @@ function convert( $src, $dest, $options ) {
} }
$vf = implode( ',', $filters ); $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 ) { if ( $still ) {
run( 'ffmpeg', run( 'ffmpeg', [
array_merge( [
'-i', $src, '-i', $src,
'-vf', $vf, '-vf', $vf,
'-c:v', $codec, '-c:v', $codec,
'-q:v', 0.95, '-b:v', $bitrate,
'-update', 1, '-update', 1,
'-frames:v', 1, '-frames:v', 1,
'-an', '-an',
'-y', $dest '-y', $dest
], $codecOptions ) ] );
);
} else { } else {
$tempPrefix = 'pack-vid-passlog' . rand(0,1 << 31); $tempPrefix = 'pack-vid-passlog' . rand(0,1 << 31);
$passlog = tempnam( '.', $tempPrefix ); $passlog = tempnam( '.', $tempPrefix );
@ -261,7 +264,7 @@ function convert( $src, $dest, $options ) {
'-pass', '1', '-pass', '1',
'-passlogfile', $passlog, '-passlogfile', $passlog,
'-g', $keyframeInt, '-g', $keyframeInt,
], $audio, $codecOptions, [ ], $audio, [
'-y', '/dev/null' '-y', '/dev/null'
] ) ] )
); );
@ -274,7 +277,8 @@ function convert( $src, $dest, $options ) {
'-pass', '2', '-pass', '2',
'-passlogfile', $passlog, '-passlogfile', $passlog,
'-g', $keyframeInt, '-g', $keyframeInt,
], $audio, $codecOptions, [ ], $audio, [
'-movflags', '+faststart',
'-y', $dest '-y', $dest
] ) ] )
); );