aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/mpegvideo_enc.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-03-01 01:13:16 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-03-01 03:17:11 +0100
commit79ae084e9b930f8b53ae0499c6a06636d194574d (patch)
treee7d829e566b01ef7e84a12b06a2bcb87a8164059 /libavcodec/mpegvideo_enc.c
parenta77c8ade2ee20fc6149e4c689a3f196f53e85273 (diff)
parent882abda5a26ffb8e3d1c5852dfa7cdad0a291d2d (diff)
downloadffmpeg-79ae084e9b930f8b53ae0499c6a06636d194574d.tar.gz
Merge remote-tracking branch 'qatar/master'
* qatar/master: (58 commits) amrnbdec: check frame size before decoding. cscd: use negative error values to indicate decode_init() failures. h264: prevent overreads in intra PCM decoding. FATE: do not decode audio in the nuv test. dxa: set audio stream time base using the sample rate psx-str: do not allow seeking by bytes asfdec: Do not set AVCodecContext.frame_size vqf: set packet parameters after av_new_packet() mpegaudiodec: use DSPUtil.butterflies_float(). FATE: add mp3 test for sample that exhibited false overreads fate: add cdxl test for bit line plane arrangement vmnc: return error on decode_init() failure. libvorbis: add/update error messages libvorbis: use AVFifoBuffer for output packet buffer libvorbis: remove unneeded e_o_s check libvorbis: check return values for functions that can return errors libvorbis: use float input instead of s16 libvorbis: do not flush libvorbis analysis if dsp state was not initialized libvorbis: use VBR by default, with default quality of 3 libvorbis: fix use of minrate/maxrate AVOptions ... Conflicts: Changelog doc/APIchanges libavcodec/avcodec.h libavcodec/dpxenc.c libavcodec/libvorbis.c libavcodec/vmnc.c libavformat/asfdec.c libavformat/id3v2enc.c libavformat/internal.h libavformat/mp3enc.c libavformat/utils.c libavformat/version.h libswscale/utils.c tests/fate/video.mak tests/ref/fate/nuv tests/ref/fate/prores-alpha tests/ref/lavf/ffm tests/ref/vsynth1/prores tests/ref/vsynth2/prores Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/mpegvideo_enc.c')
-rw-r--r--libavcodec/mpegvideo_enc.c73
1 files changed, 56 insertions, 17 deletions
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 0441d8fa35..c780ffb598 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -63,6 +63,11 @@ static int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int
static uint8_t default_mv_penalty[MAX_FCODE + 1][MAX_MV * 2 + 1];
static uint8_t default_fcode_tab[MAX_MV * 2 + 1];
+const AVOption ff_mpv_generic_options[] = {
+ FF_MPV_COMMON_OPTS
+ { NULL },
+};
+
void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64],
uint16_t (*qmat16)[2][64],
const uint16_t *quant_matrix,
@@ -352,8 +357,12 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx)
s->flags2 = avctx->flags2;
s->max_b_frames = avctx->max_b_frames;
s->codec_id = avctx->codec->id;
- s->luma_elim_threshold = avctx->luma_elim_threshold;
- s->chroma_elim_threshold = avctx->chroma_elim_threshold;
+#if FF_API_MPV_GLOBAL_OPTS
+ if (avctx->luma_elim_threshold)
+ s->luma_elim_threshold = avctx->luma_elim_threshold;
+ if (avctx->chroma_elim_threshold)
+ s->chroma_elim_threshold = avctx->chroma_elim_threshold;
+#endif
s->strict_std_compliance = avctx->strict_std_compliance;
s->quarter_sample = (avctx->flags & CODEC_FLAG_QPEL) != 0;
s->mpeg_quant = avctx->mpeg_quant;
@@ -373,13 +382,18 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx)
/* Fixed QSCALE */
s->fixed_qscale = !!(avctx->flags & CODEC_FLAG_QSCALE);
+#if FF_API_MPV_GLOBAL_OPTS
+ if (s->flags & CODEC_FLAG_QP_RD)
+ s->mpv_flags |= FF_MPV_FLAG_QP_RD;
+#endif
+
s->adaptive_quant = (s->avctx->lumi_masking ||
s->avctx->dark_masking ||
s->avctx->temporal_cplx_masking ||
s->avctx->spatial_cplx_masking ||
s->avctx->p_masking ||
s->avctx->border_masking ||
- (s->flags & CODEC_FLAG_QP_RD)) &&
+ (s->mpv_flags & FF_MPV_FLAG_QP_RD)) &&
!s->fixed_qscale;
s->loop_filter = !!(s->flags & CODEC_FLAG_LOOP_FILTER);
@@ -488,12 +502,17 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx)
return -1;
}
- if ((s->flags & CODEC_FLAG_CBP_RD) && !avctx->trellis) {
+#if FF_API_MPV_GLOBAL_OPTS
+ if (s->flags & CODEC_FLAG_CBP_RD)
+ s->mpv_flags |= FF_MPV_FLAG_CBP_RD;
+#endif
+
+ if ((s->mpv_flags & FF_MPV_FLAG_CBP_RD) && !avctx->trellis) {
av_log(avctx, AV_LOG_ERROR, "CBP RD needs trellis quant\n");
return -1;
}
- if ((s->flags & CODEC_FLAG_QP_RD) &&
+ if ((s->mpv_flags & FF_MPV_FLAG_QP_RD) &&
s->avctx->mb_decision != FF_MB_DECISION_RD) {
av_log(avctx, AV_LOG_ERROR, "QP RD needs mbd=2\n");
return -1;
@@ -610,6 +629,15 @@ av_cold int ff_MPV_encode_init(AVCodecContext *avctx)
}
s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1;
+#if FF_API_MPV_GLOBAL_OPTS
+ if (avctx->flags2 & CODEC_FLAG2_SKIP_RD)
+ s->mpv_flags |= FF_MPV_FLAG_SKIP_RD;
+ if (avctx->flags2 & CODEC_FLAG2_STRICT_GOP)
+ s->mpv_flags |= FF_MPV_FLAG_STRICT_GOP;
+ if (avctx->quantizer_noise_shaping)
+ s->quantizer_noise_shaping = avctx->quantizer_noise_shaping;
+#endif
+
switch (avctx->codec->id) {
case CODEC_ID_MPEG1VIDEO:
s->out_format = FMT_MPEG1;
@@ -1301,7 +1329,7 @@ static int select_input_picture(MpegEncContext *s)
}
if (s->picture_in_gop_number + b_frames >= s->gop_size) {
- if ((s->flags2 & CODEC_FLAG2_STRICT_GOP) &&
+ if ((s->mpv_flags & FF_MPV_FLAG_STRICT_GOP) &&
s->gop_size > s->picture_in_gop_number) {
b_frames = s->gop_size - s->picture_in_gop_number - 1;
} else {
@@ -1726,7 +1754,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
s->lambda = s->lambda_table[mb_xy];
update_qscale(s);
- if (!(s->flags & CODEC_FLAG_QP_RD)) {
+ if (!(s->mpv_flags & FF_MPV_FLAG_QP_RD)) {
s->qscale = s->current_picture_ptr->f.qscale_table[mb_xy];
s->dquant = s->qscale - last_qp;
@@ -1746,7 +1774,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
}
}
ff_set_qscale(s, last_qp + s->dquant);
- } else if (s->flags & CODEC_FLAG_QP_RD)
+ } else if (s->mpv_flags & FF_MPV_FLAG_QP_RD)
ff_set_qscale(s, s->qscale + s->dquant);
wrap_y = s->linesize;
@@ -1934,7 +1962,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
}
}
- if (s->avctx->quantizer_noise_shaping) {
+ if (s->quantizer_noise_shaping) {
if (!skip_dct[0])
get_visual_weight(weight[0], ptr_y , wrap_y);
if (!skip_dct[1])
@@ -1975,7 +2003,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
} else
s->block_last_index[i] = -1;
}
- if (s->avctx->quantizer_noise_shaping) {
+ if (s->quantizer_noise_shaping) {
for (i = 0; i < mb_block_count; i++) {
if (!skip_dct[i]) {
s->block_last_index[i] =
@@ -1992,7 +2020,7 @@ static av_always_inline void encode_mb_internal(MpegEncContext *s,
for (i = 4; i < mb_block_count; i++)
dct_single_coeff_elimination(s, i, s->chroma_elim_threshold);
- if (s->flags & CODEC_FLAG_CBP_RD) {
+ if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) {
for (i = 0; i < mb_block_count; i++) {
if (s->block_last_index[i] == -1)
s->coded_score[i] = INT_MAX / 256;
@@ -2513,7 +2541,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
s->mb_skipped=0;
s->dquant=0; //only for QP_RD
- if(mb_type & (mb_type-1) || (s->flags & CODEC_FLAG_QP_RD)){ // more than 1 MB type possible or CODEC_FLAG_QP_RD
+ if (mb_type & (mb_type-1) || (s->mpv_flags & FF_MPV_FLAG_QP_RD)) { // more than 1 MB type possible or FF_MPV_FLAG_QP_RD
int next_block=0;
int pb_bits_count, pb2_bits_count, tex_pb_bits_count;
@@ -2650,7 +2678,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
}
}
- if((s->flags & CODEC_FLAG_QP_RD) && dmin < INT_MAX){
+ if ((s->mpv_flags & FF_MPV_FLAG_QP_RD) && dmin < INT_MAX) {
if(best_s.mv_type==MV_TYPE_16X16){ //FIXME move 4mv after QPRD
const int last_qp= backup_s.qscale;
int qpi, qp, dc[6];
@@ -2715,7 +2743,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb,
&dmin, &next_block, 0, 0);
}
- if(!best_s.mb_intra && s->flags2&CODEC_FLAG2_SKIP_RD){
+ if (!best_s.mb_intra && s->mpv_flags & FF_MPV_FLAG_SKIP_RD) {
int coded=0;
for(i=0; i<6; i++)
coded |= s->block_last_index[i];
@@ -3755,7 +3783,7 @@ STOP_TIMER("init rem[]")
#ifdef REFINE_STATS
{START_TIMER
#endif
- analyze_gradient = last_non_zero > 2 || s->avctx->quantizer_noise_shaping >= 3;
+ analyze_gradient = last_non_zero > 2 || s->quantizer_noise_shaping >= 3;
if(analyze_gradient){
#ifdef REFINE_STATS
@@ -3813,7 +3841,7 @@ STOP_TIMER("dct")}
const int level= block[j];
int change, old_coeff;
- if(s->avctx->quantizer_noise_shaping < 3 && i > last_non_zero + 1)
+ if(s->quantizer_noise_shaping < 3 && i > last_non_zero + 1)
break;
if(level){
@@ -3831,7 +3859,7 @@ STOP_TIMER("dct")}
int score, new_coeff, unquant_change;
score=0;
- if(s->avctx->quantizer_noise_shaping < 2 && FFABS(new_level) > FFABS(level))
+ if(s->quantizer_noise_shaping < 2 && FFABS(new_level) > FFABS(level))
continue;
if(new_level){
@@ -4089,6 +4117,7 @@ int ff_dct_quantize_c(MpegEncContext *s,
static const AVOption h263_options[] = {
{ "obmc", "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
{ "structured_slices","Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE},
+ FF_MPV_COMMON_OPTS
{ NULL },
};
@@ -4117,6 +4146,7 @@ static const AVOption h263p_options[] = {
{ "aiv", "Use alternative inter VLC.", OFFSET(alt_inter_vlc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
{ "obmc", "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },
{ "structured_slices", "Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE},
+ FF_MPV_COMMON_OPTS
{ NULL },
};
static const AVClass h263p_class = {
@@ -4140,6 +4170,8 @@ AVCodec ff_h263p_encoder = {
.priv_class = &h263p_class,
};
+FF_MPV_GENERIC_CLASS(msmpeg4v2)
+
AVCodec ff_msmpeg4v2_encoder = {
.name = "msmpeg4v2",
.type = AVMEDIA_TYPE_VIDEO,
@@ -4150,8 +4182,11 @@ AVCodec ff_msmpeg4v2_encoder = {
.close = ff_MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"),
+ .priv_class = &msmpeg4v2_class,
};
+FF_MPV_GENERIC_CLASS(msmpeg4v3)
+
AVCodec ff_msmpeg4v3_encoder = {
.name = "msmpeg4",
.type = AVMEDIA_TYPE_VIDEO,
@@ -4162,8 +4197,11 @@ AVCodec ff_msmpeg4v3_encoder = {
.close = ff_MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"),
+ .priv_class = &msmpeg4v3_class,
};
+FF_MPV_GENERIC_CLASS(wmv1)
+
AVCodec ff_wmv1_encoder = {
.name = "wmv1",
.type = AVMEDIA_TYPE_VIDEO,
@@ -4174,4 +4212,5 @@ AVCodec ff_wmv1_encoder = {
.close = ff_MPV_encode_end,
.pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE},
.long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 7"),
+ .priv_class = &wmv1_class,
};