[FFmpeg-cvslog] avcodec/cfhdenc: improve quality vs size ratio

Paul B Mahol git at videolan.org
Tue Aug 11 11:03:42 EEST 2020


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Tue Aug 11 09:49:24 2020 +0200| [16b79f3d3ae6d330b4b8b439dea14a0bf471c082] | committer: Paul B Mahol

avcodec/cfhdenc: improve quality vs size ratio

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=16b79f3d3ae6d330b4b8b439dea14a0bf471c082
---

 libavcodec/cfhdenc.c | 160 +++++++++++++++++++++++++--------------------------
 1 file changed, 80 insertions(+), 80 deletions(-)

diff --git a/libavcodec/cfhdenc.c b/libavcodec/cfhdenc.c
index d53604ae11..9b045c43c1 100644
--- a/libavcodec/cfhdenc.c
+++ b/libavcodec/cfhdenc.c
@@ -105,94 +105,94 @@ static const uint16_t runbook[8][3] = {
  */
 static const uint16_t quantization_per_subband[2][3][13][9] = {
     {{
-        { 16, 16,  8,  4,  4,  2,   3,   3,   4, }, // film3+
-        { 16, 16,  8,  4,  4,  2,   3,   3,   4, }, // film3
-        { 16, 16,  8,  4,  4,  2,   4,   4,   6, }, // film2+
-        { 16, 16,  8,  4,  4,  2,   4,   4,   6, }, // film2
-        { 16, 16,  8,  4,  4,  2,   8,   8,  12, }, // film1++
-        { 24, 24, 12,  6,  6,  3,  12,  12,  18, }, // film1+
-        { 24, 24, 12,  6,  6,  3,  12,  12,  18, }, // film1
-        { 32, 32, 24,  8,  8,  6,  16,  16,  24, }, // high+
-        { 32, 32, 24,  8,  8,  6,  16,  16,  24, }, // high
-        { 48, 48, 32, 12, 12,  8,  32,  32,  48, }, // medium+
-        { 48, 48, 32, 12, 12,  8,  32,  32,  48, }, // medium
-        { 64, 64, 48, 16, 16, 12,  48,  48,  64, }, // low+
-        { 64, 64, 48, 16, 16, 12,  64,  64,  96, }, // low
+        { 16, 16,  8,  4,  4,  2,   6,   6,   9, }, // film3+
+        { 16, 16,  8,  4,  4,  2,   6,   6,   9, }, // film3
+        { 16, 16,  8,  4,  4,  2,   7,   7,  10, }, // film2+
+        { 16, 16,  8,  4,  4,  2,   8,   8,  12, }, // film2
+        { 16, 16,  8,  4,  4,  2,  16,  16,  26, }, // film1++
+        { 24, 24, 12,  6,  6,  3,  24,  24,  36, }, // film1+
+        { 24, 24, 12,  6,  6,  3,  24,  24,  36, }, // film1
+        { 32, 32, 24,  8,  8,  6,  32,  32,  48, }, // high+
+        { 32, 32, 24,  8,  8,  6,  32,  32,  48, }, // high
+        { 48, 48, 32, 12, 12,  8,  64,  64,  96, }, // medium+
+        { 48, 48, 32, 12, 12,  8,  64,  64,  96, }, // medium
+        { 64, 64, 48, 16, 16, 12,  96,  96, 144, }, // low+
+        { 64, 64, 48, 16, 16, 12, 128, 128, 192, }, // low
     },
     {
-        { 16, 16,  8,  4,  4,  2,   3,   3,   4, },
-        { 16, 16,  8,  4,  4,  2,   3,   3,   6, },
-        { 16, 16,  8,  4,  4,  2,   4,   4,   6, },
-        { 16, 16,  8,  4,  4,  2,   4,   4,   8, },
-        { 16, 16,  8,  4,  4,  2,   8,   8,  16, },
-        { 24, 24, 12,  6,  6,  3,  12,  12,  18, },
-        { 24, 24, 12,  6,  6,  3,  12,  12,  24, },
-        { 32, 32, 24,  8,  8,  6,  16,  16,  24, },
-        { 48, 48, 32, 12, 12,  8,  16,  16,  32, },
-        { 48, 48, 32, 12, 12,  8,  32,  32,  48, },
-        { 48, 48, 32, 12, 12,  8,  32,  32,  64, },
-        { 64, 64, 48, 16, 16, 12,  48,  48,  64, },
-        { 64, 64, 48, 16, 16, 12,  64,  64,  96, },
+        { 16, 16,  8,  4,  4,  2,   6,   6,   9, }, // film3+
+        { 16, 16,  8,  4,  4,  2,   6,   6,  12, }, // film3
+        { 16, 16,  8,  4,  4,  2,   7,   7,  14, }, // film2+
+        { 16, 16,  8,  4,  4,  2,   8,   8,  16, }, // film2
+        { 16, 16,  8,  4,  4,  2,  16,  16,  26, }, // film1++
+        { 24, 24, 12,  6,  6,  3,  24,  24,  36, }, // film1+
+        { 24, 24, 12,  6,  6,  3,  24,  24,  48, }, // film1
+        { 32, 32, 24,  8,  8,  6,  32,  32,  48, }, // high+
+        { 48, 48, 32, 12, 12,  8,  32,  32,  64, }, // high
+        { 48, 48, 32, 12, 12,  8,  64,  64,  96, }, // medium+
+        { 48, 48, 32, 12, 12,  8,  64,  64, 128, }, // medium
+        { 64, 64, 48, 16, 16, 12,  96,  96, 160, }, // low+
+        { 64, 64, 48, 16, 16, 12, 128, 128, 192, }, // low
     },
     {
-        { 16, 16,  8,  4,  4,  2,   3,   3,   4, },
-        { 16, 16,  8,  4,  4,  2,   3,   3,   6, },
-        { 16, 16,  8,  4,  4,  2,   4,   4,   6, },
-        { 16, 16,  8,  4,  4,  2,   4,   4,   8, },
-        { 16, 16,  8,  4,  4,  2,   8,   8,  16, },
-        { 24, 24, 12,  6,  6,  3,  12,  12,  18, },
-        { 24, 24, 12,  6,  6,  3,  12,  12,  24, },
-        { 32, 32, 24,  8,  8,  6,  16,  16,  24, },
-        { 48, 48, 32, 12, 12,  8,  16,  16,  32, },
-        { 48, 48, 32, 12, 12,  8,  32,  32,  48, },
-        { 48, 48, 32, 12, 12,  8,  32,  32,  64, },
-        { 64, 64, 48, 16, 16, 12,  48,  48,  64, },
-        { 64, 64, 48, 16, 16, 12,  64,  64,  96, },
+        { 16, 16,  8,  4,  4,  2,   6,   6,   9, }, // film3+
+        { 16, 16,  8,  4,  4,  2,   6,   6,  12, }, // film3
+        { 16, 16,  8,  4,  4,  2,   7,   7,  14, }, // film2+
+        { 16, 16,  8,  4,  4,  2,   8,   8,  16, }, // film2
+        { 16, 16,  8,  4,  4,  2,  16,  16,  26, }, // film1++
+        { 24, 24, 12,  6,  6,  3,  24,  24,  36, }, // film1+
+        { 24, 24, 12,  6,  6,  3,  24,  24,  48, }, // film1
+        { 32, 32, 24,  8,  8,  6,  32,  32,  48, }, // high+
+        { 48, 48, 32, 12, 12,  8,  32,  32,  64, }, // high
+        { 48, 48, 32, 12, 12,  8,  64,  64,  96, }, // medium+
+        { 48, 48, 32, 12, 12,  8,  64,  64, 128, }, // medium
+        { 64, 64, 48, 16, 16, 12,  96,  96, 160, }, // low+
+        { 64, 64, 48, 16, 16, 12, 128, 128, 192, }, // low
     }},
     {{
-        { 16, 16,  8, 16, 16,  8,  24,  24,  36, },
-        { 16, 16,  8, 16, 16,  8,  32,  32,  48, },
-        { 16, 16,  8, 16, 16,  8,  48,  48,  72, },
-        { 16, 16,  8, 16, 16,  8,  64,  64,  96, },
-        { 16, 16,  8, 20, 20, 10,  80,  80, 128, },
-        { 24, 24, 12, 24, 24, 12,  96,  96, 144, },
-        { 24, 24, 12, 24, 24, 12, 128, 128, 192, },
-        { 32, 32, 24, 32, 32, 24, 192, 192, 288, },
-        { 32, 32, 24, 32, 32, 24, 256, 256, 384, },
-        { 48, 48, 32, 48, 48, 32, 256, 256, 384, },
-        { 48, 48, 32, 48, 48, 32, 512, 512, 768, },
-        { 56, 56, 40, 56, 56, 40, 512, 512, 768, },
-        { 64, 64, 48, 64, 64, 48, 512, 512, 768, },
+        { 16, 16,  8, 16, 16,  8,  24,  24,  36, }, // film3+
+        { 16, 16,  8, 16, 16,  8,  24,  24,  36, }, // film3
+        { 16, 16,  8, 16, 16,  8,  32,  32,  48, }, // film2+
+        { 16, 16,  8, 16, 16,  8,  32,  32,  48, }, // film2
+        { 16, 16,  8, 20, 20, 10,  80,  80, 128, }, // film1++
+        { 24, 24, 12, 24, 24, 12,  96,  96, 144, }, // film1+
+        { 24, 24, 12, 24, 24, 12,  96,  96, 144, }, // film1
+        { 32, 32, 24, 32, 32, 24, 128, 128, 192, }, // high+
+        { 32, 32, 24, 32, 32, 24, 128, 128, 192, }, // high
+        { 48, 48, 32, 48, 48, 32, 256, 256, 384, }, // medium+
+        { 48, 48, 32, 48, 48, 32, 256, 256, 384, }, // medium
+        { 56, 56, 40, 56, 56, 40, 512, 512, 768, }, // low+
+        { 64, 64, 48, 64, 64, 48, 512, 512, 768, }, // low
     },
     {
-        { 16, 16,  8, 16, 16,  8,  24,  24,  36, },
-        { 16, 16,  8, 16, 16,  8,  32,  32,  48, },
-        { 16, 16,  8, 16, 16,  8,  48,  48,  72, },
-        { 16, 16,  8, 16, 16,  8,  64,  64,  96, },
-        { 16, 16,  8, 20, 20, 10,  80,  80, 128, },
-        { 24, 24, 12, 24, 24, 12,  96,  96, 144, },
-        { 24, 24, 12, 24, 24, 12, 128, 128, 192, },
-        { 32, 32, 24, 32, 32, 24, 192, 192, 288, },
-        { 32, 32, 24, 32, 32, 24, 256, 256, 384, },
-        { 48, 48, 32, 48, 48, 32, 256, 256, 384, },
-        { 48, 48, 32, 48, 48, 32, 512, 512, 768, },
-        { 56, 56, 40, 56, 56, 40, 512, 512, 768, },
-        { 64, 64, 48, 64, 64, 48, 512, 512, 768, },
+        { 16, 16,  8, 16, 16,  8,  24,  24,  36, }, // film3+
+        { 16, 16,  8, 16, 16,  8,  48,  48,  72, }, // film3
+        { 16, 16,  8, 16, 16,  8,  48,  48,  72, }, // film2+
+        { 16, 16,  8, 16, 16,  8,  64,  64,  96, }, // film2
+        { 16, 16,  8, 20, 20, 10,  80,  80, 128, }, // film1++
+        { 24, 24, 12, 24, 24, 12,  96,  96, 144, }, // film1+
+        { 24, 24, 12, 24, 24, 12, 192, 192, 288, }, // film1
+        { 32, 32, 24, 32, 32, 24, 128, 128, 192, }, // high+
+        { 32, 32, 24, 32, 32, 24, 256, 256, 384, }, // high
+        { 48, 48, 32, 48, 48, 32, 256, 256, 384, }, // medium+
+        { 48, 48, 32, 48, 48, 32, 512, 512, 768, }, // medium
+        { 56, 56, 40, 56, 56, 40, 512, 512, 768, }, // low+
+        { 64, 64, 48, 64, 64, 48,1024,1024,1536, }, // low
     },
     {
-        { 16, 16,  8, 16, 16,  8,  24,  24,  36, },
-        { 16, 16,  8, 16, 16,  8,  32,  32,  48, },
-        { 16, 16,  8, 16, 16,  8,  48,  48,  72, },
-        { 16, 16,  8, 16, 16,  8,  64,  64,  96, },
-        { 16, 16, 10, 20, 20, 10,  80,  80, 128, },
-        { 24, 24, 12, 24, 24, 12,  96,  96, 144, },
-        { 24, 24, 12, 24, 24, 12, 128, 128, 192, },
-        { 32, 32, 24, 32, 32, 24, 192, 192, 288, },
-        { 32, 32, 24, 32, 32, 24, 256, 256, 384, },
-        { 48, 48, 32, 48, 48, 32, 256, 256, 384, },
-        { 48, 48, 32, 48, 48, 32, 512, 512, 768, },
-        { 56, 56, 40, 56, 56, 40, 512, 512, 768, },
-        { 64, 64, 48, 64, 64, 48, 512, 512, 768, },
+        { 16, 16,  8, 16, 16,  8,  24,  24,  36, }, // film3+
+        { 16, 16,  8, 16, 16,  8,  48,  48,  72, }, // film3
+        { 16, 16,  8, 16, 16,  8,  48,  48,  72, }, // film2+
+        { 16, 16,  8, 16, 16,  8,  64,  64,  96, }, // film2
+        { 16, 16, 10, 20, 20, 10,  80,  80, 128, }, // film1++
+        { 24, 24, 12, 24, 24, 12,  96,  96, 144, }, // film1+
+        { 24, 24, 12, 24, 24, 12, 192, 192, 288, }, // film1
+        { 32, 32, 24, 32, 32, 24, 128, 128, 192, }, // high+
+        { 32, 32, 24, 32, 32, 24, 256, 256, 384, }, // high
+        { 48, 48, 32, 48, 48, 32, 256, 256, 384, }, // medium+
+        { 48, 48, 32, 48, 48, 32, 512, 512, 768, }, // medium
+        { 56, 56, 40, 56, 56, 40, 512, 512, 768, }, // low+
+        { 64, 64, 48, 64, 64, 48,1024,1024,1536, }, // low
     }},
 };
 
@@ -405,11 +405,11 @@ static void vert_filter(int16_t *input, ptrdiff_t in_stride,
 static void quantize_band(int16_t *input, int width, int a_width,
                           int height, unsigned quantization)
 {
-    const int factor = (1 << 16) / quantization;
+    const int16_t factor = (uint32_t)(1U << 15) / quantization;
 
     for (int i = 0; i < height; i++) {
         for (int j = 0; j < width; j++)
-            input[j] = av_clip_intp2((input[j] * factor) / 65536, 10);
+            input[j] = av_clip_intp2(((input[j] * factor + 16384 * FFSIGN(input[j])) / 32768), 10);
         input += a_width;
     }
 }



More information about the ffmpeg-cvslog mailing list