]> git.sesse.net Git - pr0n/commitdiff
Switch to 4:4:4 for AVIF.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 8 Jun 2021 22:18:39 +0000 (00:18 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 8 Jun 2021 22:18:39 +0000 (00:18 +0200)
perl/Sesse/pr0n/Common.pm

index c9511af8dbc594b21490ddd715d246554d9e5526..f6cea5b98ab8e9de7721decb63f167707eea8e43 100644 (file)
@@ -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);