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