Compare commits

...

2 commits

Author SHA1 Message Date
fbde3670d7 tonemap/colortemp 2024-05-27 08:44:17 -07:00
7ccc3bd282 wip 2024-03-16 12:35:04 -07:00
3 changed files with 71 additions and 76 deletions

View file

@ -36,6 +36,8 @@ $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 ) == '--' ) {
@ -66,7 +68,8 @@ 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;
@ -325,6 +328,7 @@ 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'] ) {
@ -336,7 +340,11 @@ function convert( $src, $dest, $options ) {
if ( $exposure ) { if ( $exposure ) {
$filters[] = "exposure=$exposure"; $filters[] = "exposure=$exposure";
} }
$filters[] = "tonemap=hable:peak=$peak:desat=0.0"; $colortemperature = $options['colortemperature'];
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,19 +13,10 @@ do
else else
echo "FILE: $INFILE" echo "FILE: $INFILE"
MAPPED="prep-set-${INFILE%.mp4}.2160p.sdr.h264.mp4" prep-vid $OPTS "$INFILE" "${INFILE%.mp4}.480p.sdr.thumb.jpg"
prep-vid $OPTS "$INFILE" "$MAPPED" prep-vid $OPTS "$INFILE" "${INFILE%.mp4}.1080p.sdr.h264.mp4"
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

120
prep-vid
View file

@ -14,20 +14,31 @@ $args = $_SERVER['argv'];
$self = array_shift( $args ); $self = array_shift( $args );
$profiles = [ $profiles = [
'360p.sdr.thumb.jpg' => [ '480p.sdr.thumb.jpg' => [
'width' => 640, 'width' => 854,
'height' => 360, 'height' => 480,
'codec' => 'mjpeg', 'codec' => 'mjpeg',
'bitrate' => '4000k',
'still' => true, 'still' => true,
], ],
'360p.hdr.thumb.avif' => [ '1080p.sdr.h264.mp4' => [
'width' => 640, 'width' => 1920,
'height' => 360, 'height' => 1080,
'codec' => 'libsvtav1', 'codec' => 'libx264',
'bitrate' => '2000k', '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, 'hdr' => true,
'still' => true,
], ],
'2160p.hdr.av1.webm' => [ '2160p.hdr.av1.webm' => [
'width' => 3840, 'width' => 3840,
@ -36,44 +47,6 @@ $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 = [
@ -191,7 +164,8 @@ 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 ) ) {
@ -239,17 +213,40 @@ 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',
'-i', $src, array_merge( [
'-vf', $vf, '-i', $src,
'-c:v', $codec, '-vf', $vf,
'-b:v', $bitrate, '-c:v', $codec,
'-update', 1, '-q:v', 0.95,
'-frames:v', 1, '-update', 1,
'-an', '-frames:v', 1,
'-y', $dest '-an',
] ); '-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 );
@ -264,7 +261,7 @@ function convert( $src, $dest, $options ) {
'-pass', '1', '-pass', '1',
'-passlogfile', $passlog, '-passlogfile', $passlog,
'-g', $keyframeInt, '-g', $keyframeInt,
], $audio, [ ], $audio, $codecOptions, [
'-y', '/dev/null' '-y', '/dev/null'
] ) ] )
); );
@ -277,8 +274,7 @@ function convert( $src, $dest, $options ) {
'-pass', '2', '-pass', '2',
'-passlogfile', $passlog, '-passlogfile', $passlog,
'-g', $keyframeInt, '-g', $keyframeInt,
], $audio, [ ], $audio, $codecOptions, [
'-movflags', '+faststart',
'-y', $dest '-y', $dest
] ) ] )
); );