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: Only allocate chroma intra matrices when needed
Also start factoring the matrix-init code out into a function of its own to declutter ff_mpv_encode_init(). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@ -348,6 +348,20 @@ static av_cold int me_cmp_init(MpegEncContext *s, AVCodecContext *avctx)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static av_cold int init_matrices(MpegEncContext *s, AVCodecContext *avctx)
|
||||||
|
{
|
||||||
|
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))
|
||||||
|
return AVERROR(ENOMEM);
|
||||||
|
} else {
|
||||||
|
s->q_chroma_intra_matrix = s->q_intra_matrix;
|
||||||
|
s->q_chroma_intra_matrix16 = s->q_intra_matrix16;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* init video encoder */
|
/* init video encoder */
|
||||||
av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
|
av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
|
||||||
{
|
{
|
||||||
@ -866,10 +880,8 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
|
|||||||
|
|
||||||
if (!(avctx->stats_out = av_mallocz(256)) ||
|
if (!(avctx->stats_out = av_mallocz(256)) ||
|
||||||
!FF_ALLOCZ_TYPED_ARRAY(s->q_intra_matrix, 32) ||
|
!FF_ALLOCZ_TYPED_ARRAY(s->q_intra_matrix, 32) ||
|
||||||
!FF_ALLOCZ_TYPED_ARRAY(s->q_chroma_intra_matrix, 32) ||
|
|
||||||
!FF_ALLOCZ_TYPED_ARRAY(s->q_inter_matrix, 32) ||
|
!FF_ALLOCZ_TYPED_ARRAY(s->q_inter_matrix, 32) ||
|
||||||
!FF_ALLOCZ_TYPED_ARRAY(s->q_intra_matrix16, 32) ||
|
!FF_ALLOCZ_TYPED_ARRAY(s->q_intra_matrix16, 32) ||
|
||||||
!FF_ALLOCZ_TYPED_ARRAY(s->q_chroma_intra_matrix16, 32) ||
|
|
||||||
!FF_ALLOCZ_TYPED_ARRAY(s->q_inter_matrix16, 32) ||
|
!FF_ALLOCZ_TYPED_ARRAY(s->q_inter_matrix16, 32) ||
|
||||||
!FF_ALLOCZ_TYPED_ARRAY(s->input_picture, MAX_B_FRAMES + 1) ||
|
!FF_ALLOCZ_TYPED_ARRAY(s->input_picture, MAX_B_FRAMES + 1) ||
|
||||||
!FF_ALLOCZ_TYPED_ARRAY(s->reordered_input_picture, MAX_B_FRAMES + 1) ||
|
!FF_ALLOCZ_TYPED_ARRAY(s->reordered_input_picture, MAX_B_FRAMES + 1) ||
|
||||||
@ -877,6 +889,10 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx)
|
|||||||
!(s->picture_pool = ff_mpv_alloc_pic_pool(0)))
|
!(s->picture_pool = ff_mpv_alloc_pic_pool(0)))
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
|
ret = init_matrices(s, avctx);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
/* Allocate MV tables; the MV and MB tables will be copied
|
/* Allocate MV tables; the MV and MB tables will be copied
|
||||||
* to slice contexts by ff_update_duplicate_context(). */
|
* to slice contexts by ff_update_duplicate_context(). */
|
||||||
mv_table_size = (s->mb_height + 2) * s->mb_stride + 1;
|
mv_table_size = (s->mb_height + 2) * s->mb_stride + 1;
|
||||||
@ -3700,13 +3716,6 @@ static int encode_picture(MpegEncContext *s, const AVPacket *pkt)
|
|||||||
update_qscale(s);
|
update_qscale(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->out_format != FMT_MJPEG) {
|
|
||||||
if(s->q_chroma_intra_matrix != s->q_intra_matrix ) av_freep(&s->q_chroma_intra_matrix);
|
|
||||||
if(s->q_chroma_intra_matrix16 != s->q_intra_matrix16) av_freep(&s->q_chroma_intra_matrix16);
|
|
||||||
s->q_chroma_intra_matrix = s->q_intra_matrix;
|
|
||||||
s->q_chroma_intra_matrix16 = s->q_intra_matrix16;
|
|
||||||
}
|
|
||||||
|
|
||||||
ff_me_init_pic(s);
|
ff_me_init_pic(s);
|
||||||
|
|
||||||
s->mb_intra=0; //for the rate distortion & bit compare functions
|
s->mb_intra=0; //for the rate distortion & bit compare functions
|
||||||
|
Reference in New Issue
Block a user