annotate ffmpeg/libavcodec/rawenc.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 6840f77b83aa
children
rev   line source
yading@10 1 /*
yading@10 2 * Raw Video Encoder
yading@10 3 * Copyright (c) 2001 Fabrice Bellard
yading@10 4 *
yading@10 5 * This file is part of FFmpeg.
yading@10 6 *
yading@10 7 * FFmpeg is free software; you can redistribute it and/or
yading@10 8 * modify it under the terms of the GNU Lesser General Public
yading@10 9 * License as published by the Free Software Foundation; either
yading@10 10 * version 2.1 of the License, or (at your option) any later version.
yading@10 11 *
yading@10 12 * FFmpeg is distributed in the hope that it will be useful,
yading@10 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@10 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@10 15 * Lesser General Public License for more details.
yading@10 16 *
yading@10 17 * You should have received a copy of the GNU Lesser General Public
yading@10 18 * License along with FFmpeg; if not, write to the Free Software
yading@10 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@10 20 */
yading@10 21
yading@10 22 /**
yading@10 23 * @file
yading@10 24 * Raw Video Encoder
yading@10 25 */
yading@10 26
yading@10 27 #include "avcodec.h"
yading@10 28 #include "raw.h"
yading@10 29 #include "internal.h"
yading@10 30 #include "libavutil/pixdesc.h"
yading@10 31 #include "libavutil/intreadwrite.h"
yading@10 32 #include "libavutil/internal.h"
yading@10 33
yading@10 34 static av_cold int raw_init_encoder(AVCodecContext *avctx)
yading@10 35 {
yading@10 36 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
yading@10 37
yading@10 38 avctx->coded_frame = avctx->priv_data;
yading@10 39 avcodec_get_frame_defaults(avctx->coded_frame);
yading@10 40 avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
yading@10 41 avctx->bits_per_coded_sample = av_get_bits_per_pixel(desc);
yading@10 42 if(!avctx->codec_tag)
yading@10 43 avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt);
yading@10 44 return 0;
yading@10 45 }
yading@10 46
yading@10 47 static int raw_encode(AVCodecContext *avctx, AVPacket *pkt,
yading@10 48 const AVFrame *frame, int *got_packet)
yading@10 49 {
yading@10 50 int ret = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
yading@10 51
yading@10 52 if (ret < 0)
yading@10 53 return ret;
yading@10 54
yading@10 55 if ((ret = ff_alloc_packet2(avctx, pkt, ret)) < 0)
yading@10 56 return ret;
yading@10 57 if ((ret = avpicture_layout((const AVPicture *)frame, avctx->pix_fmt, avctx->width,
yading@10 58 avctx->height, pkt->data, pkt->size)) < 0)
yading@10 59 return ret;
yading@10 60
yading@10 61 if(avctx->codec_tag == AV_RL32("yuv2") && ret > 0 &&
yading@10 62 avctx->pix_fmt == AV_PIX_FMT_YUYV422) {
yading@10 63 int x;
yading@10 64 for(x = 1; x < avctx->height*avctx->width*2; x += 2)
yading@10 65 pkt->data[x] ^= 0x80;
yading@10 66 }
yading@10 67 pkt->flags |= AV_PKT_FLAG_KEY;
yading@10 68 *got_packet = 1;
yading@10 69 return 0;
yading@10 70 }
yading@10 71
yading@10 72 AVCodec ff_rawvideo_encoder = {
yading@10 73 .name = "rawvideo",
yading@10 74 .type = AVMEDIA_TYPE_VIDEO,
yading@10 75 .id = AV_CODEC_ID_RAWVIDEO,
yading@10 76 .priv_data_size = sizeof(AVFrame),
yading@10 77 .init = raw_init_encoder,
yading@10 78 .encode2 = raw_encode,
yading@10 79 .long_name = NULL_IF_CONFIG_SMALL("raw video"),
yading@10 80 };