[Ffmpeg-devel] [PATCH] DV image quality improvement
Dan Maas
dmaas
Mon Feb 27 13:15:58 CET 2006
> I have nothing against having this alternative method for assigning
> class numbers, but I would like to
> suggest one thing: could you, please, make it easy to switch
> between the two versions of how classes are assigned ?
See attached... I've rewritten the patch so that it's just a one-line
change from the SMPTE method.
I also included the new checksums. The PSNR increase on ffmpeg's test
video is from 29.03 to 29.17. The impact on natural-looking live video
is more dramatic - the 4825-frame BBC test video (all live scenes)
goes up from 41.77 to 44.72 with my adjustment (in DV50 mode - patch
forthcoming).
> I completely agree with you here. In fact, when I was developing DV encoder
> the quantization step table (on page 37) made me very puzzled. It is quite
> obvious to anyone that having just two class numbers 2 and 3 is enough
> to cover *all* possible cases of quantization
Class number is per-block, whereas QNO is per-macroblock. A really
sophisticated encoder could optimize class numbers together with QNO
to squeeze out every last bit of efficiency. Of course, that would
come at a huge cost in CPU time.
On the bright side, I've looked at a lot of DV encoders, and most of
them don't even come close to the sophistication of ffmpeg's. For
instance, my $1500 Canopus ADVC-500 hardware encoder assigns a fixed
QNO to almost all blocks, and performs quantization very coarsely by
playing with class numbers. Only Apple's encoder seems to make an
attempt of optimizing both class numbers and QNO. But it's still more
conservative than ffmpeg in QNO assignment, so the results aren't
necessarily better. With this class-number patch, ffmpeg's output is
roughly equal in image quality to the Apple encoder. (no small feat,
as Apple's is one of the best, if not the best one out there)
Regards,
Dan
-------------- next part --------------
Index: libavcodec/dv.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/libavcodec/dv.c,v
retrieving revision 1.80
diff -u -p -r1.80 dv.c
--- libavcodec/dv.c 27 Feb 2006 05:04:05 -0000 1.80
+++ libavcodec/dv.c 27 Feb 2006 12:09:28 -0000
@@ -658,8 +658,22 @@ static always_inline void dv_set_class_n
const uint8_t* zigzag_scan, const int *weight, int bias)
{
int i, area;
+ /* We offer two different methods for class number assignment: the
+ method suggested in SMPTE 314M Table 22, and an improved
+ method. The SMPTE method is very conservative; it assigns class
+ 3 (i.e. severe quantization) to any block where the largest AC
+ component is greater than 36. ffmpeg's DV encoder tracks AC bit
+ consumption precisely, so there is no need to bias most blocks
+ towards strongly lossy compression. Instead, we assign class 2
+ to most blocks, and use class 3 only when strictly necessary
+ (for blocks whose largest AC component exceeds 255). */
+
+#if 0 /* SMPTE spec method */
static const int classes[] = {12, 24, 36, 0xffff};
- int max=12;
+#else /* improved ffmpeg method */
+ static const int classes[] = {-1, -1, 255, 0xffff};
+#endif
+ int max=classes[0];
int prev=0;
bi->mb[0] = blk[0];
Index: tests/ffmpeg.regression.ref
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/tests/ffmpeg.regression.ref,v
retrieving revision 1.167
diff -u -p -r1.167 ffmpeg.regression.ref
--- tests/ffmpeg.regression.ref 27 Feb 2006 04:50:05 -0000 1.167
+++ tests/ffmpeg.regression.ref 27 Feb 2006 12:09:29 -0000
@@ -133,10 +133,10 @@ stddev: 23.20 PSNR:20.81 bytes:7602176
3533710 ./data/a-snow53.avi
799d3db687f6cdd7a837ec156efc171f *./data/out.yuv
stddev: 0.00 PSNR:99.99 bytes:7602176
-1352049a75c5c94f21a360888b12d75d *./data/a-dv.dv
+85529d9838c5a8aef041445fa8ef3c85 *./data/a-dv.dv
7200000 ./data/a-dv.dv
-2c7f745a74c1ac25566b6c49ed619649 *./data/out.yuv
-stddev: 9.00 PSNR:29.03 bytes:7602176
+c2082cd8adf417c4ebc32654e446cba1 *./data/out.yuv
+stddev: 8.86 PSNR:29.17 bytes:7602176
bd0db310a36ad94bcd4448abe0a88368 *./data/a-svq1.mov
1379827 ./data/a-svq1.mov
bbff871d1475e1eee4231a08e075de2c *./data/out.yuv
More information about the ffmpeg-devel
mailing list