Fix wrong error message.
[libav.git] / libavformat / raw.c
CommitLineData
115329f1 1/*
7fbde343 2 * RAW muxer and demuxer
19720f15 3 * Copyright (c) 2001 Fabrice Bellard.
84c63c01 4 * Copyright (c) 2005 Alex Beregszaszi
de6d9b64 5 *
b78e7197
DB
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
19720f15
FB
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
b78e7197 11 * version 2.1 of the License, or (at your option) any later version.
de6d9b64 12 *
b78e7197 13 * FFmpeg is distributed in the hope that it will be useful,
de6d9b64 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19720f15
FB
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
de6d9b64 17 *
19720f15 18 * You should have received a copy of the GNU Lesser General Public
b78e7197 19 * License along with FFmpeg; if not, write to the Free Software
5509bffa 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
de6d9b64 21 */
de6d9b64 22#include "avformat.h"
99ff31dc 23#include "ac3_parser.h"
7241a6bb 24#include "raw.h"
de6d9b64 25
a9e35095 26#ifdef CONFIG_MUXERS
de6d9b64 27/* simple formats */
ce1d2a95
JR
28static int flac_write_header(struct AVFormatContext *s)
29{
30 static const uint8_t header[8] = {
31 0x66, 0x4C, 0x61, 0x43, 0x80, 0x00, 0x00, 0x22
32 };
33 uint8_t *streaminfo = s->streams[0]->codec->extradata;
34 int len = s->streams[0]->codec->extradata_size;
35 if(streaminfo != NULL && len > 0) {
36 put_buffer(&s->pb, header, 8);
37 put_buffer(&s->pb, streaminfo, len);
38 }
39 return 0;
40}
41
13dec857
VS
42
43static int roq_write_header(struct AVFormatContext *s)
44{
45 static const uint8_t header[] = {
46 0x84, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0x1E, 0x00
47 };
48
49 put_buffer(&s->pb, header, 8);
50 put_flush_packet(&s->pb);
51
52 return 0;
53}
54
e928649b 55static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt)
de6d9b64 56{
e928649b 57 put_buffer(&s->pb, pkt->data, pkt->size);
de6d9b64
FB
58 put_flush_packet(&s->pb);
59 return 0;
60}
a9e35095 61#endif //CONFIG_MUXERS
de6d9b64
FB
62
63/* raw input */
0c1a9eda 64static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
de6d9b64
FB
65{
66 AVStream *st;
c9a65ca8 67 int id;
de6d9b64 68
c9a65ca8 69 st = av_new_stream(s, 0);
de6d9b64 70 if (!st)
769e10f0 71 return AVERROR(ENOMEM);
c04c3282 72
c9a65ca8
FB
73 id = s->iformat->value;
74 if (id == CODEC_ID_RAWVIDEO) {
01f4895c 75 st->codec->codec_type = CODEC_TYPE_VIDEO;
de6d9b64 76 } else {
01f4895c 77 st->codec->codec_type = CODEC_TYPE_AUDIO;
de6d9b64 78 }
01f4895c 79 st->codec->codec_id = id;
c9a65ca8 80
01f4895c 81 switch(st->codec->codec_type) {
de6d9b64 82 case CODEC_TYPE_AUDIO:
01f4895c
MN
83 st->codec->sample_rate = ap->sample_rate;
84 st->codec->channels = ap->channels;
85 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
de6d9b64
FB
86 break;
87 case CODEC_TYPE_VIDEO:
c0df9d75 88 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
01f4895c
MN
89 st->codec->width = ap->width;
90 st->codec->height = ap->height;
91 st->codec->pix_fmt = ap->pix_fmt;
92 if(st->codec->pix_fmt == PIX_FMT_NONE)
93 st->codec->pix_fmt= PIX_FMT_YUV420P;
de6d9b64
FB
94 break;
95 default:
27e084bd 96 return -1;
de6d9b64 97 }
de6d9b64
FB
98 return 0;
99}
100
2e93e3aa 101#define RAW_PACKET_SIZE 1024
de6d9b64 102
5c91a675 103static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
de6d9b64 104{
7866eeff 105 int ret, size;
2a6874fd 106 // AVStream *st = s->streams[0];
115329f1 107
231dd3f3 108 size= RAW_PACKET_SIZE;
de6d9b64 109
2692067a 110 ret= av_get_packet(&s->pb, pkt, size);
de6d9b64
FB
111
112 pkt->stream_index = 0;
2e93e3aa 113 if (ret <= 0) {
6f3e0b21 114 return AVERROR(EIO);
2e93e3aa
FB
115 }
116 /* note: we need to modify the packet size here to handle the last
117 packet */
118 pkt->size = ret;
de6d9b64
FB
119 return ret;
120}
121
e15dec10
LS
122static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
123{
124 int ret, size;
125
126 size = RAW_PACKET_SIZE;
127
128 if (av_new_packet(pkt, size) < 0)
6f3e0b21 129 return AVERROR(EIO);
115329f1 130
2692067a 131 pkt->pos= url_ftell(&s->pb);
e15dec10
LS
132 pkt->stream_index = 0;
133 ret = get_partial_buffer(&s->pb, pkt->data, size);
134 if (ret <= 0) {
135 av_free_packet(pkt);
6f3e0b21 136 return AVERROR(EIO);
e15dec10
LS
137 }
138 pkt->size = ret;
139 return ret;
140}
141
84c63c01
AB
142// http://www.artificis.hu/files/texts/ingenient.txt
143static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt)
144{
145 int ret, size, w, h, unk1, unk2;
115329f1 146
84c63c01 147 if (get_le32(&s->pb) != MKTAG('M', 'J', 'P', 'G'))
6f3e0b21 148 return AVERROR(EIO); // FIXME
84c63c01
AB
149
150 size = get_le32(&s->pb);
115329f1 151
84c63c01
AB
152 w = get_le16(&s->pb);
153 h = get_le16(&s->pb);
115329f1 154
84c63c01
AB
155 url_fskip(&s->pb, 8); // zero + size (padded?)
156 url_fskip(&s->pb, 2);
157 unk1 = get_le16(&s->pb);
158 unk2 = get_le16(&s->pb);
159 url_fskip(&s->pb, 22); // ascii timestamp
115329f1 160
84c63c01 161 av_log(NULL, AV_LOG_DEBUG, "Ingenient packet: size=%d, width=%d, height=%d, unk1=%d unk2=%d\n",
bb270c08 162 size, w, h, unk1, unk2);
84c63c01
AB
163
164 if (av_new_packet(pkt, size) < 0)
6f3e0b21 165 return AVERROR(EIO);
84c63c01
AB
166
167 pkt->pos = url_ftell(&s->pb);
168 pkt->stream_index = 0;
169 ret = get_buffer(&s->pb, pkt->data, size);
170 if (ret <= 0) {
171 av_free_packet(pkt);
6f3e0b21 172 return AVERROR(EIO);
84c63c01
AB
173 }
174 pkt->size = ret;
175 return ret;
176}
177
5c91a675 178static int raw_read_close(AVFormatContext *s)
de6d9b64
FB
179{
180 return 0;
181}
182
115329f1 183int pcm_read_seek(AVFormatContext *s,
7b3c1382 184 int stream_index, int64_t timestamp, int flags)
4986a429
FB
185{
186 AVStream *st;
187 int block_align, byte_rate;
188 int64_t pos;
189
190 st = s->streams[0];
708e3e7d
BC
191
192 block_align = st->codec->block_align ? st->codec->block_align :
193 (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3;
194 byte_rate = st->codec->bit_rate ? st->codec->bit_rate >> 3 :
195 block_align * st->codec->sample_rate;
115329f1 196
4986a429
FB
197 if (block_align <= 0 || byte_rate <= 0)
198 return -1;
199
200 /* compute the position by aligning it to block_align */
115329f1
DB
201 pos = av_rescale_rnd(timestamp * byte_rate,
202 st->time_base.num,
7b3c1382
MN
203 st->time_base.den * (int64_t)block_align,
204 (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
205 pos *= block_align;
4986a429
FB
206
207 /* recompute exact position */
77405fc8 208 st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
4986a429
FB
209 url_fseek(&s->pb, pos + s->data_offset, SEEK_SET);
210 return 0;
211}
212
cd66005d
FB
213/* ac3 read */
214static int ac3_read_header(AVFormatContext *s,
215 AVFormatParameters *ap)
216{
217 AVStream *st;
218
219 st = av_new_stream(s, 0);
220 if (!st)
769e10f0 221 return AVERROR(ENOMEM);
cd66005d 222
01f4895c
MN
223 st->codec->codec_type = CODEC_TYPE_AUDIO;
224 st->codec->codec_id = CODEC_ID_AC3;
57004ff1 225 st->need_parsing = AVSTREAM_PARSE_FULL;
cd66005d
FB
226 /* the parameters will be extracted from the compressed bitstream */
227 return 0;
228}
229
85ad5695
MN
230static int shorten_read_header(AVFormatContext *s,
231 AVFormatParameters *ap)
232{
233 AVStream *st;
234
235 st = av_new_stream(s, 0);
236 if (!st)
769e10f0 237 return AVERROR(ENOMEM);
01f4895c
MN
238 st->codec->codec_type = CODEC_TYPE_AUDIO;
239 st->codec->codec_id = CODEC_ID_SHORTEN;
57004ff1 240 st->need_parsing = AVSTREAM_PARSE_FULL;
85ad5695
MN
241 /* the parameters will be extracted from the compressed bitstream */
242 return 0;
243}
244
89ca8c49
BL
245/* flac read */
246static int flac_read_header(AVFormatContext *s,
247 AVFormatParameters *ap)
248{
249 AVStream *st;
250
251 st = av_new_stream(s, 0);
252 if (!st)
769e10f0 253 return AVERROR(ENOMEM);
89ca8c49
BL
254 st->codec->codec_type = CODEC_TYPE_AUDIO;
255 st->codec->codec_id = CODEC_ID_FLAC;
57004ff1 256 st->need_parsing = AVSTREAM_PARSE_FULL;
89ca8c49
BL
257 /* the parameters will be extracted from the compressed bitstream */
258 return 0;
259}
260
23c99253
MN
261/* dts read */
262static int dts_read_header(AVFormatContext *s,
263 AVFormatParameters *ap)
264{
265 AVStream *st;
266
267 st = av_new_stream(s, 0);
268 if (!st)
769e10f0 269 return AVERROR(ENOMEM);
23c99253 270
01f4895c
MN
271 st->codec->codec_type = CODEC_TYPE_AUDIO;
272 st->codec->codec_id = CODEC_ID_DTS;
57004ff1 273 st->need_parsing = AVSTREAM_PARSE_FULL;
23c99253
MN
274 /* the parameters will be extracted from the compressed bitstream */
275 return 0;
276}
277
fda885c7
MR
278/* aac read */
279static int aac_read_header(AVFormatContext *s,
280 AVFormatParameters *ap)
281{
282 AVStream *st;
283
284 st = av_new_stream(s, 0);
285 if (!st)
769e10f0 286 return AVERROR(ENOMEM);
fda885c7
MR
287
288 st->codec->codec_type = CODEC_TYPE_AUDIO;
289 st->codec->codec_id = CODEC_ID_AAC;
57004ff1 290 st->need_parsing = AVSTREAM_PARSE_FULL;
fda885c7
MR
291 /* the parameters will be extracted from the compressed bitstream */
292 return 0;
293}
294
de6d9b64
FB
295/* mpeg1/h263 input */
296static int video_read_header(AVFormatContext *s,
297 AVFormatParameters *ap)
298{
299 AVStream *st;
300
c9a65ca8 301 st = av_new_stream(s, 0);
de6d9b64 302 if (!st)
769e10f0 303 return AVERROR(ENOMEM);
de6d9b64 304
01f4895c
MN
305 st->codec->codec_type = CODEC_TYPE_VIDEO;
306 st->codec->codec_id = s->iformat->value;
57004ff1 307 st->need_parsing = AVSTREAM_PARSE_FULL;
4986a429 308
27e084bd 309 /* for mjpeg, specify frame rate */
755bfeab 310 /* for mpeg4 specify it too (most mpeg4 streams do not have the fixed_vop_rate set ...)*/
c04c3282 311 if (ap->time_base.num) {
80ce3254 312 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
115329f1 313 } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
01f4895c
MN
314 st->codec->codec_id == CODEC_ID_MPEG4 ||
315 st->codec->codec_id == CODEC_ID_H264) {
80ce3254 316 av_set_pts_info(st, 64, 1, 25);
27e084bd 317 }
80ce3254 318
de6d9b64
FB
319 return 0;
320}
321
bb270c08
DB
322#define SEQ_START_CODE 0x000001b3
323#define GOP_START_CODE 0x000001b8
324#define PICTURE_START_CODE 0x00000100
93d3e278
MN
325#define SLICE_START_CODE 0x00000101
326#define PACK_START_CODE 0x000001ba
e01dc227
MR
327#define VIDEO_ID 0x000001e0
328#define AUDIO_ID 0x000001c0
c9a65ca8 329
c9a65ca8
FB
330static int mpegvideo_probe(AVProbeData *p)
331{
93d3e278 332 uint32_t code= -1;
e01dc227 333 int pic=0, seq=0, slice=0, pspack=0, pes=0;
93d3e278
MN
334 int i;
335
336 for(i=0; i<p->buf_size; i++){
337 code = (code<<8) + p->buf[i];
338 if ((code & 0xffffff00) == 0x100) {
339 switch(code){
340 case SEQ_START_CODE: seq++; break;
341 case PICTURE_START_CODE: pic++; break;
342 case SLICE_START_CODE: slice++; break;
343 case PACK_START_CODE: pspack++; break;
344 }
e9f6c8ea
MN
345 if ((code & 0x1f0) == VIDEO_ID) pes++;
346 else if((code & 0x1e0) == AUDIO_ID) pes++;
93d3e278 347 }
c9a65ca8 348 }
e01dc227 349 if(seq && seq*9<=pic*10 && pic*9<=slice*10 && !pspack && !pes)
93d3e278 350 return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
c9a65ca8
FB
351 return 0;
352}
353
8f57cc5a
TV
354#define VISUAL_OBJECT_START_CODE 0x000001b5
355#define VOP_START_CODE 0x000001b6
356
357static int mpeg4video_probe(AVProbeData *probe_packet)
358{
359 uint32_t temp_buffer= -1;
5fd5d0ef 360 int VO=0, VOL=0, VOP = 0, VISO = 0, res=0;
8f57cc5a
TV
361 int i;
362
363 for(i=0; i<probe_packet->buf_size; i++){
364 temp_buffer = (temp_buffer<<8) + probe_packet->buf[i];
c21f308e
RS
365 if ((temp_buffer & 0xffffff00) != 0x100)
366 continue;
367
368 if (temp_buffer == VOP_START_CODE) VOP++;
369 else if (temp_buffer == VISUAL_OBJECT_START_CODE) VISO++;
370 else if (temp_buffer < 0x120) VO++;
371 else if (temp_buffer < 0x130) VOL++;
372 else if ( !(0x1AF < temp_buffer && temp_buffer < 0x1B7)
373 && !(0x1B9 < temp_buffer && temp_buffer < 0x1C4)) res++;
8f57cc5a
TV
374 }
375
5fd5d0ef 376 if ( VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res==0)
8f57cc5a
TV
377 return AVPROBE_SCORE_MAX/2;
378 return 0;
379}
380
d07f9043
MN
381static int h263_probe(AVProbeData *p)
382{
383 int code;
384 const uint8_t *d;
385
d07f9043
MN
386 d = p->buf;
387 code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2);
388 if (code == 0x20) {
389 return 50;
390 }
391 return 0;
392}
393
c6148de2
MN
394static int h261_probe(AVProbeData *p)
395{
396 int code;
397 const uint8_t *d;
398
c6148de2
MN
399 d = p->buf;
400 code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4);
401 if (code == 0x10) {
402 return 50;
403 }
404 return 0;
405}
406
7156aeb9
JR
407static int ac3_probe(AVProbeData *p)
408{
8c222bb4 409 int max_frames, first_frames = 0, frames;
f8b9830b
JR
410 uint8_t *buf, *buf2, *end;
411 AC3HeaderInfo hdr;
7156aeb9 412
f8b9830b
JR
413 max_frames = 0;
414 buf = p->buf;
ecc8fc11 415 end = buf + p->buf_size;
f8b9830b
JR
416
417 for(; buf < end; buf++) {
418 buf2 = buf;
7156aeb9 419
f8b9830b
JR
420 for(frames = 0; buf2 < end; frames++) {
421 if(ff_ac3_parse_header(buf2, &hdr) < 0)
422 break;
423 buf2 += hdr.frame_size;
424 }
425 max_frames = FFMAX(max_frames, frames);
426 if(buf == p->buf)
427 first_frames = frames;
428 }
429 if (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4;
2477ce23 430 else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2;
f8b9830b
JR
431 else if(max_frames>=1) return 1;
432 else return 0;
7156aeb9
JR
433}
434
e020dbd2
MN
435static int flac_probe(AVProbeData *p)
436{
437 if(memcmp(p->buf, "fLaC", 4)) return 0;
fbd69f51 438 else return AVPROBE_SCORE_MAX / 2;
e020dbd2
MN
439}
440
d2a067d1 441AVInputFormat shorten_demuxer = {
85ad5695 442 "shn",
84c63c01 443 "raw shorten",
85ad5695
MN
444 0,
445 NULL,
446 shorten_read_header,
447 raw_read_partial_packet,
448 raw_read_close,
e9b78eeb 449 .flags= AVFMT_GENERIC_INDEX,
85ad5695
MN
450 .extensions = "shn",
451};
452
d2a067d1 453AVInputFormat flac_demuxer = {
89ca8c49
BL
454 "flac",
455 "raw flac",
456 0,
e020dbd2 457 flac_probe,
89ca8c49
BL
458 flac_read_header,
459 raw_read_partial_packet,
460 raw_read_close,
e9b78eeb 461 .flags= AVFMT_GENERIC_INDEX,
89ca8c49
BL
462 .extensions = "flac",
463};
464
ce1d2a95 465#ifdef CONFIG_MUXERS
d2a067d1 466AVOutputFormat flac_muxer = {
ce1d2a95
JR
467 "flac",
468 "raw flac",
469 "audio/x-flac",
470 "flac",
471 0,
472 CODEC_ID_FLAC,
473 0,
474 flac_write_header,
475 raw_write_packet,
494bbf58 476 .flags= AVFMT_NOTIMESTAMPS,
ce1d2a95
JR
477};
478#endif //CONFIG_MUXERS
479
cefd4907 480#ifdef CONFIG_AC3_DEMUXER
d2a067d1 481AVInputFormat ac3_demuxer = {
c9a65ca8
FB
482 "ac3",
483 "raw ac3",
484 0,
7156aeb9 485 ac3_probe,
cd66005d 486 ac3_read_header,
e15dec10 487 raw_read_partial_packet,
de6d9b64 488 raw_read_close,
e9b78eeb 489 .flags= AVFMT_GENERIC_INDEX,
bb76a117 490 .extensions = "ac3",
de6d9b64 491};
cefd4907 492#endif
de6d9b64 493
a9e35095 494#ifdef CONFIG_MUXERS
d2a067d1 495AVOutputFormat ac3_muxer = {
de6d9b64
FB
496 "ac3",
497 "raw ac3",
115329f1 498 "audio/x-ac3",
de6d9b64 499 "ac3",
c9a65ca8 500 0,
de6d9b64
FB
501 CODEC_ID_AC3,
502 0,
7a97dd84 503 NULL,
de6d9b64 504 raw_write_packet,
494bbf58 505 .flags= AVFMT_NOTIMESTAMPS,
de6d9b64 506};
a9e35095 507#endif //CONFIG_MUXERS
de6d9b64 508
d2a067d1 509AVInputFormat dts_demuxer = {
23c99253
MN
510 "dts",
511 "raw dts",
512 0,
513 NULL,
514 dts_read_header,
515 raw_read_partial_packet,
516 raw_read_close,
e9b78eeb 517 .flags= AVFMT_GENERIC_INDEX,
23c99253
MN
518 .extensions = "dts",
519};
520
d2a067d1 521AVInputFormat aac_demuxer = {
fda885c7
MR
522 "aac",
523 "ADTS AAC",
524 0,
525 NULL,
526 aac_read_header,
527 raw_read_partial_packet,
528 raw_read_close,
e9b78eeb 529 .flags= AVFMT_GENERIC_INDEX,
fda885c7
MR
530 .extensions = "aac",
531};
532
13dec857
VS
533#ifdef CONFIG_ROQ_MUXER
534AVOutputFormat roq_muxer =
535{
536 "RoQ",
537 "Id RoQ format",
538 NULL,
539 "roq",
540 0,
541 CODEC_ID_ROQ_DPCM,
542 CODEC_ID_ROQ,
543 roq_write_header,
544 raw_write_packet,
13dec857
VS
545};
546#endif //CONFIG_ROQ_MUXER
547
d2a067d1 548AVInputFormat h261_demuxer = {
c6148de2
MN
549 "h261",
550 "raw h261",
551 0,
552 h261_probe,
553 video_read_header,
554 raw_read_partial_packet,
555 raw_read_close,
e9b78eeb 556 .flags= AVFMT_GENERIC_INDEX,
c6148de2
MN
557 .extensions = "h261",
558 .value = CODEC_ID_H261,
559};
560
a9e35095 561#ifdef CONFIG_MUXERS
d2a067d1 562AVOutputFormat h261_muxer = {
1c3990db
MN
563 "h261",
564 "raw h261",
565 "video/x-h261",
566 "h261",
567 0,
568 0,
569 CODEC_ID_H261,
7a97dd84 570 NULL,
1c3990db 571 raw_write_packet,
494bbf58 572 .flags= AVFMT_NOTIMESTAMPS,
1c3990db 573};
a9e35095 574#endif //CONFIG_MUXERS
1c3990db 575
d2a067d1 576AVInputFormat h263_demuxer = {
d07f9043
MN
577 "h263",
578 "raw h263",
579 0,
580 h263_probe,
581 video_read_header,
e15dec10 582 raw_read_partial_packet,
d07f9043 583 raw_read_close,
e9b78eeb 584 .flags= AVFMT_GENERIC_INDEX,
d07f9043
MN
585// .extensions = "h263", //FIXME remove after writing mpeg4_probe
586 .value = CODEC_ID_H263,
587};
588
a9e35095 589#ifdef CONFIG_MUXERS
d2a067d1 590AVOutputFormat h263_muxer = {
de6d9b64
FB
591 "h263",
592 "raw h263",
593 "video/x-h263",
594 "h263",
595 0,
c9a65ca8 596 0,
de6d9b64 597 CODEC_ID_H263,
7a97dd84 598 NULL,
de6d9b64 599 raw_write_packet,
494bbf58 600 .flags= AVFMT_NOTIMESTAMPS,
c9a65ca8 601};
a9e35095 602#endif //CONFIG_MUXERS
c9a65ca8 603
d2a067d1 604AVInputFormat m4v_demuxer = {
7866eeff
MN
605 "m4v",
606 "raw MPEG4 video format",
607 0,
8f57cc5a 608 mpeg4video_probe, /** probing for mpeg4 data */
7866eeff 609 video_read_header,
e15dec10 610 raw_read_partial_packet,
7866eeff 611 raw_read_close,
e9b78eeb 612 .flags= AVFMT_GENERIC_INDEX,
bb76a117
MR
613 .extensions = "m4v", //FIXME remove after writing mpeg4_probe
614 .value = CODEC_ID_MPEG4,
7866eeff
MN
615};
616
a9e35095 617#ifdef CONFIG_MUXERS
d2a067d1 618AVOutputFormat m4v_muxer = {
89b3d7c9
MK
619 "m4v",
620 "raw MPEG4 video format",
621 NULL,
622 "m4v",
623 0,
624 CODEC_ID_NONE,
625 CODEC_ID_MPEG4,
7a97dd84 626 NULL,
89b3d7c9 627 raw_write_packet,
494bbf58 628 .flags= AVFMT_NOTIMESTAMPS,
89b3d7c9 629};
a9e35095 630#endif //CONFIG_MUXERS
89b3d7c9 631
d2a067d1 632AVInputFormat h264_demuxer = {
0da71265
MN
633 "h264",
634 "raw H264 video format",
635 0,
636 NULL /*mpegvideo_probe*/,
637 video_read_header,
e15dec10 638 raw_read_partial_packet,
0da71265 639 raw_read_close,
e9b78eeb 640 .flags= AVFMT_GENERIC_INDEX,
ba5697d5 641 .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
0da71265
MN
642 .value = CODEC_ID_H264,
643};
644
a9e35095 645#ifdef CONFIG_MUXERS
d2a067d1 646AVOutputFormat h264_muxer = {
0da71265
MN
647 "h264",
648 "raw H264 video format",
649 NULL,
650 "h264",
651 0,
652 CODEC_ID_NONE,
653 CODEC_ID_H264,
7a97dd84 654 NULL,
0da71265 655 raw_write_packet,
494bbf58 656 .flags= AVFMT_NOTIMESTAMPS,
0da71265 657};
a9e35095 658#endif //CONFIG_MUXERS
0da71265 659
d2a067d1 660AVInputFormat mpegvideo_demuxer = {
c9a65ca8
FB
661 "mpegvideo",
662 "MPEG video",
663 0,
664 mpegvideo_probe,
de6d9b64 665 video_read_header,
e15dec10 666 raw_read_partial_packet,
de6d9b64 667 raw_read_close,
e9b78eeb 668 .flags= AVFMT_GENERIC_INDEX,
bb76a117 669 .value = CODEC_ID_MPEG1VIDEO,
de6d9b64
FB
670};
671
a9e35095 672#ifdef CONFIG_MUXERS
d2a067d1 673AVOutputFormat mpeg1video_muxer = {
c9a65ca8 674 "mpeg1video",
de6d9b64
FB
675 "MPEG video",
676 "video/x-mpeg",
e0827ba4 677 "mpg,mpeg,m1v",
de6d9b64 678 0,
c9a65ca8 679 0,
de6d9b64 680 CODEC_ID_MPEG1VIDEO,
7a97dd84 681 NULL,
de6d9b64 682 raw_write_packet,
494bbf58 683 .flags= AVFMT_NOTIMESTAMPS,
de6d9b64 684};
a9e35095 685#endif //CONFIG_MUXERS
de6d9b64 686
a9e35095 687#ifdef CONFIG_MUXERS
d2a067d1 688AVOutputFormat mpeg2video_muxer = {
6ec864da
MN
689 "mpeg2video",
690 "MPEG2 video",
691 NULL,
692 "m2v",
693 0,
694 0,
695 CODEC_ID_MPEG2VIDEO,
7a97dd84 696 NULL,
6ec864da 697 raw_write_packet,
494bbf58 698 .flags= AVFMT_NOTIMESTAMPS,
6ec864da 699};
a9e35095 700#endif //CONFIG_MUXERS
6ec864da 701
d2a067d1 702AVInputFormat mjpeg_demuxer = {
27e084bd
FB
703 "mjpeg",
704 "MJPEG video",
27e084bd 705 0,
c9a65ca8 706 NULL,
27e084bd 707 video_read_header,
e15dec10 708 raw_read_partial_packet,
27e084bd 709 raw_read_close,
e9b78eeb 710 .flags= AVFMT_GENERIC_INDEX,
bb76a117
MR
711 .extensions = "mjpg,mjpeg",
712 .value = CODEC_ID_MJPEG,
27e084bd
FB
713};
714
d2a067d1 715AVInputFormat ingenient_demuxer = {
84c63c01
AB
716 "ingenient",
717 "Ingenient MJPEG",
718 0,
719 NULL,
720 video_read_header,
721 ingenient_read_packet,
722 raw_read_close,
e9b78eeb 723 .flags= AVFMT_GENERIC_INDEX,
84c63c01
AB
724 .extensions = "cgi", // FIXME
725 .value = CODEC_ID_MJPEG,
726};
727
a9e35095 728#ifdef CONFIG_MUXERS
d2a067d1 729AVOutputFormat mjpeg_muxer = {
c9a65ca8
FB
730 "mjpeg",
731 "MJPEG video",
732 "video/x-mjpeg",
733 "mjpg,mjpeg",
5ed8fafc 734 0,
5ed8fafc 735 0,
c9a65ca8 736 CODEC_ID_MJPEG,
7a97dd84 737 NULL,
5ed8fafc 738 raw_write_packet,
494bbf58 739 .flags= AVFMT_NOTIMESTAMPS,
5ed8fafc 740};
a9e35095 741#endif //CONFIG_MUXERS
5ed8fafc 742
7bb5c2a6
KS
743AVInputFormat vc1_demuxer = {
744 "vc1",
745 "raw vc1",
746 0,
747 NULL /* vc1_probe */,
748 video_read_header,
749 raw_read_partial_packet,
750 raw_read_close,
751 .extensions = "vc1",
752 .value = CODEC_ID_VC1,
753};
754
c9a65ca8 755/* pcm formats */
764ef400 756
4986a429 757#define PCMINPUTDEF(name, long_name, ext, codec) \
d2a067d1 758AVInputFormat pcm_ ## name ## _demuxer = {\
764ef400
MM
759 #name,\
760 long_name,\
761 0,\
762 NULL,\
763 raw_read_header,\
764 raw_read_packet,\
765 raw_read_close,\
4986a429 766 pcm_read_seek,\
e9b78eeb 767 .flags= AVFMT_GENERIC_INDEX,\
764ef400
MM
768 .extensions = ext,\
769 .value = codec,\
770};
771
2c8e2014 772#define PCMOUTPUTDEF(name, long_name, ext, codec) \
d2a067d1 773AVOutputFormat pcm_ ## name ## _muxer = {\
c9a65ca8
FB
774 #name,\
775 long_name,\
776 NULL,\
777 ext,\
778 0,\
779 codec,\
780 0,\
7a97dd84 781 NULL,\
c9a65ca8 782 raw_write_packet,\
494bbf58 783 .flags= AVFMT_NOTIMESTAMPS,\
5ed8fafc 784};
2c8e2014
DB
785
786
787#if !defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
788#define PCMDEF(name, long_name, ext, codec) \
789 PCMINPUTDEF(name, long_name, ext, codec)
790#elif defined(CONFIG_MUXERS) && !defined(CONFIG_DEMUXERS)
791#define PCMDEF(name, long_name, ext, codec) \
792 PCMOUTPUTDEF(name, long_name, ext, codec)
793#elif defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
794#define PCMDEF(name, long_name, ext, codec) \
795 PCMINPUTDEF(name, long_name, ext, codec)\
796 PCMOUTPUTDEF(name, long_name, ext, codec)
797#else
798#define PCMDEF(name, long_name, ext, codec)
799#endif
5ed8fafc 800
5ed8fafc 801#ifdef WORDS_BIGENDIAN
c9a65ca8
FB
802#define BE_DEF(s) s
803#define LE_DEF(s) NULL
5ed8fafc 804#else
c9a65ca8
FB
805#define BE_DEF(s) NULL
806#define LE_DEF(s) s
5ed8fafc 807#endif
5ed8fafc 808
5ed8fafc 809
115329f1 810PCMDEF(s16le, "pcm signed 16 bit little endian format",
c9a65ca8 811 LE_DEF("sw"), CODEC_ID_PCM_S16LE)
5ed8fafc 812
115329f1 813PCMDEF(s16be, "pcm signed 16 bit big endian format",
c9a65ca8 814 BE_DEF("sw"), CODEC_ID_PCM_S16BE)
5ed8fafc 815
115329f1 816PCMDEF(u16le, "pcm unsigned 16 bit little endian format",
c9a65ca8 817 LE_DEF("uw"), CODEC_ID_PCM_U16LE)
5ed8fafc 818
115329f1 819PCMDEF(u16be, "pcm unsigned 16 bit big endian format",
c9a65ca8 820 BE_DEF("uw"), CODEC_ID_PCM_U16BE)
5ed8fafc 821
115329f1 822PCMDEF(s8, "pcm signed 8 bit format",
c9a65ca8 823 "sb", CODEC_ID_PCM_S8)
5ed8fafc 824
115329f1 825PCMDEF(u8, "pcm unsigned 8 bit format",
c9a65ca8 826 "ub", CODEC_ID_PCM_U8)
5ed8fafc 827
115329f1 828PCMDEF(mulaw, "pcm mu law format",
c9a65ca8 829 "ul", CODEC_ID_PCM_MULAW)
de6d9b64 830
115329f1 831PCMDEF(alaw, "pcm A law format",
c9a65ca8 832 "al", CODEC_ID_PCM_ALAW)
de6d9b64 833
5c91a675 834static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
de6d9b64
FB
835{
836 int packet_size, ret, width, height;
837 AVStream *st = s->streams[0];
838
01f4895c
MN
839 width = st->codec->width;
840 height = st->codec->height;
de6d9b64 841
01f4895c 842 packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
63167088 843 if (packet_size < 0)
71c32f19 844 return -1;
de6d9b64 845
2692067a 846 ret= av_get_packet(&s->pb, pkt, packet_size);
de6d9b64
FB
847
848 pkt->stream_index = 0;
2692067a 849 if (ret != packet_size) {
6f3e0b21 850 return AVERROR(EIO);
de6d9b64
FB
851 } else {
852 return 0;
853 }
854}
855
d2a067d1 856AVInputFormat rawvideo_demuxer = {
c9a65ca8
FB
857 "rawvideo",
858 "raw video format",
859 0,
860 NULL,
861 raw_read_header,
862 rawvideo_read_packet,
863 raw_read_close,
e9b78eeb 864 .flags= AVFMT_GENERIC_INDEX,
5faf2d36 865 .extensions = "yuv,cif,qcif,rgb",
bb76a117 866 .value = CODEC_ID_RAWVIDEO,
c9a65ca8
FB
867};
868
a9e35095 869#ifdef CONFIG_MUXERS
d2a067d1 870AVOutputFormat rawvideo_muxer = {
de6d9b64
FB
871 "rawvideo",
872 "raw video format",
873 NULL,
b47f86c4 874 "yuv,rgb",
c9a65ca8 875 0,
de6d9b64
FB
876 CODEC_ID_NONE,
877 CODEC_ID_RAWVIDEO,
7a97dd84 878 NULL,
de6d9b64 879 raw_write_packet,
494bbf58 880 .flags= AVFMT_NOTIMESTAMPS,
de6d9b64 881};
a9e35095 882#endif //CONFIG_MUXERS
c9a65ca8 883
a9e35095 884#ifdef CONFIG_MUXERS
e928649b 885static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
87bdd3e5
FB
886{
887 return 0;
888}
889
d2a067d1 890AVOutputFormat null_muxer = {
87bdd3e5
FB
891 "null",
892 "null video format",
893 NULL,
894 NULL,
895 0,
896#ifdef WORDS_BIGENDIAN
897 CODEC_ID_PCM_S16BE,
898#else
899 CODEC_ID_PCM_S16LE,
900#endif
901 CODEC_ID_RAWVIDEO,
7a97dd84 902 NULL,
87bdd3e5 903 null_write_packet,
494bbf58 904 .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
87bdd3e5 905};
a9e35095 906#endif //CONFIG_MUXERS