]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/commitdiff
fix display of theora videos with visible size smaller than encoded size
authoraurel <aurel@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Mon, 7 May 2007 15:43:01 +0000 (15:43 +0000)
committeraurel <aurel@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Mon, 7 May 2007 15:43:01 +0000 (15:43 +0000)
git-svn-id: file:///var/local/repositories/ffmpeg/trunk@8928 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b

libavcodec/vp3.c
libavformat/oggparsetheora.c

index 0a5d7601355d5bc773ed464d13a06081dd3dc9a6..a8529fb7ffa30ac92020715e91fe16781d9e8930 100644 (file)
@@ -2371,6 +2371,7 @@ static int read_huffman_tree(AVCodecContext *avctx, GetBitContext *gb)
 static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb)
 {
     Vp3DecodeContext *s = avctx->priv_data;
+    int visible_width, visible_height;
 
     s->theora = get_bits_long(gb, 24);
     av_log(avctx, AV_LOG_INFO, "Theora bitstream version %X\n", s->theora);
@@ -2399,16 +2400,11 @@ static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb)
         skip_bits(gb, 32); /* total number of blocks in a frame */
         skip_bits(gb, 4); /* total number of blocks in a frame */
         skip_bits(gb, 32); /* total number of macroblocks in a frame */
-
-        skip_bits(gb, 24); /* frame width */
-        skip_bits(gb, 24); /* frame height */
-    }
-    else
-    {
-        skip_bits(gb, 24); /* frame width */
-        skip_bits(gb, 24); /* frame height */
     }
 
+    visible_width  = get_bits_long(gb, 24);
+    visible_height = get_bits_long(gb, 24);
+
   if (s->theora >= 0x030200) {
     skip_bits(gb, 8); /* offset x */
     skip_bits(gb, 8); /* offset y */
@@ -2438,8 +2434,11 @@ static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb)
 
 //    align_get_bits(gb);
 
-    avctx->width = s->width;
-    avctx->height = s->height;
+    if (   visible_width  <= s->width  && visible_width  > s->width-16
+        && visible_height <= s->height && visible_height > s->height-16)
+        avcodec_set_dimensions(avctx, visible_width, visible_height);
+    else
+        avcodec_set_dimensions(avctx, s->width, s->height);
 
     return 0;
 }
index 9052bbbea060d945a75fb11cbd87ecb36405f94c..c2045ce17e02b28973b2b7cc18bc0831c78e411a 100644 (file)
@@ -53,6 +53,7 @@ theora_header (AVFormatContext * s, int idx)
 
     if (os->buf[os->pstart] == 0x80) {
         GetBitContext gb;
+        int width, height;
         int version;
 
         init_get_bits(&gb, os->buf + os->pstart, os->psize*8);
@@ -70,13 +71,21 @@ theora_header (AVFormatContext * s, int idx)
             return -1;
         }
 
-        st->codec->width = get_bits(&gb, 16) << 4;
-        st->codec->height = get_bits(&gb, 16) << 4;
+        width  = get_bits(&gb, 16) << 4;
+        height = get_bits(&gb, 16) << 4;
+        avcodec_set_dimensions(st->codec, width, height);
 
         if (version >= 0x030400)
-            skip_bits(&gb, 164);
-        else if (version >= 0x030200)
-            skip_bits(&gb, 64);
+            skip_bits(&gb, 100);
+
+        width  = get_bits_long(&gb, 24);
+        height = get_bits_long(&gb, 24);
+        if (   width  <= st->codec->width  && width  > st->codec->width-16
+            && height <= st->codec->height && height > st->codec->height-16)
+            avcodec_set_dimensions(st->codec, width, height);
+
+        if (version >= 0x030200)
+            skip_bits(&gb, 16);
         st->codec->time_base.den = get_bits(&gb, 32);
         st->codec->time_base.num = get_bits(&gb, 32);
         st->time_base = st->codec->time_base;