Libav 0.7.1
|
00001 /* 00002 * Raw Video Encoder 00003 * Copyright (c) 2001 Fabrice Bellard 00004 * 00005 * This file is part of Libav. 00006 * 00007 * Libav is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * Libav is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with Libav; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00027 #include "avcodec.h" 00028 #include "raw.h" 00029 #include "libavutil/pixdesc.h" 00030 #include "libavutil/intreadwrite.h" 00031 00032 static av_cold int raw_init_encoder(AVCodecContext *avctx) 00033 { 00034 avctx->coded_frame = (AVFrame *)avctx->priv_data; 00035 avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; 00036 avctx->coded_frame->key_frame = 1; 00037 avctx->bits_per_coded_sample = av_get_bits_per_pixel(&av_pix_fmt_descriptors[avctx->pix_fmt]); 00038 if(!avctx->codec_tag) 00039 avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt); 00040 return 0; 00041 } 00042 00043 static int raw_encode(AVCodecContext *avctx, 00044 unsigned char *frame, int buf_size, void *data) 00045 { 00046 int ret = avpicture_layout((AVPicture *)data, avctx->pix_fmt, avctx->width, 00047 avctx->height, frame, buf_size); 00048 00049 if(avctx->codec_tag == AV_RL32("yuv2") && ret > 0 && 00050 avctx->pix_fmt == PIX_FMT_YUYV422) { 00051 int x; 00052 for(x = 1; x < avctx->height*avctx->width*2; x += 2) 00053 frame[x] ^= 0x80; 00054 } 00055 return ret; 00056 } 00057 00058 AVCodec ff_rawvideo_encoder = { 00059 "rawvideo", 00060 AVMEDIA_TYPE_VIDEO, 00061 CODEC_ID_RAWVIDEO, 00062 sizeof(AVFrame), 00063 raw_init_encoder, 00064 raw_encode, 00065 .long_name = NULL_IF_CONFIG_SMALL("raw video"), 00066 };