You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-04 22:03:09 +02:00
avcodec/mpegvideo_enc: Factor checks out of loop
Also move this code to init_matrices(). Reviewed-by: Ramiro Polla <ramiro.polla@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@ -350,6 +350,8 @@ static av_cold int me_cmp_init(MpegEncContext *s, AVCodecContext *avctx)
|
||||
|
||||
static av_cold int init_matrices(MpegEncContext *s, AVCodecContext *avctx)
|
||||
{
|
||||
const uint16_t *intra_matrix, *inter_matrix;
|
||||
|
||||
if (s->out_format == FMT_MJPEG) {
|
||||
if (!FF_ALLOCZ_TYPED_ARRAY(s->q_chroma_intra_matrix, 32) ||
|
||||
!FF_ALLOCZ_TYPED_ARRAY(s->q_chroma_intra_matrix16, 32))
|
||||
@ -359,6 +361,31 @@ static av_cold int init_matrices(MpegEncContext *s, AVCodecContext *avctx)
|
||||
s->q_chroma_intra_matrix16 = s->q_intra_matrix16;
|
||||
}
|
||||
|
||||
if (CONFIG_MPEG4_ENCODER && s->codec_id == AV_CODEC_ID_MPEG4 &&
|
||||
s->mpeg_quant) {
|
||||
intra_matrix = ff_mpeg4_default_intra_matrix;
|
||||
inter_matrix = ff_mpeg4_default_non_intra_matrix;
|
||||
} else if (s->out_format == FMT_H263 || s->out_format == FMT_H261) {
|
||||
intra_matrix =
|
||||
inter_matrix = ff_mpeg1_default_non_intra_matrix;
|
||||
} else {
|
||||
/* MPEG-1/2, SpeedHQ */
|
||||
intra_matrix = ff_mpeg1_default_intra_matrix;
|
||||
inter_matrix = ff_mpeg1_default_non_intra_matrix;
|
||||
}
|
||||
if (avctx->intra_matrix)
|
||||
intra_matrix = avctx->intra_matrix;
|
||||
if (avctx->inter_matrix)
|
||||
inter_matrix = avctx->inter_matrix;
|
||||
|
||||
/* init q matrix */
|
||||
for (int i = 0; i < 64; i++) {
|
||||
int j = s->idsp.idct_permutation[i];
|
||||
|
||||
s->intra_matrix[j] = s->chroma_intra_matrix[j] = intra_matrix[i];
|
||||
s->inter_matrix[j] = inter_matrix[i];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -982,28 +1009,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* init q matrix */
|
||||
for (i = 0; i < 64; i++) {
|
||||
int j = s->idsp.idct_permutation[i];
|
||||
if (CONFIG_MPEG4_ENCODER && s->codec_id == AV_CODEC_ID_MPEG4 &&
|
||||
s->mpeg_quant) {
|
||||
s->intra_matrix[j] = ff_mpeg4_default_intra_matrix[i];
|
||||
s->inter_matrix[j] = ff_mpeg4_default_non_intra_matrix[i];
|
||||
} else if (s->out_format == FMT_H263 || s->out_format == FMT_H261) {
|
||||
s->intra_matrix[j] =
|
||||
s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i];
|
||||
} else {
|
||||
/* MPEG-1/2, SpeedHQ */
|
||||
s->chroma_intra_matrix[j] =
|
||||
s->intra_matrix[j] = ff_mpeg1_default_intra_matrix[i];
|
||||
s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i];
|
||||
}
|
||||
if (avctx->intra_matrix)
|
||||
s->intra_matrix[j] = avctx->intra_matrix[i];
|
||||
if (avctx->inter_matrix)
|
||||
s->inter_matrix[j] = avctx->inter_matrix[i];
|
||||
}
|
||||
|
||||
/* precompute matrix */
|
||||
/* for mjpeg, we do include qscale in the matrix */
|
||||
if (s->out_format != FMT_MJPEG) {
|
||||
|
Reference in New Issue
Block a user