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