[Ffmpeg-devel] [RFC] VC1 frame decoder

Kostya kostya.shishkov
Sun Jan 21 08:05:08 CET 2007


Forgot to attach.
-------------- next part --------------
Index: vc1.c
===================================================================
--- libavcodec/vc1.c	(revision 7590)
+++ libavcodec/vc1.c	(working copy)
@@ -4222,10 +4222,29 @@
 
     //for advanced profile we need to unescape buffer
     if (avctx->codec_id == CODEC_ID_VC1) {
-        int i, buf_size2;
+        int i, buf_size2, skip = 0;
         buf2 = av_malloc(buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
         buf_size2 = 0;
-        for(i = 0; i < buf_size; i++) {
+        // test if frame starts with some escape and seek to frame start
+        if(!buf[0] && !buf[1] && buf[2] == 1 && buf[3] != 3){
+            if(buf[3] == 0x0D || buf[3] == 0x0C){
+                skip = 4;
+            }else{
+                int code;
+                // search for frame/field start code
+                code = AV_RB32(buf);
+                while(skip < buf_size - 4){
+                    code <<= 8;
+                    code |= buf[skip++];
+                    if(code == 0x0000010D || code == 0x0000010C) break;
+                }
+                if(skip == buf_size - 4){
+                    av_log(avctx, AV_LOG_ERROR, "Frame begins with marker but no frame/field marker found\n");
+                    return -1;
+                }
+            }
+        }
+        for(i = skip; i < buf_size; i++) {
             if(buf[i] == 3 && i >= 2 && !buf[i-1] && !buf[i-2] && i < buf_size-1 && buf[i+1] < 4) {
                 buf2[buf_size2++] = buf[i+1];
                 i++;



More information about the ffmpeg-devel mailing list