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
;
103 /* the parameters will be extracted from the compressed bitstream */
108 /* MPEG-1/H.263 input */
109 int ff_raw_video_read_header(AVFormatContext
*s
,
110 AVFormatParameters
*ap
)
114 st
= av_new_stream(s
, 0);
116 return AVERROR(ENOMEM
);
118 st
->codec
->codec_type
= AVMEDIA_TYPE_VIDEO
;
119 st
->codec
->codec_id
= s
->iformat
->value
;
120 st
->need_parsing
= AVSTREAM_PARSE_FULL
;
122 /* for MJPEG, specify frame rate */
123 /* for MPEG-4 specify it, too (most MPEG-4 streams do not have the fixed_vop_rate set ...)*/
124 if (ap
->time_base
.num
) {
125 st
->codec
->time_base
= ap
->time_base
;
126 } else if ( st
->codec
->codec_id
== CODEC_ID_MJPEG
||
127 st
->codec
->codec_id
== CODEC_ID_MPEG4
||
128 st
->codec
->codec_id
== CODEC_ID_DIRAC
||
129 st
->codec
->codec_id
== CODEC_ID_DNXHD
||
130 st
->codec
->codec_id
== CODEC_ID_VC1
||
131 st
->codec
->codec_id
== CODEC_ID_H264
) {
132 st
->codec
->time_base
= (AVRational
){1,25};
134 av_set_pts_info(st
, 64, 1, 1200000);
139 /* Note: Do not forget to add new entries to the Makefile as well. */
141 #if CONFIG_G722_DEMUXER
142 AVInputFormat ff_g722_demuxer
= {
144 NULL_IF_CONFIG_SMALL("raw G.722"),
148 ff_raw_read_partial_packet
,
149 .flags
= AVFMT_GENERIC_INDEX
,
150 .extensions
= "g722,722",
151 .value
= CODEC_ID_ADPCM_G722
,
155 #if CONFIG_GSM_DEMUXER
156 AVInputFormat ff_gsm_demuxer
= {
158 NULL_IF_CONFIG_SMALL("raw GSM"),
161 ff_raw_audio_read_header
,
162 ff_raw_read_partial_packet
,
163 .flags
= AVFMT_GENERIC_INDEX
,
165 .value
= CODEC_ID_GSM
,
169 #if CONFIG_MJPEG_DEMUXER
170 AVInputFormat ff_mjpeg_demuxer
= {
172 NULL_IF_CONFIG_SMALL("raw MJPEG video"),
175 ff_raw_video_read_header
,
176 ff_raw_read_partial_packet
,
177 .flags
= AVFMT_GENERIC_INDEX
,
178 .extensions
= "mjpg,mjpeg",
179 .value
= CODEC_ID_MJPEG
,
183 #if CONFIG_MLP_DEMUXER
184 AVInputFormat ff_mlp_demuxer
= {
186 NULL_IF_CONFIG_SMALL("raw MLP"),
189 ff_raw_audio_read_header
,
190 ff_raw_read_partial_packet
,
191 .flags
= AVFMT_GENERIC_INDEX
,
193 .value
= CODEC_ID_MLP
,
197 #if CONFIG_TRUEHD_DEMUXER
198 AVInputFormat ff_truehd_demuxer
= {
200 NULL_IF_CONFIG_SMALL("raw TrueHD"),
203 ff_raw_audio_read_header
,
204 ff_raw_read_partial_packet
,
205 .flags
= AVFMT_GENERIC_INDEX
,
207 .value
= CODEC_ID_TRUEHD
,
211 #if CONFIG_SHORTEN_DEMUXER
212 AVInputFormat ff_shorten_demuxer
= {
214 NULL_IF_CONFIG_SMALL("raw Shorten"),
217 ff_raw_audio_read_header
,
218 ff_raw_read_partial_packet
,
219 .flags
= AVFMT_GENERIC_INDEX
,
221 .value
= CODEC_ID_SHORTEN
,
225 #if CONFIG_VC1_DEMUXER
226 AVInputFormat ff_vc1_demuxer
= {
228 NULL_IF_CONFIG_SMALL("raw VC-1"),
230 NULL
/* vc1_probe */,
231 ff_raw_video_read_header
,
232 ff_raw_read_partial_packet
,
234 .value
= CODEC_ID_VC1
,