summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libavcodec/avcodec.h5
-rw-r--r--libavcodec/mpeg12.c26
-rw-r--r--libavcodec/mpeg12data.h5
-rw-r--r--libavcodec/mpegvideo.c12
-rw-r--r--libavcodec/utils.c1
5 files changed, 39 insertions, 10 deletions
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 21c3f57251..836307ae71 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -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)
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 0b7cb47e80..033b9803fd 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -419,9 +419,19 @@ void ff_mpeg1_clean_buffers(MpegEncContext *s){
#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_encode_mb_internal(MpegEncContext *s,
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_encode_mb_internal(MpegEncContext *s,
} 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_encode_mb_internal(MpegEncContext *s,
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_encode_mb_internal(MpegEncContext *s,
} 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_encode_mb_internal(MpegEncContext *s,
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_encode_mb_internal(MpegEncContext *s,
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_encode_mb_internal(MpegEncContext *s,
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);
}
diff --git a/libavcodec/mpeg12data.h b/libavcodec/mpeg12data.h
index 6c96a495b6..1176a75fa7 100644
--- a/libavcodec/mpeg12data.h
+++ b/libavcodec/mpeg12data.h
@@ -381,6 +381,11 @@ static const uint8_t non_linear_qscale[32] = {
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,
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 89e333a040..9d7a0a70cc 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -1015,6 +1015,7 @@ int MPV_encode_init(AVCodecContext *avctx)
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 *avctx)
}
}
+ 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))){
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index a42219f917..3ab6bd8916 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -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},
};