Commit 1f801f3a authored by Paul B Mahol's avatar Paul B Mahol Committed by Michael Niedermayer

yuv4enc: switch to encode2()

Signed-off-by: 's avatarPaul B Mahol <onemda@gmail.com>
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent d1ede561
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
*/ */
#include "avcodec.h" #include "avcodec.h"
#include "internal.h"
static av_cold int yuv4_encode_init(AVCodecContext *avctx) static av_cold int yuv4_encode_init(AVCodecContext *avctx)
{ {
...@@ -34,19 +35,18 @@ static av_cold int yuv4_encode_init(AVCodecContext *avctx) ...@@ -34,19 +35,18 @@ static av_cold int yuv4_encode_init(AVCodecContext *avctx)
return 0; return 0;
} }
static int yuv4_encode_frame(AVCodecContext *avctx, uint8_t *buf, static int yuv4_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
int buf_size, void *data) const AVFrame *pic, int *got_packet)
{ {
AVFrame *pic = data; uint8_t *dst;
uint8_t *dst = buf;
uint8_t *y, *u, *v; uint8_t *y, *u, *v;
int i, j; int i, j, ret;
int output_size = 0;
if (buf_size < 6 * (avctx->width + 1 >> 1) * (avctx->height + 1 >> 1)) { if ((ret = ff_alloc_packet(pkt, 6 * (avctx->width + 1 >> 1) * (avctx->height + 1 >> 1))) < 0) {
av_log(avctx, AV_LOG_ERROR, "Out buffer is too small.\n"); av_log(avctx, AV_LOG_ERROR, "Out buffer is too small.\n");
return AVERROR(ENOMEM); return ret;
} }
dst = pkt->data;
avctx->coded_frame->reference = 0; avctx->coded_frame->reference = 0;
avctx->coded_frame->key_frame = 1; avctx->coded_frame->key_frame = 1;
...@@ -64,14 +64,15 @@ static int yuv4_encode_frame(AVCodecContext *avctx, uint8_t *buf, ...@@ -64,14 +64,15 @@ static int yuv4_encode_frame(AVCodecContext *avctx, uint8_t *buf,
*dst++ = y[ 2 * j + 1]; *dst++ = y[ 2 * j + 1];
*dst++ = y[pic->linesize[0] + 2 * j ]; *dst++ = y[pic->linesize[0] + 2 * j ];
*dst++ = y[pic->linesize[0] + 2 * j + 1]; *dst++ = y[pic->linesize[0] + 2 * j + 1];
output_size += 6;
} }
y += 2 * pic->linesize[0]; y += 2 * pic->linesize[0];
u += pic->linesize[1]; u += pic->linesize[1];
v += pic->linesize[2]; v += pic->linesize[2];
} }
return output_size; pkt->flags |= AV_PKT_FLAG_KEY;
*got_packet = 1;
return 0;
} }
static av_cold int yuv4_encode_close(AVCodecContext *avctx) static av_cold int yuv4_encode_close(AVCodecContext *avctx)
...@@ -86,7 +87,7 @@ AVCodec ff_yuv4_encoder = { ...@@ -86,7 +87,7 @@ AVCodec ff_yuv4_encoder = {
.type = AVMEDIA_TYPE_VIDEO, .type = AVMEDIA_TYPE_VIDEO,
.id = CODEC_ID_YUV4, .id = CODEC_ID_YUV4,
.init = yuv4_encode_init, .init = yuv4_encode_init,
.encode = yuv4_encode_frame, .encode2 = yuv4_encode_frame,
.close = yuv4_encode_close, .close = yuv4_encode_close,
.pix_fmts = (const enum PixelFormat[]){ PIX_FMT_YUV420P, PIX_FMT_NONE }, .pix_fmts = (const enum PixelFormat[]){ PIX_FMT_YUV420P, PIX_FMT_NONE },
.long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed 4:2:0"), .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed 4:2:0"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment