00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027 #include "avcodec.h"
00028 #include "raw.h"
00029 #include "internal.h"
00030 #include "libavutil/pixdesc.h"
00031 #include "libavutil/intreadwrite.h"
00032
00033 static av_cold int raw_init_encoder(AVCodecContext *avctx)
00034 {
00035 avctx->coded_frame = avctx->priv_data;
00036 avcodec_get_frame_defaults(avctx->coded_frame);
00037 avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
00038 avctx->bits_per_coded_sample = av_get_bits_per_pixel(&av_pix_fmt_descriptors[avctx->pix_fmt]);
00039 if(!avctx->codec_tag)
00040 avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt);
00041 return 0;
00042 }
00043
00044 static int raw_encode(AVCodecContext *avctx, AVPacket *pkt,
00045 const AVFrame *frame, int *got_packet)
00046 {
00047 int ret = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
00048
00049 if (ret < 0)
00050 return ret;
00051
00052 if ((ret = ff_alloc_packet2(avctx, pkt, ret)) < 0)
00053 return ret;
00054 if ((ret = avpicture_layout((const AVPicture *)frame, avctx->pix_fmt, avctx->width,
00055 avctx->height, pkt->data, pkt->size)) < 0)
00056 return ret;
00057
00058 if(avctx->codec_tag == AV_RL32("yuv2") && ret > 0 &&
00059 avctx->pix_fmt == PIX_FMT_YUYV422) {
00060 int x;
00061 for(x = 1; x < avctx->height*avctx->width*2; x += 2)
00062 pkt->data[x] ^= 0x80;
00063 }
00064 pkt->flags |= AV_PKT_FLAG_KEY;
00065 *got_packet = 1;
00066 return 0;
00067 }
00068
00069 AVCodec ff_rawvideo_encoder = {
00070 .name = "rawvideo",
00071 .type = AVMEDIA_TYPE_VIDEO,
00072 .id = CODEC_ID_RAWVIDEO,
00073 .priv_data_size = sizeof(AVFrame),
00074 .init = raw_init_encoder,
00075 .encode2 = raw_encode,
00076 .long_name = NULL_IF_CONFIG_SMALL("raw video"),
00077 };