You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-04 22:03:09 +02:00
avcodec/mpegvideo: Move last-pic information to MPVMainEncContext
last_pict_type, last_non_b_pict_type and last_lambda_for are only used by the encoder's main thread. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@ -185,10 +185,7 @@ typedef struct MpegEncContext {
|
||||
int adaptive_quant; ///< use adaptive quantization
|
||||
int dquant; ///< qscale difference to prev qscale
|
||||
int pict_type; ///< AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
|
||||
int last_pict_type; //FIXME removes
|
||||
int last_non_b_pict_type; ///< used for MPEG-4 gmc B-frames & ratecontrol
|
||||
int droppable;
|
||||
int last_lambda_for[5]; ///< last lambda for a specific pict type
|
||||
int skipdct; ///< skip dct and code zero residual
|
||||
|
||||
/* motion compensation */
|
||||
|
@ -1515,9 +1515,9 @@ static int estimate_best_b_count(MPVMainEncContext *const m)
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
//emms_c();
|
||||
p_lambda = s->last_lambda_for[AV_PICTURE_TYPE_P];
|
||||
p_lambda = m->last_lambda_for[AV_PICTURE_TYPE_P];
|
||||
//p_lambda * FFABS(s->avctx->b_quant_factor) + s->avctx->b_quant_offset;
|
||||
b_lambda = s->last_lambda_for[AV_PICTURE_TYPE_B];
|
||||
b_lambda = m->last_lambda_for[AV_PICTURE_TYPE_B];
|
||||
if (!b_lambda) // FIXME we should do this somewhere else
|
||||
b_lambda = p_lambda;
|
||||
lambda2 = (b_lambda * b_lambda + (1 << FF_LAMBDA_SHIFT) / 2) >>
|
||||
@ -1871,10 +1871,10 @@ static void frame_end(MPVMainEncContext *const m)
|
||||
|
||||
emms_c();
|
||||
|
||||
s->last_pict_type = s->pict_type;
|
||||
s->last_lambda_for [s->pict_type] = s->cur_pic.ptr->f->quality;
|
||||
m->last_pict_type = s->pict_type;
|
||||
m->last_lambda_for[s->pict_type] = s->cur_pic.ptr->f->quality;
|
||||
if (s->pict_type!= AV_PICTURE_TYPE_B)
|
||||
s->last_non_b_pict_type = s->pict_type;
|
||||
m->last_non_b_pict_type = s->pict_type;
|
||||
}
|
||||
|
||||
static void update_noise_reduction(MPVMainEncContext *const m)
|
||||
@ -3702,9 +3702,9 @@ static int encode_picture(MPVMainEncContext *const m, const AVPacket *pkt)
|
||||
ff_get_2pass_fcode(m);
|
||||
} else if (!(s->avctx->flags & AV_CODEC_FLAG_QSCALE)) {
|
||||
if(s->pict_type==AV_PICTURE_TYPE_B)
|
||||
s->lambda= s->last_lambda_for[s->pict_type];
|
||||
s->lambda = m->last_lambda_for[s->pict_type];
|
||||
else
|
||||
s->lambda= s->last_lambda_for[s->last_non_b_pict_type];
|
||||
s->lambda = m->last_lambda_for[m->last_non_b_pict_type];
|
||||
update_qscale(m);
|
||||
}
|
||||
|
||||
@ -3735,7 +3735,7 @@ static int encode_picture(MPVMainEncContext *const m, const AVPacket *pkt)
|
||||
s->lambda = (s->lambda * s->me_penalty_compensation + 128) >> 8;
|
||||
s->lambda2 = (s->lambda2 * (int64_t) s->me_penalty_compensation + 128) >> 8;
|
||||
if (s->pict_type != AV_PICTURE_TYPE_B) {
|
||||
if ((s->me_pre && s->last_non_b_pict_type == AV_PICTURE_TYPE_I) ||
|
||||
if ((s->me_pre && m->last_non_b_pict_type == AV_PICTURE_TYPE_I) ||
|
||||
s->me_pre == 2) {
|
||||
s->avctx->execute(s->avctx, pre_estimate_motion_thread, &s->thread_context[0], NULL, context_count, sizeof(void*));
|
||||
}
|
||||
|
@ -96,6 +96,9 @@ typedef struct MPVMainEncContext {
|
||||
int stuffing_bits; ///< bits used for stuffing
|
||||
int next_lambda; ///< next lambda used for retrying to encode a frame
|
||||
int fixed_qscale; ///< fixed qscale if non zero
|
||||
int last_lambda_for[5]; ///< last lambda for a specific pict type
|
||||
int last_pict_type; //FIXME removes
|
||||
int last_non_b_pict_type; ///< used for MPEG-4 gmc B-frames & ratecontrol
|
||||
RateControlContext rc_context; ///< contains stuff only accessed in ratecontrol.c
|
||||
|
||||
int64_t mb_var_sum; ///< sum of MB variance for current frame
|
||||
|
@ -203,7 +203,7 @@ static void find_best_tables(MSMPEG4EncContext *ms)
|
||||
ms->rl_table_index = best;
|
||||
ms->rl_chroma_table_index = chroma_best;
|
||||
|
||||
if(s->pict_type != s->last_non_b_pict_type){
|
||||
if (s->pict_type != ms->m.last_non_b_pict_type) {
|
||||
ms->rl_table_index= 2;
|
||||
if(s->pict_type==AV_PICTURE_TYPE_I)
|
||||
ms->rl_chroma_table_index = 1;
|
||||
|
@ -940,10 +940,10 @@ float ff_rate_estimate_qscale(MPVMainEncContext *const m, int dry_run)
|
||||
/* update predictors */
|
||||
if (picture_number > 2 && !dry_run) {
|
||||
const int64_t last_var =
|
||||
s->last_pict_type == AV_PICTURE_TYPE_I ? rcc->last_mb_var_sum
|
||||
m->last_pict_type == AV_PICTURE_TYPE_I ? rcc->last_mb_var_sum
|
||||
: rcc->last_mc_mb_var_sum;
|
||||
av_assert1(m->frame_bits >= m->stuffing_bits);
|
||||
update_predictor(&rcc->pred[s->last_pict_type],
|
||||
update_predictor(&rcc->pred[m->last_pict_type],
|
||||
rcc->last_qscale,
|
||||
sqrt(last_var),
|
||||
m->frame_bits - m->stuffing_bits);
|
||||
|
@ -2058,7 +2058,7 @@ redo_frame:
|
||||
}
|
||||
if(avctx->flags&AV_CODEC_FLAG_PASS1)
|
||||
ff_write_pass1_stats(&enc->m);
|
||||
mpv->last_pict_type = mpv->pict_type;
|
||||
enc->m.last_pict_type = mpv->pict_type;
|
||||
|
||||
emms_c();
|
||||
|
||||
|
Reference in New Issue
Block a user