#include <float.h>
#include "avcodec.h"
+#include "internal.h"
#include "bytestream.h"
#include "j2k.h"
#include "libavutil/common.h"
}
}
-static int encode_frame(AVCodecContext *avctx,
- uint8_t *buf, int buf_size,
- void *data)
+static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
+ const AVFrame *pict, int *got_packet)
{
int tileno, ret;
J2kEncoderContext *s = avctx->priv_data;
+ if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width*avctx->height*9 + FF_MIN_BUFFER_SIZE)) < 0) {
+ return ret;
+ }
+
// init:
- s->buf = s->buf_start = buf;
- s->buf_end = buf + buf_size;
+ s->buf = s->buf_start = pkt->data;
+ s->buf_end = pkt->data + pkt->size;
- s->picture = *(AVFrame*)data;
+ s->picture = *pict;
avctx->coded_frame= &s->picture;
s->lambda = s->picture.quality * LAMBDA_SCALE;
bytestream_put_be16(&s->buf, J2K_EOC);
av_log(s->avctx, AV_LOG_DEBUG, "end\n");
- return s->buf - s->buf_start;
+ pkt->size = s->buf - s->buf_start;
+ pkt->flags |= AV_PKT_FLAG_KEY;
+ *got_packet = 1;
+
+ return 0;
}
static av_cold int j2kenc_init(AVCodecContext *avctx)
.id = CODEC_ID_JPEG2000,
.priv_data_size = sizeof(J2kEncoderContext),
.init = j2kenc_init,
- .encode = encode_frame,
+ .encode2 = encode_frame,
.close = j2kenc_destroy,
.capabilities= CODEC_CAP_EXPERIMENTAL,
.long_name = NULL_IF_CONFIG_SMALL("JPEG 2000"),