From: Steinar H. Gunderson Date: Tue, 8 Jun 2021 22:18:39 +0000 (+0200) Subject: Switch to 4:4:4 for AVIF. X-Git-Url: https://git.sesse.net/?p=pr0n;a=commitdiff_plain;h=c7fd47d6b2323d28a5ece7f3019b40224605cb61 Switch to 4:4:4 for AVIF. --- diff --git a/perl/Sesse/pr0n/Common.pm b/perl/Sesse/pr0n/Common.pm index c9511af..f6cea5b 100644 --- a/perl/Sesse/pr0n/Common.pm +++ b/perl/Sesse/pr0n/Common.pm @@ -631,11 +631,6 @@ sub make_cache { my $height = $img->Get('rows'); my ($nwidth, $nheight) = scale_aspect($width, $height, $xres, $yres); - if ($format eq 'avif') { # AVIF uses 4:2:0. - ++$nwidth if ($nwidth % 2 == 1); - ++$nheight if ($nheight % 2 == 1); - } - my $filter = 'Lanczos'; my $quality = 87; my $sf = "1x1"; @@ -665,20 +660,20 @@ sub make_cache { # and Debian hasn't packaged that even in unstable as of 2021. # So we'll need to do it the manual way. (We don't use /tmp, for security reasons.) (my $dirname = $cachename) =~ s,/[^/]*$,,; - my ($fh, $raw_filename) = File::Temp::tempfile('tmp.XXXXXXXX', DIR => $dirname, SUFFIX => '.yuv'); - # Write a Y4M header, so that we get the chroma siting and color space correct. - printf $fh "YUV4MPEG2 W%d H%d F25:1 Ip A1:1 C420jpeg XYSCSS=420JPEG XCOLORRANGE=FULL\nFRAME\n", $nwidth, $nheight; + my ($fh, $raw_filename) = File::Temp::tempfile('tmp.XXXXXXXX', DIR => $dirname, SUFFIX => '.ycbcr'); + # Write a Y4M header, so that we get the chroma range correct. + printf $fh "YUV4MPEG2 W%d H%d F25:1 Ip A1:1 C444 XYSCSS=444 XCOLORRANGE=FULL\nFRAME\n", $nwidth, $nheight; my %parms = ( file => $fh, filename => $raw_filename, - 'sampling-factor' => '2x2' + interlace => 'Plane' ); $cimg->write(%parms); close($fh); my $ivf_filename; ($fh, $ivf_filename) = File::Temp::tempfile('tmp.XXXXXXXX', DIR => $dirname, SUFFIX => '.ivf'); close($fh); - system('aomenc', '--quiet', '--cpu-used=0', '--bit-depth=10', '--end-usage=q', '--cq-level=10', '--target-bitrate=0', '--good', '--aq-mode=1', '--matrix-coefficients=bt601', '-o', $ivf_filename, $raw_filename); + system('aomenc', '--quiet', '--cpu-used=0', '--bit-depth=10', '--end-usage=q', '--cq-level=13', '--target-bitrate=0', '--good', '--aq-mode=1', '--matrix-coefficients=bt601', '-o', $ivf_filename, $raw_filename); unlink($raw_filename); system('MP4Box', '-quiet', '-add-image', "$ivf_filename:primary", '-ab', 'avif', '-ab', 'miaf', '-new', $cachename); unlink($ivf_filename);