Commit f9c2f5c7 authored by bcoudurier's avatar bcoudurier

dummy support for mpeg2 non linear quant

git-svn-id: file:///var/local/repositories/ffmpeg/trunk@8215 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent ebcc4688
...@@ -37,8 +37,8 @@ extern "C" { ...@@ -37,8 +37,8 @@ extern "C" {
#define AV_STRINGIFY(s) AV_TOSTRING(s) #define AV_STRINGIFY(s) AV_TOSTRING(s)
#define AV_TOSTRING(s) #s #define AV_TOSTRING(s) #s
#define LIBAVCODEC_VERSION_INT ((51<<16)+(36<<8)+0) #define LIBAVCODEC_VERSION_INT ((51<<16)+(37<<8)+0)
#define LIBAVCODEC_VERSION 51.36.0 #define LIBAVCODEC_VERSION 51.37.0
#define LIBAVCODEC_BUILD LIBAVCODEC_VERSION_INT #define LIBAVCODEC_BUILD LIBAVCODEC_VERSION_INT
#define LIBAVCODEC_IDENT "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION) #define LIBAVCODEC_IDENT "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION)
...@@ -385,6 +385,7 @@ typedef struct RcOverride{ ...@@ -385,6 +385,7 @@ typedef struct RcOverride{
#define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format #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_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_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 : /* Unsupported options :
* Syntax Arithmetic coding (SAC) * Syntax Arithmetic coding (SAC)
......
...@@ -419,9 +419,19 @@ void ff_mpeg1_clean_buffers(MpegEncContext *s){ ...@@ -419,9 +419,19 @@ void ff_mpeg1_clean_buffers(MpegEncContext *s){
#ifdef CONFIG_ENCODERS #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){ void ff_mpeg1_encode_slice_header(MpegEncContext *s){
put_header(s, SLICE_MIN_START_CODE + s->mb_y); 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 */ put_bits(&s->pb, 1, 0); /* slice extra information */
} }
...@@ -567,7 +577,7 @@ static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s, ...@@ -567,7 +577,7 @@ static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s,
if (s->pict_type == I_TYPE) { if (s->pict_type == I_TYPE) {
if(s->dquant && cbp){ if(s->dquant && cbp){
put_mb_modes(s, 2, 1, 0, 0); /* macroblock_type : macroblock_quant = 1 */ put_mb_modes(s, 2, 1, 0, 0); /* macroblock_type : macroblock_quant = 1 */
put_bits(&s->pb, 5, s->qscale); put_qscale(s);
}else{ }else{
put_mb_modes(s, 1, 1, 0, 0); /* macroblock_type : macroblock_quant = 0 */ put_mb_modes(s, 1, 1, 0, 0); /* macroblock_type : macroblock_quant = 0 */
s->qscale -= s->dquant; s->qscale -= s->dquant;
...@@ -577,7 +587,7 @@ static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s, ...@@ -577,7 +587,7 @@ static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s,
} else if (s->mb_intra) { } else if (s->mb_intra) {
if(s->dquant && cbp){ if(s->dquant && cbp){
put_mb_modes(s, 6, 0x01, 0, 0); put_mb_modes(s, 6, 0x01, 0, 0);
put_bits(&s->pb, 5, s->qscale); put_qscale(s);
}else{ }else{
put_mb_modes(s, 5, 0x03, 0, 0); put_mb_modes(s, 5, 0x03, 0, 0);
s->qscale -= s->dquant; s->qscale -= s->dquant;
...@@ -591,7 +601,7 @@ static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s, ...@@ -591,7 +601,7 @@ static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s,
if ((motion_x|motion_y) == 0) { if ((motion_x|motion_y) == 0) {
if(s->dquant){ if(s->dquant){
put_mb_modes(s, 5, 1, 0, 0); /* macroblock_pattern & quant */ put_mb_modes(s, 5, 1, 0, 0); /* macroblock_pattern & quant */
put_bits(&s->pb, 5, s->qscale); put_qscale(s);
}else{ }else{
put_mb_modes(s, 2, 1, 0, 0); /* macroblock_pattern only */ 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, ...@@ -599,7 +609,7 @@ static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s,
} else { } else {
if(s->dquant){ if(s->dquant){
put_mb_modes(s, 5, 2, 1, 0); /* motion + cbp */ put_mb_modes(s, 5, 2, 1, 0); /* motion + cbp */
put_bits(&s->pb, 5, s->qscale); put_qscale(s);
}else{ }else{
put_mb_modes(s, 1, 1, 1, 0); /* motion + cbp */ 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, ...@@ -626,7 +636,7 @@ static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s,
if (cbp) { if (cbp) {
if(s->dquant){ if(s->dquant){
put_mb_modes(s, 5, 2, 1, 1); /* motion + cbp */ put_mb_modes(s, 5, 2, 1, 1); /* motion + cbp */
put_bits(&s->pb, 5, s->qscale); put_qscale(s);
}else{ }else{
put_mb_modes(s, 1, 1, 1, 1); /* motion + cbp */ 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, ...@@ -664,7 +674,7 @@ static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s,
put_mb_modes(s, 6, 3, 1, 0); put_mb_modes(s, 6, 3, 1, 0);
else else
put_mb_modes(s, mb_type_len[s->mv_dir]+3, 2, 1, 0); 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 { } else {
put_mb_modes(s, mb_type_len[s->mv_dir], 3, 1, 0); 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, ...@@ -698,7 +708,7 @@ static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s,
put_mb_modes(s, 6, 3, 1, 1); put_mb_modes(s, 6, 3, 1, 1);
else else
put_mb_modes(s, mb_type_len[s->mv_dir]+3, 2, 1, 1); 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 { } else {
put_mb_modes(s, mb_type_len[s->mv_dir], 3, 1, 1); put_mb_modes(s, mb_type_len[s->mv_dir], 3, 1, 1);
} }
......
...@@ -381,6 +381,11 @@ static const uint8_t non_linear_qscale[32] = { ...@@ -381,6 +381,11 @@ static const uint8_t non_linear_qscale[32] = {
56,64,72,80,88,96,104,112, 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]={ 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 // 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, 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,
......
...@@ -1015,6 +1015,7 @@ int MPV_encode_init(AVCodecContext *avctx) ...@@ -1015,6 +1015,7 @@ int MPV_encode_init(AVCodecContext *avctx)
s->loop_filter= !!(s->flags & CODEC_FLAG_LOOP_FILTER); s->loop_filter= !!(s->flags & CODEC_FLAG_LOOP_FILTER);
s->alternate_scan= !!(s->flags & CODEC_FLAG_ALT_SCAN); s->alternate_scan= !!(s->flags & CODEC_FLAG_ALT_SCAN);
s->intra_vlc_format= !!(s->flags2 & CODEC_FLAG2_INTRA_VLC); 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){ 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"); 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) ...@@ -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 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_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO
&& (s->codec_id != CODEC_ID_H263P || !(s->flags & CODEC_FLAG_H263P_SLICE_STRUCT))){ && (s->codec_id != CODEC_ID_H263P || !(s->flags & CODEC_FLAG_H263P_SLICE_STRUCT))){
......
...@@ -718,6 +718,7 @@ static const AVOption options[]={ ...@@ -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}, {"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}, {"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"}, {"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}, {NULL},
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment