[FFmpeg-devel] [PATCH] H.264/AVCHD interlaced fixes

Ivan Schreter schreter
Mon Feb 16 10:47:00 CET 2009


Michael Niedermayer wrote:
> of course ANY method that scans the whole is unacceptable and i mean
> unacceptable in the sense that no argument will help you, we will
> not read the whole frame to extract 5 fields from the headers in the
> first 20 bytes
>   
True. So I suppose something like this would suit your requirements:

+    for(;;){
+        int src_length, dst_length, consumed, bit_length;
+        buf = ff_find_start_code(buf, buf_end, &state);
+        /*for(; buf + 3 < buf_end; buf++){
+            // This should always succeed in the first iteration.
+            if(buf[0] == 0 && buf[1] == 0 && buf[2] == 1)
+                break;
+        }
+        buf += 3;*/
+        if(buf >= buf_end)
+            break;
+        --buf;
+        src_length = buf_end - buf;
+        switch (buf[0] & 0x1f) {
+        case NAL_SLICE:
+        case NAL_IDR_SLICE:
+            // Do not walk the whole buffer just to decode slice header
+            if (src_length > 20)
+                src_length = 20;
+            break;
+        }
+        ptr= ff_h264_decode_nal(h, buf, &dst_length, &consumed, 
src_length);
+        if (ptr==NULL || dst_length < 0)
+            break;
+        while(ptr[dst_length - 1] == 0 && dst_length > 0)
+            dst_length--;
+        bit_length= !dst_length ? 0 : (8*dst_length - 
ff_h264_decode_rbsp_trailing(h, ptr + dst_length - 1));
+
+        init_get_bits(&h->s.gb, ptr, bit_length);
+        nal = h->nal_unit_type;
[...]
+        buf += consumed;
+    }


In this case, everything up to slice header must be decoded fully (no 
way around it, since we need to get to the slice header, but it's 
normally just peanuts), and then for slice itself, we will decode only 
first 20 bytes or so. I need to check exact size needed, but 20 bytes 
should be actually enough. The loop terminates at slice header.

Please let me know, if you are happy with it, so I can update the patch 
appropriately.

Thanks & regards,

Ivan





More information about the ffmpeg-devel mailing list