Compare commits
2 commits
7b47c441fb
...
fbde3670d7
Author | SHA1 | Date | |
---|---|---|---|
fbde3670d7 | |||
7ccc3bd282 |
3 changed files with 71 additions and 76 deletions
12
pack-vid
12
pack-vid
|
@ -36,6 +36,8 @@ $options = [
|
|||
'crop-height' => false,
|
||||
'crop-left' => false,
|
||||
'crop-top' => false,
|
||||
'tonemap' => 'hable',
|
||||
'colortemperature' => false,
|
||||
];
|
||||
|
||||
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" .
|
||||
" --width=n override frame width 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;
|
||||
|
@ -325,6 +328,7 @@ function convert( $src, $dest, $options ) {
|
|||
$sdrNits = 80;
|
||||
$peak = $peakNits / $sdrNits;
|
||||
$vibrance = floatval( $options['vibrance'] );
|
||||
$tonemap = $options['tonemap'];
|
||||
|
||||
$filters = [];
|
||||
if ( $options['crop-width'] || $options['crop-height'] ) {
|
||||
|
@ -336,7 +340,11 @@ function convert( $src, $dest, $options ) {
|
|||
if ( $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'] ) {
|
||||
$dither = ":dither=ordered";
|
||||
} else {
|
||||
|
|
15
prep-set
15
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
|
||||
|
|
120
prep-vid
120
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
|
||||
] )
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue