annotate ffmpeg/libavformat/rawvideodec.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 f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * RAW video demuxer
yading@11 3 * Copyright (c) 2001 Fabrice Bellard
yading@11 4 *
yading@11 5 * This file is part of FFmpeg.
yading@11 6 *
yading@11 7 * FFmpeg is free software; you can redistribute it and/or
yading@11 8 * modify it under the terms of the GNU Lesser General Public
yading@11 9 * License as published by the Free Software Foundation; either
yading@11 10 * version 2.1 of the License, or (at your option) any later version.
yading@11 11 *
yading@11 12 * FFmpeg is distributed in the hope that it will be useful,
yading@11 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 15 * Lesser General Public License for more details.
yading@11 16 *
yading@11 17 * You should have received a copy of the GNU Lesser General Public
yading@11 18 * License along with FFmpeg; if not, write to the Free Software
yading@11 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 20 */
yading@11 21
yading@11 22 #include "libavutil/parseutils.h"
yading@11 23 #include "libavutil/pixdesc.h"
yading@11 24 #include "libavutil/opt.h"
yading@11 25 #include "internal.h"
yading@11 26 #include "avformat.h"
yading@11 27
yading@11 28 typedef struct RawVideoDemuxerContext {
yading@11 29 const AVClass *class; /**< Class for private options. */
yading@11 30 int width, height; /**< Integers describing video size, set by a private option. */
yading@11 31 char *pixel_format; /**< Set by a private option. */
yading@11 32 AVRational framerate; /**< AVRational describing framerate, set by a private option. */
yading@11 33 } RawVideoDemuxerContext;
yading@11 34
yading@11 35
yading@11 36 static int rawvideo_read_header(AVFormatContext *ctx)
yading@11 37 {
yading@11 38 RawVideoDemuxerContext *s = ctx->priv_data;
yading@11 39 enum AVPixelFormat pix_fmt;
yading@11 40 AVStream *st;
yading@11 41
yading@11 42 st = avformat_new_stream(ctx, NULL);
yading@11 43 if (!st)
yading@11 44 return AVERROR(ENOMEM);
yading@11 45
yading@11 46 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
yading@11 47
yading@11 48 st->codec->codec_id = ctx->iformat->raw_codec_id;
yading@11 49
yading@11 50 if ((pix_fmt = av_get_pix_fmt(s->pixel_format)) == AV_PIX_FMT_NONE) {
yading@11 51 av_log(ctx, AV_LOG_ERROR, "No such pixel format: %s.\n",
yading@11 52 s->pixel_format);
yading@11 53 return AVERROR(EINVAL);
yading@11 54 }
yading@11 55
yading@11 56 avpriv_set_pts_info(st, 64, s->framerate.den, s->framerate.num);
yading@11 57
yading@11 58 st->codec->width = s->width;
yading@11 59 st->codec->height = s->height;
yading@11 60 st->codec->pix_fmt = pix_fmt;
yading@11 61 st->codec->bit_rate = av_rescale_q(avpicture_get_size(st->codec->pix_fmt, s->width, s->height),
yading@11 62 (AVRational){8,1}, st->time_base);
yading@11 63
yading@11 64 return 0;
yading@11 65 }
yading@11 66
yading@11 67
yading@11 68 static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
yading@11 69 {
yading@11 70 int packet_size, ret, width, height;
yading@11 71 AVStream *st = s->streams[0];
yading@11 72
yading@11 73 width = st->codec->width;
yading@11 74 height = st->codec->height;
yading@11 75
yading@11 76 packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
yading@11 77 if (packet_size < 0)
yading@11 78 return -1;
yading@11 79
yading@11 80 ret = av_get_packet(s->pb, pkt, packet_size);
yading@11 81 pkt->pts = pkt->dts = pkt->pos / packet_size;
yading@11 82
yading@11 83 pkt->stream_index = 0;
yading@11 84 if (ret < 0)
yading@11 85 return ret;
yading@11 86 return 0;
yading@11 87 }
yading@11 88
yading@11 89 #define OFFSET(x) offsetof(RawVideoDemuxerContext, x)
yading@11 90 #define DEC AV_OPT_FLAG_DECODING_PARAM
yading@11 91 static const AVOption rawvideo_options[] = {
yading@11 92 { "video_size", "set frame size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = NULL}, 0, 0, DEC },
yading@11 93 { "pixel_format", "set pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = "yuv420p"}, 0, 0, DEC },
yading@11 94 { "framerate", "set frame rate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, DEC },
yading@11 95 { NULL },
yading@11 96 };
yading@11 97
yading@11 98 static const AVClass rawvideo_demuxer_class = {
yading@11 99 .class_name = "rawvideo demuxer",
yading@11 100 .item_name = av_default_item_name,
yading@11 101 .option = rawvideo_options,
yading@11 102 .version = LIBAVUTIL_VERSION_INT,
yading@11 103 };
yading@11 104
yading@11 105 AVInputFormat ff_rawvideo_demuxer = {
yading@11 106 .name = "rawvideo",
yading@11 107 .long_name = NULL_IF_CONFIG_SMALL("raw video"),
yading@11 108 .priv_data_size = sizeof(RawVideoDemuxerContext),
yading@11 109 .read_header = rawvideo_read_header,
yading@11 110 .read_packet = rawvideo_read_packet,
yading@11 111 .flags = AVFMT_GENERIC_INDEX,
yading@11 112 .extensions = "yuv,cif,qcif,rgb",
yading@11 113 .raw_codec_id = AV_CODEC_ID_RAWVIDEO,
yading@11 114 .priv_class = &rawvideo_demuxer_class,
yading@11 115 };