3 * Copyright (c) 2001 Fabrice Bellard
4 * Copyright (c) 2005 Alex Beregszaszi
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "avio_internal.h"
28 int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
33 st = av_new_stream(s, 0);
35 return AVERROR(ENOMEM);
37 id = s->iformat->value;
38 if (id == CODEC_ID_RAWVIDEO) {
39 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
41 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
43 st->codec->codec_id = id;
45 switch(st->codec->codec_type) {
46 case AVMEDIA_TYPE_AUDIO:
47 st->codec->sample_rate = ap->sample_rate;
48 if(ap->channels) st->codec->channels = ap->channels;
49 else st->codec->channels = 1;
50 st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id);
51 assert(st->codec->bits_per_coded_sample > 0);
52 st->codec->block_align = st->codec->bits_per_coded_sample*st->codec->channels/8;
53 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
55 case AVMEDIA_TYPE_VIDEO:
57 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
59 av_set_pts_info(st, 64, 1, 25);
60 st->codec->width = ap->width;
61 st->codec->height = ap->height;
62 st->codec->pix_fmt = ap->pix_fmt;
63 if(st->codec->pix_fmt == PIX_FMT_NONE)
64 st->codec->pix_fmt= PIX_FMT_YUV420P;
72 #define RAW_PACKET_SIZE 1024
74 int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
78 size = RAW_PACKET_SIZE;
80 if (av_new_packet(pkt, size) < 0)
81 return AVERROR(ENOMEM);
83 pkt->pos= avio_tell(s->pb);
84 pkt->stream_index = 0;
85 ret = ffio_read_partial(s->pb, pkt->data, size);
94 int ff_raw_audio_read_header(AVFormatContext *s,
95 AVFormatParameters *ap)
97 AVStream *st = av_new_stream(s, 0);
99 return AVERROR(ENOMEM);
100 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
101 st->codec->codec_id = s->iformat->value;
102 st->need_parsing = AVSTREAM_PARSE_FULL;
104 /* the parameters will be extracted from the compressed bitstream */
109 /* MPEG-1/H.263 input */
110 int ff_raw_video_read_header(AVFormatContext *s,
111 AVFormatParameters *ap)
115 st = av_new_stream(s, 0);
117 return AVERROR(ENOMEM);
119 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
120 st->codec->codec_id = s->iformat->value;
121 st->need_parsing = AVSTREAM_PARSE_FULL;
123 /* for MJPEG, specify frame rate */
124 /* for MPEG-4 specify it, too (most MPEG-4 streams do not have the fixed_vop_rate set ...)*/
125 if (ap->time_base.num) {
126 st->codec->time_base= ap->time_base;
127 } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
128 st->codec->codec_id == CODEC_ID_MPEG4 ||
129 st->codec->codec_id == CODEC_ID_DIRAC ||
130 st->codec->codec_id == CODEC_ID_DNXHD ||
131 st->codec->codec_id == CODEC_ID_VC1 ||
132 st->codec->codec_id == CODEC_ID_H264) {
133 st->codec->time_base= (AVRational){1,25};
135 av_set_pts_info(st, 64, 1, 1200000);
140 /* Note: Do not forget to add new entries to the Makefile as well. */
142 #if CONFIG_G722_DEMUXER
143 AVInputFormat ff_g722_demuxer = {
145 NULL_IF_CONFIG_SMALL("raw G.722"),
149 ff_raw_read_partial_packet,
150 .flags= AVFMT_GENERIC_INDEX,
151 .extensions = "g722,722",
152 .value = CODEC_ID_ADPCM_G722,
156 #if CONFIG_GSM_DEMUXER
157 AVInputFormat ff_gsm_demuxer = {
159 NULL_IF_CONFIG_SMALL("raw GSM"),
162 ff_raw_audio_read_header,
163 ff_raw_read_partial_packet,
164 .flags= AVFMT_GENERIC_INDEX,
166 .value = CODEC_ID_GSM,
170 #if CONFIG_MJPEG_DEMUXER
171 AVInputFormat ff_mjpeg_demuxer = {
173 NULL_IF_CONFIG_SMALL("raw MJPEG video"),
176 ff_raw_video_read_header,
177 ff_raw_read_partial_packet,
178 .flags= AVFMT_GENERIC_INDEX,
179 .extensions = "mjpg,mjpeg",
180 .value = CODEC_ID_MJPEG,
184 #if CONFIG_MLP_DEMUXER
185 AVInputFormat ff_mlp_demuxer = {
187 NULL_IF_CONFIG_SMALL("raw MLP"),
190 ff_raw_audio_read_header,
191 ff_raw_read_partial_packet,
192 .flags= AVFMT_GENERIC_INDEX,
194 .value = CODEC_ID_MLP,
198 #if CONFIG_TRUEHD_DEMUXER
199 AVInputFormat ff_truehd_demuxer = {
201 NULL_IF_CONFIG_SMALL("raw TrueHD"),
204 ff_raw_audio_read_header,
205 ff_raw_read_partial_packet,
206 .flags= AVFMT_GENERIC_INDEX,
208 .value = CODEC_ID_TRUEHD,
212 #if CONFIG_SHORTEN_DEMUXER
213 AVInputFormat ff_shorten_demuxer = {
215 NULL_IF_CONFIG_SMALL("raw Shorten"),
218 ff_raw_audio_read_header,
219 ff_raw_read_partial_packet,
220 .flags= AVFMT_GENERIC_INDEX,
222 .value = CODEC_ID_SHORTEN,
226 #if CONFIG_VC1_DEMUXER
227 AVInputFormat ff_vc1_demuxer = {
229 NULL_IF_CONFIG_SMALL("raw VC-1"),
231 NULL /* vc1_probe */,
232 ff_raw_video_read_header,
233 ff_raw_read_partial_packet,
235 .value = CODEC_ID_VC1,