ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinha...@outlook.com> | Thu Feb 27 22:01:12 2025 +0100| [a43124452f8c2ca6d00f3bf61c83fac4cd487a2e] | committer: Andreas Rheinhardt
avcodec/mpegvideo_enc: Factor checks out of loop Also move this code to init_matrices(). Reviewed-by: Ramiro Polla <ramiro.po...@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinha...@outlook.com> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a43124452f8c2ca6d00f3bf61c83fac4cd487a2e --- libavcodec/mpegvideo_enc.c | 49 +++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 11ebbe6a30..aab82248e0 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -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) { _______________________________________________ ffmpeg-cvslog mailing list ffmpeg-cvslog@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog To unsubscribe, visit link above, or email ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".