#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)
#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)
#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 */
}
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;
} 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;
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 */
}
} 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 */
}
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 */
}
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);
}
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);
}
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,
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");
}
}
+ 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))){
{"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},
};