00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "avcodec.h"
00024 #include "internal.h"
00025
00026 static av_cold int y41p_encode_init(AVCodecContext *avctx)
00027 {
00028 if (avctx->width & 7) {
00029 av_log(avctx, AV_LOG_ERROR, "y41p requires width to be divisible by 8.\n");
00030 return AVERROR_INVALIDDATA;
00031 }
00032
00033 avctx->coded_frame = avcodec_alloc_frame();
00034 avctx->bits_per_coded_sample = 12;
00035
00036 if (!avctx->coded_frame) {
00037 av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
00038 return AVERROR(ENOMEM);
00039 }
00040
00041 return 0;
00042 }
00043
00044 static int y41p_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
00045 const AVFrame *pic, int *got_packet)
00046 {
00047 uint8_t *dst;
00048 uint8_t *y, *u, *v;
00049 int i, j, ret;
00050
00051 if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width * avctx->height * 1.5)) < 0)
00052 return ret;
00053
00054 avctx->coded_frame->reference = 0;
00055 avctx->coded_frame->key_frame = 1;
00056 avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
00057 dst = pkt->data;
00058
00059 for (i = avctx->height - 1; i >= 0; i--) {
00060 y = &pic->data[0][i * pic->linesize[0]];
00061 u = &pic->data[1][i * pic->linesize[1]];
00062 v = &pic->data[2][i * pic->linesize[2]];
00063 for (j = 0; j < avctx->width; j += 8) {
00064 *(dst++) = *(u++);
00065 *(dst++) = *(y++);
00066 *(dst++) = *(v++);
00067 *(dst++) = *(y++);
00068
00069 *(dst++) = *(u++);
00070 *(dst++) = *(y++);
00071 *(dst++) = *(v++);
00072 *(dst++) = *(y++);
00073
00074 *(dst++) = *(y++);
00075 *(dst++) = *(y++);
00076 *(dst++) = *(y++);
00077 *(dst++) = *(y++);
00078 }
00079 }
00080
00081 pkt->flags |= AV_PKT_FLAG_KEY;
00082 *got_packet = 1;
00083 return 0;
00084 }
00085
00086 static av_cold int y41p_encode_close(AVCodecContext *avctx)
00087 {
00088 av_freep(&avctx->coded_frame);
00089
00090 return 0;
00091 }
00092
00093 AVCodec ff_y41p_encoder = {
00094 .name = "y41p",
00095 .type = AVMEDIA_TYPE_VIDEO,
00096 .id = AV_CODEC_ID_Y41P,
00097 .init = y41p_encode_init,
00098 .encode2 = y41p_encode_frame,
00099 .close = y41p_encode_close,
00100 .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_YUV411P,
00101 PIX_FMT_NONE },
00102 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed YUV 4:1:1 12-bit"),
00103 };