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 #include "libavutil/internal.h"
00033
00034 static av_cold int raw_init_encoder(AVCodecContext *avctx)
00035 {
00036 avctx->coded_frame = avctx->priv_data;
00037 avcodec_get_frame_defaults(avctx->coded_frame);
00038 avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
00039 avctx->bits_per_coded_sample = av_get_bits_per_pixel(&av_pix_fmt_descriptors[avctx->pix_fmt]);
00040 if(!avctx->codec_tag)
00041 avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt);
00042 return 0;
00043 }
00044
00045 static int raw_encode(AVCodecContext *avctx, AVPacket *pkt,
00046 const AVFrame *frame, int *got_packet)
00047 {
00048 int ret = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
00049
00050 if (ret < 0)
00051 return ret;
00052
00053 if ((ret = ff_alloc_packet2(avctx, pkt, ret)) < 0)
00054 return ret;
00055 if ((ret = avpicture_layout((const AVPicture *)frame, avctx->pix_fmt, avctx->width,
00056 avctx->height, pkt->data, pkt->size)) < 0)
00057 return ret;
00058
00059 if(avctx->codec_tag == AV_RL32("yuv2") && ret > 0 &&
00060 avctx->pix_fmt == PIX_FMT_YUYV422) {
00061 int x;
00062 for(x = 1; x < avctx->height*avctx->width*2; x += 2)
00063 pkt->data[x] ^= 0x80;
00064 }
00065 pkt->flags |= AV_PKT_FLAG_KEY;
00066 *got_packet = 1;
00067 return 0;
00068 }
00069
00070 AVCodec ff_rawvideo_encoder = {
00071 .name = "rawvideo",
00072 .type = AVMEDIA_TYPE_VIDEO,
00073 .id = AV_CODEC_ID_RAWVIDEO,
00074 .priv_data_size = sizeof(AVFrame),
00075 .init = raw_init_encoder,
00076 .encode2 = raw_encode,
00077 .long_name = NULL_IF_CONFIG_SMALL("raw video"),
00078 };