[FFmpeg-devel] [PATCH 1/3] avcodec/j2kenc: reinitialize state if frame size changes
Aman Gupta
ffmpeg at tmm1.net
Sat Nov 18 02:36:46 EET 2017
From: Aman Gupta <aman at tmm1.net>
---
libavcodec/j2kenc.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/libavcodec/j2kenc.c b/libavcodec/j2kenc.c
index 2135ece540..1eb091af3b 100644
--- a/libavcodec/j2kenc.c
+++ b/libavcodec/j2kenc.c
@@ -995,7 +995,15 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
Jpeg2000EncoderContext *s = avctx->priv_data;
uint8_t *chunkstart, *jp2cstart, *jp2hstart;
- if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width*avctx->height*9 + AV_INPUT_BUFFER_MIN_SIZE, 0)) < 0)
+ if (pict->height != s->height || pict->width != s->width) {
+ s->height = pict->height;
+ s->width = pict->width;
+ cleanup(s);
+ if ((ret=init_tiles(s)) < 0)
+ return ret;
+ }
+
+ if ((ret = ff_alloc_packet2(avctx, pkt, s->width*s->height*9 + AV_INPUT_BUFFER_MIN_SIZE, 0)) < 0)
return ret;
// init:
@@ -1031,8 +1039,8 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
chunkstart = s->buf;
bytestream_put_be32(&s->buf, 0);
bytestream_put_buffer(&s->buf, "ihdr", 4);
- bytestream_put_be32(&s->buf, avctx->height);
- bytestream_put_be32(&s->buf, avctx->width);
+ bytestream_put_be32(&s->buf, s->height);
+ bytestream_put_be32(&s->buf, s->width);
bytestream_put_be16(&s->buf, s->ncomponents);
bytestream_put_byte(&s->buf, s->cbps[0]);
bytestream_put_byte(&s->buf, 7);
--
2.14.2
More information about the ffmpeg-devel
mailing list