yading@10: /* yading@10: * Raw Video Encoder yading@10: * Copyright (c) 2001 Fabrice Bellard yading@10: * yading@10: * This file is part of FFmpeg. yading@10: * yading@10: * FFmpeg is free software; you can redistribute it and/or yading@10: * modify it under the terms of the GNU Lesser General Public yading@10: * License as published by the Free Software Foundation; either yading@10: * version 2.1 of the License, or (at your option) any later version. yading@10: * yading@10: * FFmpeg is distributed in the hope that it will be useful, yading@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@10: * Lesser General Public License for more details. yading@10: * yading@10: * You should have received a copy of the GNU Lesser General Public yading@10: * License along with FFmpeg; if not, write to the Free Software yading@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@10: */ yading@10: yading@10: /** yading@10: * @file yading@10: * Raw Video Encoder yading@10: */ yading@10: yading@10: #include "avcodec.h" yading@10: #include "raw.h" yading@10: #include "internal.h" yading@10: #include "libavutil/pixdesc.h" yading@10: #include "libavutil/intreadwrite.h" yading@10: #include "libavutil/internal.h" yading@10: yading@10: static av_cold int raw_init_encoder(AVCodecContext *avctx) yading@10: { yading@10: const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt); yading@10: yading@10: avctx->coded_frame = avctx->priv_data; yading@10: avcodec_get_frame_defaults(avctx->coded_frame); yading@10: avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; yading@10: avctx->bits_per_coded_sample = av_get_bits_per_pixel(desc); yading@10: if(!avctx->codec_tag) yading@10: avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt); yading@10: return 0; yading@10: } yading@10: yading@10: static int raw_encode(AVCodecContext *avctx, AVPacket *pkt, yading@10: const AVFrame *frame, int *got_packet) yading@10: { yading@10: int ret = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height); yading@10: yading@10: if (ret < 0) yading@10: return ret; yading@10: yading@10: if ((ret = ff_alloc_packet2(avctx, pkt, ret)) < 0) yading@10: return ret; yading@10: if ((ret = avpicture_layout((const AVPicture *)frame, avctx->pix_fmt, avctx->width, yading@10: avctx->height, pkt->data, pkt->size)) < 0) yading@10: return ret; yading@10: yading@10: if(avctx->codec_tag == AV_RL32("yuv2") && ret > 0 && yading@10: avctx->pix_fmt == AV_PIX_FMT_YUYV422) { yading@10: int x; yading@10: for(x = 1; x < avctx->height*avctx->width*2; x += 2) yading@10: pkt->data[x] ^= 0x80; yading@10: } yading@10: pkt->flags |= AV_PKT_FLAG_KEY; yading@10: *got_packet = 1; yading@10: return 0; yading@10: } yading@10: yading@10: AVCodec ff_rawvideo_encoder = { yading@10: .name = "rawvideo", yading@10: .type = AVMEDIA_TYPE_VIDEO, yading@10: .id = AV_CODEC_ID_RAWVIDEO, yading@10: .priv_data_size = sizeof(AVFrame), yading@10: .init = raw_init_encoder, yading@10: .encode2 = raw_encode, yading@10: .long_name = NULL_IF_CONFIG_SMALL("raw video"), yading@10: };