diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index 366de02ac8..d2324fa41b 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -1080,17 +1080,25 @@ static int encode_slice(AVCodecContext *c, void *arg){ return 0; } -static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ +static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, + const AVFrame *pict, int *got_packet) +{ FFV1Context *f = avctx->priv_data; RangeCoder * const c= &f->slice_context[0]->c; - AVFrame *pict = data; AVFrame * const p= &f->picture; int used_count= 0; uint8_t keystate=128; uint8_t *buf_p; - int i; + int i, ret; - ff_init_range_encoder(c, buf, buf_size); + if (!pkt->data && + (ret = av_new_packet(pkt, avctx->width*avctx->height*((8*2+1+1)*4)/8 + + FF_MIN_BUFFER_SIZE)) < 0) { + av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n"); + return ret; + } + + ff_init_range_encoder(c, pkt->data, pkt->size); ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); *p = *pict; @@ -1110,7 +1118,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, if(!f->ac){ used_count += ff_rac_terminate(c); //printf("pos=%d\n", used_count); - init_put_bits(&f->slice_context[0]->pb, buf + used_count, buf_size - used_count); + init_put_bits(&f->slice_context[0]->pb, pkt->data + used_count, pkt->size - used_count); }else if (f->ac>1){ int i; for(i=1; i<256; i++){ @@ -1121,8 +1129,8 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, for(i=1; islice_count; i++){ FFV1Context *fs= f->slice_context[i]; - uint8_t *start= buf + (buf_size-used_count)*i/f->slice_count; - int len= buf_size/f->slice_count; + uint8_t *start = pkt->data + (pkt->size-used_count)*i/f->slice_count; + int len = pkt->size/f->slice_count; if(fs->ac){ ff_init_range_encoder(&fs->c, start, len); @@ -1132,7 +1140,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, } avctx->execute(avctx, encode_slice, &f->slice_context[0], NULL, f->slice_count, sizeof(void*)); - buf_p=buf; + buf_p = pkt->data; for(i=0; islice_count; i++){ FFV1Context *fs= f->slice_context[i]; int bytes; @@ -1147,7 +1155,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, used_count= 0; } if(i>0){ - av_assert0(bytes < buf_size/f->slice_count); + av_assert0(bytes < pkt->size/f->slice_count); memmove(buf_p, fs->ac ? fs->c.bytestream_start : fs->pb.buf, bytes); av_assert0(bytes < (1<<24)); AV_WB24(buf_p+bytes, bytes); @@ -1200,7 +1208,11 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, avctx->stats_out[0] = '\0'; f->picture_number++; - return buf_p-buf; + pkt->size = buf_p - pkt->data; + pkt->flags |= AV_PKT_FLAG_KEY*p->key_frame; + *got_packet = 1; + + return 0; } #endif /* CONFIG_FFV1_ENCODER */ @@ -1742,7 +1754,7 @@ AVCodec ff_ffv1_encoder = { .id = CODEC_ID_FFV1, .priv_data_size = sizeof(FFV1Context), .init = encode_init, - .encode = encode_frame, + .encode2 = encode_frame, .close = common_end, .capabilities = CODEC_CAP_SLICE_THREADS, .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV411P, PIX_FMT_YUV410P, PIX_FMT_RGB32, PIX_FMT_YUV420P16, PIX_FMT_YUV422P16, PIX_FMT_YUV444P16, PIX_FMT_NONE},