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
27 int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
32 st = av_new_stream(s, 0);
34 return AVERROR(ENOMEM);
36 id = s->iformat->value;
37 if (id == CODEC_ID_RAWVIDEO) {
38 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
40 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
42 st->codec->codec_id = id;
44 switch(st->codec->codec_type) {
45 case AVMEDIA_TYPE_AUDIO:
46 st->codec->sample_rate = ap->sample_rate;
47 if(ap->channels) st->codec->channels = ap->channels;
48 else st->codec->channels = 1;
49 st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id);
50 assert(st->codec->bits_per_coded_sample > 0);
51 st->codec->block_align = st->codec->bits_per_coded_sample*st->codec->channels/8;
52 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
54 case AVMEDIA_TYPE_VIDEO:
56 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
58 av_set_pts_info(st, 64, 1, 25);
59 st->codec->width = ap->width;
60 st->codec->height = ap->height;
61 st->codec->pix_fmt = ap->pix_fmt;
62 if(st->codec->pix_fmt == PIX_FMT_NONE)
63 st->codec->pix_fmt= PIX_FMT_YUV420P;
71 #define RAW_PACKET_SIZE 1024
73 int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
77 size = RAW_PACKET_SIZE;
79 if (av_new_packet(pkt, size) < 0)
80 return AVERROR(ENOMEM);
82 pkt->pos= url_ftell(s->pb);
83 pkt->stream_index = 0;
84 ret = get_partial_buffer(s->pb, pkt->data, size);
93 int ff_raw_audio_read_header(AVFormatContext *s,
94 AVFormatParameters *ap)
96 AVStream *st = av_new_stream(s, 0);
98 return AVERROR(ENOMEM);
99 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
100 st->codec->codec_id = s->iformat->value;
101 st->need_parsing = AVSTREAM_PARSE_FULL;
102 /* the parameters will be extracted from the compressed bitstream */
107 /* MPEG-1/H.263 input */
108 int ff_raw_video_read_header(AVFormatContext *s,
109 AVFormatParameters *ap)
113 st = av_new_stream(s, 0);
115 return AVERROR(ENOMEM);
117 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
118 st->codec->codec_id = s->iformat->value;
119 st->need_parsing = AVSTREAM_PARSE_FULL;
121 /* for MJPEG, specify frame rate */
122 /* for MPEG-4 specify it, too (most MPEG-4 streams do not have the fixed_vop_rate set ...)*/
123 if (ap->time_base.num) {
124 st->codec->time_base= ap->time_base;
125 } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
126 st->codec->codec_id == CODEC_ID_MPEG4 ||
127 st->codec->codec_id == CODEC_ID_DIRAC ||
128 st->codec->codec_id == CODEC_ID_DNXHD ||
129 st->codec->codec_id == CODEC_ID_VC1 ||
130 st->codec->codec_id == CODEC_ID_H264) {
131 st->codec->time_base= (AVRational){1,25};
133 av_set_pts_info(st, 64, 1, 1200000);
138 /* Note: Do not forget to add new entries to the Makefile as well. */
140 #if CONFIG_G722_DEMUXER
141 AVInputFormat ff_g722_demuxer = {
143 NULL_IF_CONFIG_SMALL("raw G.722"),
147 ff_raw_read_partial_packet,
148 .flags= AVFMT_GENERIC_INDEX,
149 .extensions = "g722,722",
150 .value = CODEC_ID_ADPCM_G722,
154 #if CONFIG_GSM_DEMUXER
155 AVInputFormat ff_gsm_demuxer = {
157 NULL_IF_CONFIG_SMALL("raw GSM"),
160 ff_raw_audio_read_header,
161 ff_raw_read_partial_packet,
162 .flags= AVFMT_GENERIC_INDEX,
164 .value = CODEC_ID_GSM,
168 #if CONFIG_MJPEG_DEMUXER
169 AVInputFormat ff_mjpeg_demuxer = {
171 NULL_IF_CONFIG_SMALL("raw MJPEG video"),
174 ff_raw_video_read_header,
175 ff_raw_read_partial_packet,
176 .flags= AVFMT_GENERIC_INDEX,
177 .extensions = "mjpg,mjpeg",
178 .value = CODEC_ID_MJPEG,
182 #if CONFIG_MLP_DEMUXER
183 AVInputFormat ff_mlp_demuxer = {
185 NULL_IF_CONFIG_SMALL("raw MLP"),
188 ff_raw_audio_read_header,
189 ff_raw_read_partial_packet,
190 .flags= AVFMT_GENERIC_INDEX,
192 .value = CODEC_ID_MLP,
196 #if CONFIG_TRUEHD_DEMUXER
197 AVInputFormat ff_truehd_demuxer = {
199 NULL_IF_CONFIG_SMALL("raw TrueHD"),
202 ff_raw_audio_read_header,
203 ff_raw_read_partial_packet,
204 .flags= AVFMT_GENERIC_INDEX,
206 .value = CODEC_ID_TRUEHD,
210 #if CONFIG_SHORTEN_DEMUXER
211 AVInputFormat ff_shorten_demuxer = {
213 NULL_IF_CONFIG_SMALL("raw Shorten"),
216 ff_raw_audio_read_header,
217 ff_raw_read_partial_packet,
218 .flags= AVFMT_GENERIC_INDEX,
220 .value = CODEC_ID_SHORTEN,
224 #if CONFIG_VC1_DEMUXER
225 AVInputFormat ff_vc1_demuxer = {
227 NULL_IF_CONFIG_SMALL("raw VC-1"),
229 NULL /* vc1_probe */,
230 ff_raw_video_read_header,
231 ff_raw_read_partial_packet,
233 .value = CODEC_ID_VC1,