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