Mercurial > libavformat.hg
annotate raw.c @ 223:848b612d0595 libavformat
move packetheader after startcodes
author | al3x |
---|---|
date | Sun, 07 Sep 2003 00:37:46 +0000 |
parents | 56590088f801 |
children | eb90c0a5a1ba |
rev | line source |
---|---|
0 | 1 /* |
2 * RAW encoder and decoder | |
3 * Copyright (c) 2001 Fabrice Bellard. | |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 */ | |
19 #include "avformat.h" | |
20 | |
21 /* simple formats */ | |
64 | 22 static int raw_write_header(struct AVFormatContext *s) |
0 | 23 { |
24 return 0; | |
25 } | |
26 | |
64 | 27 static int raw_write_packet(struct AVFormatContext *s, int stream_index, |
28 unsigned char *buf, int size, int force_pts) | |
0 | 29 { |
30 put_buffer(&s->pb, buf, size); | |
31 put_flush_packet(&s->pb); | |
32 return 0; | |
33 } | |
34 | |
64 | 35 static int raw_write_trailer(struct AVFormatContext *s) |
0 | 36 { |
37 return 0; | |
38 } | |
39 | |
40 /* raw input */ | |
65 | 41 static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap) |
0 | 42 { |
43 AVStream *st; | |
44 int id; | |
45 | |
46 st = av_new_stream(s, 0); | |
47 if (!st) | |
48 return AVERROR_NOMEM; | |
49 if (ap) { | |
50 id = s->iformat->value; | |
51 if (id == CODEC_ID_RAWVIDEO) { | |
52 st->codec.codec_type = CODEC_TYPE_VIDEO; | |
53 } else { | |
54 st->codec.codec_type = CODEC_TYPE_AUDIO; | |
55 } | |
56 st->codec.codec_id = id; | |
57 | |
58 switch(st->codec.codec_type) { | |
59 case CODEC_TYPE_AUDIO: | |
60 st->codec.sample_rate = ap->sample_rate; | |
61 st->codec.channels = ap->channels; | |
62 break; | |
63 case CODEC_TYPE_VIDEO: | |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
64 st->codec.frame_rate = ap->frame_rate; |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
65 st->codec.frame_rate_base = ap->frame_rate_base; |
0 | 66 st->codec.width = ap->width; |
67 st->codec.height = ap->height; | |
128 | 68 st->codec.pix_fmt = ap->pix_fmt; |
0 | 69 break; |
70 default: | |
71 return -1; | |
72 } | |
73 } else { | |
74 return -1; | |
75 } | |
76 return 0; | |
77 } | |
78 | |
79 #define RAW_PACKET_SIZE 1024 | |
80 | |
64 | 81 static int raw_read_packet(AVFormatContext *s, AVPacket *pkt) |
0 | 82 { |
83 int ret, size; | |
28 | 84 // AVStream *st = s->streams[0]; |
0 | 85 |
86 size= RAW_PACKET_SIZE; | |
87 | |
88 if (av_new_packet(pkt, size) < 0) | |
89 return -EIO; | |
90 | |
91 pkt->stream_index = 0; | |
92 ret = get_buffer(&s->pb, pkt->data, size); | |
93 if (ret <= 0) { | |
94 av_free_packet(pkt); | |
95 return -EIO; | |
96 } | |
97 /* note: we need to modify the packet size here to handle the last | |
98 packet */ | |
99 pkt->size = ret; | |
100 return ret; | |
101 } | |
102 | |
64 | 103 static int raw_read_close(AVFormatContext *s) |
0 | 104 { |
105 return 0; | |
106 } | |
107 | |
108 /* mp3 read */ | |
109 static int mp3_read_header(AVFormatContext *s, | |
110 AVFormatParameters *ap) | |
111 { | |
112 AVStream *st; | |
125
7500e14259a6
mp3 codec autodetection patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
100
diff
changeset
|
113 int pos; |
0 | 114 |
115 st = av_new_stream(s, 0); | |
116 if (!st) | |
117 return AVERROR_NOMEM; | |
118 | |
119 st->codec.codec_type = CODEC_TYPE_AUDIO; | |
120 st->codec.codec_id = CODEC_ID_MP2; | |
125
7500e14259a6
mp3 codec autodetection patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
100
diff
changeset
|
121 |
7500e14259a6
mp3 codec autodetection patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
100
diff
changeset
|
122 /* looking for 11111111 111MMLLC - MPEG synchronization tag |
7500e14259a6
mp3 codec autodetection patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
100
diff
changeset
|
123 MM: 00 - MPEG-2.5, 10 - MPEG-2, 11 - MPEG-1 |
7500e14259a6
mp3 codec autodetection patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
100
diff
changeset
|
124 LL: 11 - Layer I, 10 - Layer II, 01 - Layer III |
7500e14259a6
mp3 codec autodetection patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
100
diff
changeset
|
125 XXX: this code does not read more bytes from file |
7500e14259a6
mp3 codec autodetection patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
100
diff
changeset
|
126 so if ID3 (or other stuff) length > IO_BUFFER_SIZE it fails back to CODEC_ID_MP2 */ |
7500e14259a6
mp3 codec autodetection patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
100
diff
changeset
|
127 for(pos=0; pos < s->pb.buffer_size-1; pos++) |
7500e14259a6
mp3 codec autodetection patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
100
diff
changeset
|
128 if( s->pb.buffer[pos] == 0xFF && (s->pb.buffer[pos] & 0xE0) == 0xE0 ) |
7500e14259a6
mp3 codec autodetection patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
100
diff
changeset
|
129 break; |
7500e14259a6
mp3 codec autodetection patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
100
diff
changeset
|
130 |
7500e14259a6
mp3 codec autodetection patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
100
diff
changeset
|
131 if( pos < s->pb.buffer_size-1 && (s->pb.buffer[pos+1] & 6) == 2 ) |
7500e14259a6
mp3 codec autodetection patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
100
diff
changeset
|
132 st->codec.codec_id = CODEC_ID_MP3LAME; |
7500e14259a6
mp3 codec autodetection patch by (Andriy Rysin <arysin at bcsii dot net>)
michaelni
parents:
100
diff
changeset
|
133 |
0 | 134 /* the parameters will be extracted from the compressed bitstream */ |
135 return 0; | |
136 } | |
137 | |
63 | 138 /* ac3 read */ |
139 static int ac3_read_header(AVFormatContext *s, | |
140 AVFormatParameters *ap) | |
141 { | |
142 AVStream *st; | |
143 | |
144 st = av_new_stream(s, 0); | |
145 if (!st) | |
146 return AVERROR_NOMEM; | |
147 | |
148 st->codec.codec_type = CODEC_TYPE_AUDIO; | |
149 st->codec.codec_id = CODEC_ID_AC3; | |
150 /* the parameters will be extracted from the compressed bitstream */ | |
151 return 0; | |
152 } | |
153 | |
0 | 154 /* mpeg1/h263 input */ |
155 static int video_read_header(AVFormatContext *s, | |
156 AVFormatParameters *ap) | |
157 { | |
158 AVStream *st; | |
159 | |
160 st = av_new_stream(s, 0); | |
161 if (!st) | |
162 return AVERROR_NOMEM; | |
163 | |
164 st->codec.codec_type = CODEC_TYPE_VIDEO; | |
165 st->codec.codec_id = s->iformat->value; | |
166 /* for mjpeg, specify frame rate */ | |
167 /* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/ | |
168 if (st->codec.codec_id == CODEC_ID_MJPEG || st->codec.codec_id == CODEC_ID_MPEG4) { | |
169 if (ap) { | |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
170 st->codec.frame_rate = ap->frame_rate; |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
171 st->codec.frame_rate_base = ap->frame_rate_base; |
0 | 172 } else { |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
173 st->codec.frame_rate = 25; |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
174 st->codec.frame_rate_base = 1; |
0 | 175 } |
176 } | |
177 return 0; | |
178 } | |
179 | |
180 #define SEQ_START_CODE 0x000001b3 | |
181 #define GOP_START_CODE 0x000001b8 | |
182 #define PICTURE_START_CODE 0x00000100 | |
183 | |
184 /* XXX: improve that by looking at several start codes */ | |
185 static int mpegvideo_probe(AVProbeData *p) | |
186 { | |
49 | 187 int code; |
188 const uint8_t *d; | |
0 | 189 |
190 /* we search the first start code. If it is a sequence, gop or | |
191 picture start code then we decide it is an mpeg video | |
192 stream. We do not send highest value to give a chance to mpegts */ | |
49 | 193 /* NOTE: the search range was restricted to avoid too many false |
194 detections */ | |
195 | |
196 if (p->buf_size < 6) | |
197 return 0; | |
198 d = p->buf; | |
199 code = (d[0] << 24) | (d[1] << 16) | (d[2] << 8) | (d[3]); | |
200 if ((code & 0xffffff00) == 0x100) { | |
201 if (code == SEQ_START_CODE || | |
202 code == GOP_START_CODE || | |
203 code == PICTURE_START_CODE) | |
204 return 50 - 1; | |
205 else | |
206 return 0; | |
0 | 207 } |
208 return 0; | |
209 } | |
210 | |
135
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
211 static int h263_probe(AVProbeData *p) |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
212 { |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
213 int code; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
214 const uint8_t *d; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
215 |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
216 if (p->buf_size < 6) |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
217 return 0; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
218 d = p->buf; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
219 code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2); |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
220 if (code == 0x20) { |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
221 return 50; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
222 } |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
223 return 0; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
224 } |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
225 |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
226 |
0 | 227 AVInputFormat mp3_iformat = { |
228 "mp3", | |
229 "MPEG audio", | |
230 0, | |
231 NULL, | |
232 mp3_read_header, | |
233 raw_read_packet, | |
234 raw_read_close, | |
235 .extensions = "mp2,mp3", /* XXX: use probe */ | |
236 }; | |
237 | |
238 AVOutputFormat mp2_oformat = { | |
239 "mp2", | |
240 "MPEG audio layer 2", | |
241 "audio/x-mpeg", | |
126
23f62139c013
prefers MP3 codec (rather than MP2) for output if
michaelni
parents:
125
diff
changeset
|
242 #ifdef CONFIG_MP3LAME |
23f62139c013
prefers MP3 codec (rather than MP2) for output if
michaelni
parents:
125
diff
changeset
|
243 "mp2", |
23f62139c013
prefers MP3 codec (rather than MP2) for output if
michaelni
parents:
125
diff
changeset
|
244 #else |
0 | 245 "mp2,mp3", |
126
23f62139c013
prefers MP3 codec (rather than MP2) for output if
michaelni
parents:
125
diff
changeset
|
246 #endif |
0 | 247 0, |
248 CODEC_ID_MP2, | |
249 0, | |
250 raw_write_header, | |
251 raw_write_packet, | |
252 raw_write_trailer, | |
253 }; | |
254 | |
126
23f62139c013
prefers MP3 codec (rather than MP2) for output if
michaelni
parents:
125
diff
changeset
|
255 #ifdef CONFIG_MP3LAME |
23f62139c013
prefers MP3 codec (rather than MP2) for output if
michaelni
parents:
125
diff
changeset
|
256 AVOutputFormat mp3_oformat = { |
23f62139c013
prefers MP3 codec (rather than MP2) for output if
michaelni
parents:
125
diff
changeset
|
257 "mp3", |
23f62139c013
prefers MP3 codec (rather than MP2) for output if
michaelni
parents:
125
diff
changeset
|
258 "MPEG audio layer 3", |
23f62139c013
prefers MP3 codec (rather than MP2) for output if
michaelni
parents:
125
diff
changeset
|
259 "audio/x-mpeg", |
23f62139c013
prefers MP3 codec (rather than MP2) for output if
michaelni
parents:
125
diff
changeset
|
260 "mp3", |
23f62139c013
prefers MP3 codec (rather than MP2) for output if
michaelni
parents:
125
diff
changeset
|
261 0, |
23f62139c013
prefers MP3 codec (rather than MP2) for output if
michaelni
parents:
125
diff
changeset
|
262 CODEC_ID_MP3LAME, |
23f62139c013
prefers MP3 codec (rather than MP2) for output if
michaelni
parents:
125
diff
changeset
|
263 0, |
23f62139c013
prefers MP3 codec (rather than MP2) for output if
michaelni
parents:
125
diff
changeset
|
264 raw_write_header, |
23f62139c013
prefers MP3 codec (rather than MP2) for output if
michaelni
parents:
125
diff
changeset
|
265 raw_write_packet, |
23f62139c013
prefers MP3 codec (rather than MP2) for output if
michaelni
parents:
125
diff
changeset
|
266 raw_write_trailer, |
23f62139c013
prefers MP3 codec (rather than MP2) for output if
michaelni
parents:
125
diff
changeset
|
267 }; |
23f62139c013
prefers MP3 codec (rather than MP2) for output if
michaelni
parents:
125
diff
changeset
|
268 #endif |
0 | 269 |
270 AVInputFormat ac3_iformat = { | |
271 "ac3", | |
272 "raw ac3", | |
273 0, | |
274 NULL, | |
63 | 275 ac3_read_header, |
0 | 276 raw_read_packet, |
277 raw_read_close, | |
278 .extensions = "ac3", | |
279 }; | |
280 | |
281 AVOutputFormat ac3_oformat = { | |
282 "ac3", | |
283 "raw ac3", | |
284 "audio/x-ac3", | |
285 "ac3", | |
286 0, | |
287 CODEC_ID_AC3, | |
288 0, | |
289 raw_write_header, | |
290 raw_write_packet, | |
291 raw_write_trailer, | |
292 }; | |
293 | |
135
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
294 AVInputFormat h263_iformat = { |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
295 "h263", |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
296 "raw h263", |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
297 0, |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
298 h263_probe, |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
299 video_read_header, |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
300 raw_read_packet, |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
301 raw_read_close, |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
302 // .extensions = "h263", //FIXME remove after writing mpeg4_probe |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
303 .value = CODEC_ID_H263, |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
304 }; |
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
305 |
0 | 306 AVOutputFormat h263_oformat = { |
307 "h263", | |
308 "raw h263", | |
309 "video/x-h263", | |
310 "h263", | |
311 0, | |
312 0, | |
313 CODEC_ID_H263, | |
314 raw_write_header, | |
315 raw_write_packet, | |
316 raw_write_trailer, | |
317 }; | |
318 | |
319 AVInputFormat m4v_iformat = { | |
320 "m4v", | |
321 "raw MPEG4 video format", | |
322 0, | |
323 NULL /*mpegvideo_probe*/, | |
324 video_read_header, | |
325 raw_read_packet, | |
326 raw_read_close, | |
327 .extensions = "m4v", //FIXME remove after writing mpeg4_probe | |
328 .value = CODEC_ID_MPEG4, | |
329 }; | |
330 | |
331 AVOutputFormat m4v_oformat = { | |
332 "m4v", | |
333 "raw MPEG4 video format", | |
334 NULL, | |
335 "m4v", | |
336 0, | |
337 CODEC_ID_NONE, | |
338 CODEC_ID_MPEG4, | |
339 raw_write_header, | |
340 raw_write_packet, | |
341 raw_write_trailer, | |
342 }; | |
343 | |
100 | 344 AVInputFormat h264_iformat = { |
345 "h264", | |
346 "raw H264 video format", | |
347 0, | |
348 NULL /*mpegvideo_probe*/, | |
349 video_read_header, | |
350 raw_read_packet, | |
351 raw_read_close, | |
352 .extensions = "h26l,h264", //FIXME remove after writing mpeg4_probe | |
353 .value = CODEC_ID_H264, | |
354 }; | |
355 | |
356 AVOutputFormat h264_oformat = { | |
357 "h264", | |
358 "raw H264 video format", | |
359 NULL, | |
360 "h264", | |
361 0, | |
362 CODEC_ID_NONE, | |
363 CODEC_ID_H264, | |
364 raw_write_header, | |
365 raw_write_packet, | |
366 raw_write_trailer, | |
367 }; | |
368 | |
0 | 369 AVInputFormat mpegvideo_iformat = { |
370 "mpegvideo", | |
371 "MPEG video", | |
372 0, | |
373 mpegvideo_probe, | |
374 video_read_header, | |
375 raw_read_packet, | |
376 raw_read_close, | |
377 .value = CODEC_ID_MPEG1VIDEO, | |
378 }; | |
379 | |
380 AVOutputFormat mpeg1video_oformat = { | |
381 "mpeg1video", | |
382 "MPEG video", | |
383 "video/x-mpeg", | |
384 "mpg,mpeg", | |
385 0, | |
386 0, | |
387 CODEC_ID_MPEG1VIDEO, | |
388 raw_write_header, | |
389 raw_write_packet, | |
390 raw_write_trailer, | |
391 }; | |
392 | |
393 AVInputFormat mjpeg_iformat = { | |
394 "mjpeg", | |
395 "MJPEG video", | |
396 0, | |
397 NULL, | |
398 video_read_header, | |
399 raw_read_packet, | |
400 raw_read_close, | |
401 .extensions = "mjpg,mjpeg", | |
402 .value = CODEC_ID_MJPEG, | |
403 }; | |
404 | |
405 AVOutputFormat mjpeg_oformat = { | |
406 "mjpeg", | |
407 "MJPEG video", | |
408 "video/x-mjpeg", | |
409 "mjpg,mjpeg", | |
410 0, | |
411 0, | |
412 CODEC_ID_MJPEG, | |
413 raw_write_header, | |
414 raw_write_packet, | |
415 raw_write_trailer, | |
416 }; | |
417 | |
418 /* pcm formats */ | |
419 | |
420 #define PCMDEF(name, long_name, ext, codec) \ | |
421 AVInputFormat pcm_ ## name ## _iformat = {\ | |
422 #name,\ | |
423 long_name,\ | |
424 0,\ | |
425 NULL,\ | |
426 raw_read_header,\ | |
427 raw_read_packet,\ | |
428 raw_read_close,\ | |
429 .extensions = ext,\ | |
430 .value = codec,\ | |
431 };\ | |
432 \ | |
433 AVOutputFormat pcm_ ## name ## _oformat = {\ | |
434 #name,\ | |
435 long_name,\ | |
436 NULL,\ | |
437 ext,\ | |
438 0,\ | |
439 codec,\ | |
440 0,\ | |
441 raw_write_header,\ | |
442 raw_write_packet,\ | |
443 raw_write_trailer,\ | |
444 }; | |
445 | |
446 #ifdef WORDS_BIGENDIAN | |
447 #define BE_DEF(s) s | |
448 #define LE_DEF(s) NULL | |
449 #else | |
450 #define BE_DEF(s) NULL | |
451 #define LE_DEF(s) s | |
452 #endif | |
453 | |
454 | |
455 PCMDEF(s16le, "pcm signed 16 bit little endian format", | |
456 LE_DEF("sw"), CODEC_ID_PCM_S16LE) | |
457 | |
458 PCMDEF(s16be, "pcm signed 16 bit big endian format", | |
459 BE_DEF("sw"), CODEC_ID_PCM_S16BE) | |
460 | |
461 PCMDEF(u16le, "pcm unsigned 16 bit little endian format", | |
462 LE_DEF("uw"), CODEC_ID_PCM_U16LE) | |
463 | |
464 PCMDEF(u16be, "pcm unsigned 16 bit big endian format", | |
465 BE_DEF("uw"), CODEC_ID_PCM_U16BE) | |
466 | |
467 PCMDEF(s8, "pcm signed 8 bit format", | |
468 "sb", CODEC_ID_PCM_S8) | |
469 | |
470 PCMDEF(u8, "pcm unsigned 8 bit format", | |
471 "ub", CODEC_ID_PCM_U8) | |
472 | |
473 PCMDEF(mulaw, "pcm mu law format", | |
474 "ul", CODEC_ID_PCM_MULAW) | |
475 | |
476 PCMDEF(alaw, "pcm A law format", | |
477 "al", CODEC_ID_PCM_ALAW) | |
478 | |
64 | 479 static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt) |
0 | 480 { |
481 int packet_size, ret, width, height; | |
482 AVStream *st = s->streams[0]; | |
483 | |
484 width = st->codec.width; | |
485 height = st->codec.height; | |
486 | |
128 | 487 packet_size = avpicture_get_size(st->codec.pix_fmt, width, height); |
488 if (packet_size < 0) | |
0 | 489 av_abort(); |
490 | |
491 if (av_new_packet(pkt, packet_size) < 0) | |
492 return -EIO; | |
493 | |
494 pkt->stream_index = 0; | |
495 #if 0 | |
496 /* bypass buffered I/O */ | |
497 ret = url_read(url_fileno(&s->pb), pkt->data, pkt->size); | |
498 #else | |
499 ret = get_buffer(&s->pb, pkt->data, pkt->size); | |
500 #endif | |
501 if (ret != pkt->size) { | |
502 av_free_packet(pkt); | |
503 return -EIO; | |
504 } else { | |
505 return 0; | |
506 } | |
507 } | |
508 | |
509 AVInputFormat rawvideo_iformat = { | |
510 "rawvideo", | |
511 "raw video format", | |
512 0, | |
513 NULL, | |
514 raw_read_header, | |
515 rawvideo_read_packet, | |
516 raw_read_close, | |
517 .extensions = "yuv", | |
518 .value = CODEC_ID_RAWVIDEO, | |
519 }; | |
520 | |
521 AVOutputFormat rawvideo_oformat = { | |
522 "rawvideo", | |
523 "raw video format", | |
524 NULL, | |
525 "yuv", | |
526 0, | |
527 CODEC_ID_NONE, | |
528 CODEC_ID_RAWVIDEO, | |
529 raw_write_header, | |
530 raw_write_packet, | |
531 raw_write_trailer, | |
532 }; | |
533 | |
534 static int null_write_packet(struct AVFormatContext *s, | |
535 int stream_index, | |
536 unsigned char *buf, int size, int force_pts) | |
537 { | |
538 return 0; | |
539 } | |
540 | |
541 AVOutputFormat null_oformat = { | |
542 "null", | |
543 "null video format", | |
544 NULL, | |
545 NULL, | |
546 0, | |
547 #ifdef WORDS_BIGENDIAN | |
548 CODEC_ID_PCM_S16BE, | |
549 #else | |
550 CODEC_ID_PCM_S16LE, | |
551 #endif | |
552 CODEC_ID_RAWVIDEO, | |
553 raw_write_header, | |
554 null_write_packet, | |
555 raw_write_trailer, | |
556 .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE, | |
557 }; | |
558 | |
559 int raw_init(void) | |
560 { | |
561 av_register_input_format(&mp3_iformat); | |
562 av_register_output_format(&mp2_oformat); | |
126
23f62139c013
prefers MP3 codec (rather than MP2) for output if
michaelni
parents:
125
diff
changeset
|
563 #ifdef CONFIG_MP3LAME |
23f62139c013
prefers MP3 codec (rather than MP2) for output if
michaelni
parents:
125
diff
changeset
|
564 av_register_output_format(&mp3_oformat); |
23f62139c013
prefers MP3 codec (rather than MP2) for output if
michaelni
parents:
125
diff
changeset
|
565 #endif |
0 | 566 av_register_input_format(&ac3_iformat); |
567 av_register_output_format(&ac3_oformat); | |
568 | |
135
56590088f801
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
128
diff
changeset
|
569 av_register_input_format(&h263_iformat); |
0 | 570 av_register_output_format(&h263_oformat); |
571 | |
572 av_register_input_format(&m4v_iformat); | |
573 av_register_output_format(&m4v_oformat); | |
100 | 574 |
575 av_register_input_format(&h264_iformat); | |
576 av_register_output_format(&h264_oformat); | |
0 | 577 |
578 av_register_input_format(&mpegvideo_iformat); | |
579 av_register_output_format(&mpeg1video_oformat); | |
580 | |
581 av_register_input_format(&mjpeg_iformat); | |
582 av_register_output_format(&mjpeg_oformat); | |
583 | |
584 av_register_input_format(&pcm_s16le_iformat); | |
585 av_register_output_format(&pcm_s16le_oformat); | |
586 av_register_input_format(&pcm_s16be_iformat); | |
587 av_register_output_format(&pcm_s16be_oformat); | |
588 av_register_input_format(&pcm_u16le_iformat); | |
589 av_register_output_format(&pcm_u16le_oformat); | |
590 av_register_input_format(&pcm_u16be_iformat); | |
591 av_register_output_format(&pcm_u16be_oformat); | |
592 av_register_input_format(&pcm_s8_iformat); | |
593 av_register_output_format(&pcm_s8_oformat); | |
594 av_register_input_format(&pcm_u8_iformat); | |
595 av_register_output_format(&pcm_u8_oformat); | |
596 av_register_input_format(&pcm_mulaw_iformat); | |
597 av_register_output_format(&pcm_mulaw_oformat); | |
598 av_register_input_format(&pcm_alaw_iformat); | |
599 av_register_output_format(&pcm_alaw_oformat); | |
600 | |
601 av_register_input_format(&rawvideo_iformat); | |
602 av_register_output_format(&rawvideo_oformat); | |
603 | |
604 av_register_output_format(&null_oformat); | |
605 return 0; | |
606 } |