[FFmpeg-cvslog] avcodec/mpegvideo_enc: Factor checks out of loop
Andreas Rheinhardt
git at videolan.org
Fri Mar 7 16:21:52 EET 2025
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at 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.polla at gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at 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) {
More information about the ffmpeg-cvslog
mailing list