[Ffmpeg-cvslog] r8215 - in trunk/libavcodec: avcodec.h mpeg12.c mpeg12data.h mpegvideo.c utils.c

bcoudurier subversion
Sun Mar 4 03:26:21 CET 2007


Author: bcoudurier
Date: Sun Mar  4 03:26:20 2007
New Revision: 8215

Modified:
   trunk/libavcodec/avcodec.h
   trunk/libavcodec/mpeg12.c
   trunk/libavcodec/mpeg12data.h
   trunk/libavcodec/mpegvideo.c
   trunk/libavcodec/utils.c

Log:
dummy support for mpeg2 non linear quant

Modified: trunk/libavcodec/avcodec.h
==============================================================================
--- trunk/libavcodec/avcodec.h	(original)
+++ trunk/libavcodec/avcodec.h	Sun Mar  4 03:26:20 2007
@@ -37,8 +37,8 @@ extern "C" {
 #define AV_STRINGIFY(s)         AV_TOSTRING(s)
 #define AV_TOSTRING(s) #s
 
-#define LIBAVCODEC_VERSION_INT  ((51<<16)+(36<<8)+0)
-#define LIBAVCODEC_VERSION      51.36.0
+#define LIBAVCODEC_VERSION_INT  ((51<<16)+(37<<8)+0)
+#define LIBAVCODEC_VERSION      51.37.0
 #define LIBAVCODEC_BUILD        LIBAVCODEC_VERSION_INT
 
 #define LIBAVCODEC_IDENT        "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION)
@@ -385,6 +385,7 @@ typedef struct RcOverride{
 #define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format
 #define CODEC_FLAG2_SKIP_RD       0x00004000 ///< RD optimal MB level residual skiping
 #define CODEC_FLAG2_CHUNKS        0x00008000 ///< input bitstream might be truncated at a packet boundaries instead of only at frame boundaries
+#define CODEC_FLAG2_NON_LINEAR_QUANT 0x00010000 ///< use MPEG-2 non linear quantizer
 
 /* Unsupported options :
  *              Syntax Arithmetic coding (SAC)

Modified: trunk/libavcodec/mpeg12.c
==============================================================================
--- trunk/libavcodec/mpeg12.c	(original)
+++ trunk/libavcodec/mpeg12.c	Sun Mar  4 03:26:20 2007
@@ -419,9 +419,19 @@ void ff_mpeg1_clean_buffers(MpegEncConte
 
 #ifdef CONFIG_ENCODERS
 
+static av_always_inline void put_qscale(MpegEncContext *s)
+{
+    if(s->q_scale_type){
+        assert(s->qscale>=1 && s->qscale <=12);
+        put_bits(&s->pb, 5, inv_non_linear_qscale[s->qscale]);
+    }else{
+        put_bits(&s->pb, 5, s->qscale);
+    }
+}
+
 void ff_mpeg1_encode_slice_header(MpegEncContext *s){
     put_header(s, SLICE_MIN_START_CODE + s->mb_y);
-    put_bits(&s->pb, 5, s->qscale); /* quantizer scale */
+    put_qscale(s);
     put_bits(&s->pb, 1, 0); /* slice extra information */
 }
 
@@ -567,7 +577,7 @@ static av_always_inline void mpeg1_encod
         if (s->pict_type == I_TYPE) {
             if(s->dquant && cbp){
                 put_mb_modes(s, 2, 1, 0, 0); /* macroblock_type : macroblock_quant = 1 */
-                put_bits(&s->pb, 5, s->qscale);
+                put_qscale(s);
             }else{
                 put_mb_modes(s, 1, 1, 0, 0); /* macroblock_type : macroblock_quant = 0 */
                 s->qscale -= s->dquant;
@@ -577,7 +587,7 @@ static av_always_inline void mpeg1_encod
         } else if (s->mb_intra) {
             if(s->dquant && cbp){
                 put_mb_modes(s, 6, 0x01, 0, 0);
-                put_bits(&s->pb, 5, s->qscale);
+                put_qscale(s);
             }else{
                 put_mb_modes(s, 5, 0x03, 0, 0);
                 s->qscale -= s->dquant;
@@ -591,7 +601,7 @@ static av_always_inline void mpeg1_encod
                     if ((motion_x|motion_y) == 0) {
                         if(s->dquant){
                             put_mb_modes(s, 5, 1, 0, 0); /* macroblock_pattern & quant */
-                            put_bits(&s->pb, 5, s->qscale);
+                            put_qscale(s);
                         }else{
                             put_mb_modes(s, 2, 1, 0, 0); /* macroblock_pattern only */
                         }
@@ -599,7 +609,7 @@ static av_always_inline void mpeg1_encod
                     } else {
                         if(s->dquant){
                             put_mb_modes(s, 5, 2, 1, 0); /* motion + cbp */
-                            put_bits(&s->pb, 5, s->qscale);
+                            put_qscale(s);
                         }else{
                             put_mb_modes(s, 1, 1, 1, 0); /* motion + cbp */
                         }
@@ -626,7 +636,7 @@ static av_always_inline void mpeg1_encod
                 if (cbp) {
                     if(s->dquant){
                         put_mb_modes(s, 5, 2, 1, 1); /* motion + cbp */
-                        put_bits(&s->pb, 5, s->qscale);
+                        put_qscale(s);
                     }else{
                         put_mb_modes(s, 1, 1, 1, 1); /* motion + cbp */
                     }
@@ -664,7 +674,7 @@ static av_always_inline void mpeg1_encod
                             put_mb_modes(s, 6, 3, 1, 0);
                         else
                             put_mb_modes(s, mb_type_len[s->mv_dir]+3, 2, 1, 0);
-                        put_bits(&s->pb, 5, s->qscale);
+                        put_qscale(s);
                     } else {
                         put_mb_modes(s, mb_type_len[s->mv_dir], 3, 1, 0);
                     }
@@ -698,7 +708,7 @@ static av_always_inline void mpeg1_encod
                             put_mb_modes(s, 6, 3, 1, 1);
                         else
                             put_mb_modes(s, mb_type_len[s->mv_dir]+3, 2, 1, 1);
-                        put_bits(&s->pb, 5, s->qscale);
+                        put_qscale(s);
                     } else {
                         put_mb_modes(s, mb_type_len[s->mv_dir], 3, 1, 1);
                     }

Modified: trunk/libavcodec/mpeg12data.h
==============================================================================
--- trunk/libavcodec/mpeg12data.h	(original)
+++ trunk/libavcodec/mpeg12data.h	Sun Mar  4 03:26:20 2007
@@ -381,6 +381,11 @@ static const uint8_t non_linear_qscale[3
     56,64,72,80,88,96,104,112,
 };
 
+static const uint8_t inv_non_linear_qscale[13] = {
+    0, 2, 4, 6, 8,
+    9,10,11,12,13,14,15,16,
+};
+
 const uint8_t ff_mpeg1_dc_scale_table[128]={
 //  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
     8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,

Modified: trunk/libavcodec/mpegvideo.c
==============================================================================
--- trunk/libavcodec/mpegvideo.c	(original)
+++ trunk/libavcodec/mpegvideo.c	Sun Mar  4 03:26:20 2007
@@ -1015,6 +1015,7 @@ int MPV_encode_init(AVCodecContext *avct
     s->loop_filter= !!(s->flags & CODEC_FLAG_LOOP_FILTER);
     s->alternate_scan= !!(s->flags & CODEC_FLAG_ALT_SCAN);
     s->intra_vlc_format= !!(s->flags2 & CODEC_FLAG2_INTRA_VLC);
+    s->q_scale_type= !!(s->flags2 & CODEC_FLAG2_NON_LINEAR_QUANT);
 
     if(avctx->rc_max_rate && !avctx->rc_buffer_size){
         av_log(avctx, AV_LOG_ERROR, "a vbv buffer size is needed, for encoding with a maximum bitrate\n");
@@ -1115,6 +1116,17 @@ int MPV_encode_init(AVCodecContext *avct
         }
     }
 
+    if(s->q_scale_type == 1){
+        if(s->codec_id != CODEC_ID_MPEG2VIDEO){
+            av_log(avctx, AV_LOG_ERROR, "non linear quant is only available for mpeg2\n");
+            return -1;
+        }
+        if(avctx->qmax > 12){
+            av_log(avctx, AV_LOG_ERROR, "non linear quant only supports qmax <= 12 currently\n");
+            return -1;
+        }
+    }
+
     if(s->avctx->thread_count > 1 && s->codec_id != CODEC_ID_MPEG4
        && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO
        && (s->codec_id != CODEC_ID_H263P || !(s->flags & CODEC_FLAG_H263P_SLICE_STRUCT))){

Modified: trunk/libavcodec/utils.c
==============================================================================
--- trunk/libavcodec/utils.c	(original)
+++ trunk/libavcodec/utils.c	Sun Mar  4 03:26:20 2007
@@ -718,6 +718,7 @@ static const AVOption options[]={
 {"max_partition_order", NULL, OFFSET(max_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E},
 {"timecode_frame_start", "GOP timecode frame start number, in non drop frame format", OFFSET(timecode_frame_start), FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|E},
 {"drop_frame_timecode", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_DROP_FRAME_TIMECODE, INT_MIN, INT_MAX, V|E, "flags2"},
+{"non_linear_q", "use non linear quantizer", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_NON_LINEAR_QUANT, INT_MIN, INT_MAX, V|E, "flags2"},
 {NULL},
 };
 




More information about the ffmpeg-cvslog mailing list