changeset 1411:c2e63cb94d06 libavcodec

custom quant matrix encoding support
author michaelni
date Fri, 22 Aug 2003 22:18:08 +0000
parents 524c904a66b8
children e101d1cffec6
files avcodec.h h263.c mpeg12.c mpegvideo.c mpegvideo.h
diffstat 5 files changed, 50 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/avcodec.h	Fri Aug 22 14:59:04 2003 +0000
+++ b/avcodec.h	Fri Aug 22 22:18:08 2003 +0000
@@ -15,8 +15,8 @@
 
 #define LIBAVCODEC_VERSION_INT 0x000406
 #define LIBAVCODEC_VERSION     "0.4.6"
-#define LIBAVCODEC_BUILD       4674
-#define LIBAVCODEC_BUILD_STR   "4674"
+#define LIBAVCODEC_BUILD       4675
+#define LIBAVCODEC_BUILD_STR   "4675"
 
 #define LIBAVCODEC_IDENT	"FFmpeg" LIBAVCODEC_VERSION "b" LIBAVCODEC_BUILD_STR
 
@@ -1186,6 +1186,20 @@
 #define FF_MB_DECISION_SIMPLE 0        ///< uses mb_cmp
 #define FF_MB_DECISION_BITS   1        ///< chooses the one which needs the fewest bits
 #define FF_MB_DECISION_RD     2        ///< rate distoration
+
+    /**
+     * custom intra quantization matrix
+     * - encoding: set by user, can be NULL
+     * - decoding: set by lavc
+     */
+    uint16_t *intra_matrix;
+
+    /**
+     * custom inter quantization matrix
+     * - encoding: set by user, can be NULL
+     * - decoding: set by lavc
+     */
+    uint16_t *inter_matrix;
     
 } AVCodecContext;
 
--- a/h263.c	Fri Aug 22 14:59:04 2003 +0000
+++ b/h263.c	Fri Aug 22 22:18:08 2003 +0000
@@ -1859,7 +1859,11 @@
     s->quant_precision=5;
     put_bits(&s->pb, 1, 0);		/* not 8 bit == false */
     put_bits(&s->pb, 1, s->mpeg_quant);	/* quant type= (0=h263 style)*/
-    if(s->mpeg_quant) put_bits(&s->pb, 2, 0); /* no custom matrixes */
+
+    if(s->mpeg_quant){
+        ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix);
+        ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix);
+    }
 
     if (vo_ver_id != 1)
         put_bits(&s->pb, 1, s->quarter_sample);
@@ -4551,14 +4555,15 @@
         skip_bits(gb, 4);  //video_object_layer_shape_extension
     }
 
-    skip_bits1(gb);   /* marker */
+    check_marker(gb, "before time_increment_resolution");
     
     s->time_increment_resolution = get_bits(gb, 16);
     
     s->time_increment_bits = av_log2(s->time_increment_resolution - 1) + 1;
     if (s->time_increment_bits < 1)
         s->time_increment_bits = 1;
-    skip_bits1(gb);   /* marker */
+        
+    check_marker(gb, "before fixed_vop_rate");
 
     if (get_bits1(gb) != 0) {   /* fixed_vop_rate  */
         skip_bits(gb, s->time_increment_bits);
@@ -4648,8 +4653,8 @@
                 /* replicate last value */
                 for(; i<64; i++){
 		    int j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
-                    s->intra_matrix[j]= v;
-                    s->chroma_intra_matrix[j]= v;
+                    s->intra_matrix[j]= last;
+                    s->chroma_intra_matrix[j]= last;
                 }
             }
 
@@ -4842,7 +4847,10 @@
         printf("my guess is %d bits ;)\n",s->time_increment_bits);
     }
     
-    time_increment= get_bits(gb, s->time_increment_bits);
+    if(IS_3IV1) time_increment= get_bits1(gb); //FIXME investigate further
+    else time_increment= get_bits(gb, s->time_increment_bits);
+    
+//    printf("%d %X\n", s->time_increment_bits, time_increment);
 //printf(" type:%d modulo_time_base:%d increment:%d\n", s->pict_type, time_incr, time_increment);
     if(s->pict_type!=B_TYPE){
         s->last_time_base= s->time_base;
--- a/mpeg12.c	Fri Aug 22 14:59:04 2003 +0000
+++ b/mpeg12.c	Fri Aug 22 22:18:08 2003 +0000
@@ -240,8 +240,9 @@
                 vbv_buffer_size = (( 20 * s->bit_rate) / (1151929 / 2)) * 8 * 1024;	 
             put_bits(&s->pb, 10, (vbv_buffer_size + 16383) / 16384); 
             put_bits(&s->pb, 1, 1); /* constrained parameter flag */
-            put_bits(&s->pb, 1, 0); /* no custom intra matrix */
-            put_bits(&s->pb, 1, 0); /* no custom non intra matrix */
+            
+            ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix);
+            ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix);
 
             put_header(s, GOP_START_CODE);
             put_bits(&s->pb, 1, 0); /* do drop frame */
--- a/mpegvideo.c	Fri Aug 22 14:59:04 2003 +0000
+++ b/mpegvideo.c	Fri Aug 22 22:18:08 2003 +0000
@@ -167,6 +167,18 @@
     }
 }
 
+void ff_write_quant_matrix(PutBitContext *pb, int16_t *matrix){
+    int i;
+
+    if(matrix){
+        put_bits(pb, 1, 1);
+        for(i=0;i<64;i++) {
+            put_bits(pb, 8, matrix[ ff_zigzag_direct[i] ]);
+        }
+    }else
+        put_bits(pb, 1, 0);
+}
+
 /* init common dct for both encoder and decoder */
 int DCT_common_init(MpegEncContext *s)
 {
@@ -812,6 +824,10 @@
             s->intra_matrix[j] = ff_mpeg1_default_intra_matrix[i];
             s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i];
         }
+        if(s->avctx->intra_matrix)
+            s->intra_matrix[j] = s->avctx->intra_matrix[i];
+        if(s->avctx->inter_matrix)
+            s->inter_matrix[j] = s->avctx->inter_matrix[i];
     }
 
     /* precompute matrix */
--- a/mpegvideo.h	Fri Aug 22 14:59:04 2003 +0000
+++ b/mpegvideo.h	Fri Aug 22 22:18:08 2003 +0000
@@ -716,6 +716,7 @@
 int ff_combine_frame( MpegEncContext *s, int next, uint8_t **buf, int *buf_size);
 void ff_mpeg_flush(AVCodecContext *avctx);
 void ff_print_debug_info(MpegEncContext *s, Picture *pict);
+void ff_write_quant_matrix(PutBitContext *pb, int16_t *matrix);
 
 void ff_er_frame_start(MpegEncContext *s);
 void ff_er_frame_end(MpegEncContext *s);