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