[FFmpeg-devel] [PATCH] Do not drop packets with no valid ->pos set as e.g. DV-in-AVI produces.

Reimar Döffinger Reimar.Doeffinger at gmx.de
Sat Apr 30 11:50:48 CEST 2011


Fixes ticket #140.
---
 libavformat/avidec.c |   18 +++++-------------
 1 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index 97b392a..e5e3726 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -592,16 +592,12 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
                     /* This code assumes that extradata contains only palette. */
                     /* This is true for all paletted codecs implemented in FFmpeg. */
                     if (st->codec->extradata_size && (st->codec->bits_per_coded_sample <= 8)) {
-                        int pal_size = (1 << st->codec->bits_per_coded_sample) << 2;
-                        const uint8_t *pal_src;
-
-                        pal_size = FFMIN(pal_size, st->codec->extradata_size);
-                        pal_src = st->codec->extradata + st->codec->extradata_size - pal_size;
 #if HAVE_BIGENDIAN
-                        for (i = 0; i < pal_size/4; i++)
-                            ast->pal[i] = AV_RL32(pal_src+4*i);
+                        for (i = 0; i < FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)/4; i++)
+                            ast->pal[i] = av_bswap32(((uint32_t*)st->codec->extradata)[i]);
 #else
-                        memcpy(ast->pal, pal_src, pal_size);
+                        memcpy(ast->pal, st->codec->extradata,
+                               FFMIN(st->codec->extradata_size, AVPALETTE_SIZE));
 #endif
                         ast->has_pal = 1;
                     }
@@ -738,10 +734,6 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
         if(st->nb_index_entries)
             break;
     }
-    // DV-in-AVI cannot be non-interleaved, if set this must be
-    // a mis-detection.
-    if(avi->dv_demux)
-        avi->non_interleaved=0;
     if(i==s->nb_streams && avi->non_interleaved) {
         av_log(s, AV_LOG_WARNING, "non-interleaved AVI without index, switching to interleaved\n");
         avi->non_interleaved=0;
@@ -997,7 +989,7 @@ resync:
             ast->packet_size= 0;
         }
 
-        if(!avi->non_interleaved && ast->seek_pos > pkt->pos){
+        if(!avi->non_interleaved && pkt->pos >= 0 && ast->seek_pos > pkt->pos){
             av_free_packet(pkt);
             goto resync;
         }
-- 
1.7.4.4



More information about the ffmpeg-devel mailing list