[FFmpeg-devel] ZMBV Improved Motion Estimation

Michael Niedermayer michaelni
Thu May 8 23:58:00 CEST 2008


On Wed, May 07, 2008 at 10:27:13PM -0700, Mike Melanson wrote:
> Hi,
> 
> I have been studying ZMBV (DosBox Capture Codec) for improvement 
> opportunities. One of the first items I noticed was the motion 
> estimator's block comparison function. Presently, the function XOR's 2 
> blocks together bytewise and sums all XOR'd bytes, choosing the block 
> with the lowest sum. This might help minimize error if the bytes in each 
> block represented intensity levels. However, in this case, the bytes are 
> palette indices and are more or less random numbers.
> 
> I propose that it would be more effective to simply sum the number of 
> bytes between 2 blocks that are different. I also obtained some hard 
> numbers using FLI files (the -new files use the attached patch):
> 
> $ dir *.avi
>   17104594 2008-05-07 21:44 zmbv-capcom.avi
>   16850122 2008-05-07 21:47 zmbv-capcom-new.avi
>     796366 2008-05-07 21:55 zmbv-crusher.avi
>     794910 2008-05-07 21:59 zmbv-crusher-new.avi
>    2364794 2008-05-07 21:53 zmbv-float.avi
>    2300892 2008-05-07 21:51 zmbv-float-new.avi

16774286 2008-05-08 23:20 capcom-h1-i256.avi
  793356 2008-05-08 23:01 crusher-h1-i256.avi
 2288290 2008-05-08 23:24 float-h1-i256.avi

Index: libavcodec/zmbvenc.c
===================================================================
--- libavcodec/zmbvenc.c	(revision 13005)
+++ libavcodec/zmbvenc.c	(working copy)
@@ -54,6 +54,8 @@
     z_stream zstream;
 } ZmbvEncContext;
 
+static int score_tab[256];
+
 /** Block comparing function
  * XXX should be optimized and moved to DSPContext
  * TODO handle out of edge ME
@@ -62,13 +64,18 @@
 {
     int sum = 0;
     int i, j;
+    uint8_t histogram[256]={0};
 
     for(j = 0; j < bh; j++){
         for(i = 0; i < bw; i++)
-            sum += src[i] ^ src2[i];
+            histogram[src[i] ^ src2[i]]++;
         src += stride;
         src2 += stride2;
     }
+
+    for(i=1; i<256; i++)
+        sum+= score_tab[histogram[i]];
+
     return sum;
 }
 
@@ -235,8 +242,12 @@
 {
     ZmbvEncContext * const c = avctx->priv_data;
     int zret; // Zlib return code
+    int i;
     int lvl = 9;
 
+    for(i=1; i<256; i++)
+        score_tab[i]= -i * log2(i/256.0) * 256;
+
     c->avctx = avctx;
 
     c->pic.data[0] = NULL;

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Everything should be made as simple as possible, but not simpler.
-- Albert Einstein
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080508/5216dfe9/attachment.pgp>



More information about the ffmpeg-devel mailing list