fe6f6e40c306d0674134803931066265e87f819c
[ffmpeg.git] / libavformat / raw.c
1 /*
2  * RAW muxer and demuxer
3  * Copyright (c) 2001 Fabrice Bellard
4  * Copyright (c) 2005 Alex Beregszaszi
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22
23 #include "libavutil/crc.h"
24 #include "libavcodec/ac3_parser.h"
25 #include "libavcodec/bitstream.h"
26 #include "libavcodec/bytestream.h"
27 #include "avformat.h"
28 #include "raw.h"
29 #include "id3v2.h"
30
31 /* simple formats */
32 #if CONFIG_FLAC_MUXER
33 static int flac_write_header(struct AVFormatContext *s)
34 {
35     static const uint8_t header[8] = {
36         0x66, 0x4C, 0x61, 0x43, 0x80, 0x00, 0x00, 0x22
37     };
38     uint8_t *streaminfo = s->streams[0]->codec->extradata;
39     int len = s->streams[0]->codec->extradata_size;
40     if(streaminfo != NULL && len > 0) {
41         put_buffer(s->pb, header, 8);
42         put_buffer(s->pb, streaminfo, len);
43     }
44     return 0;
45 }
46
47 static int flac_write_trailer(struct AVFormatContext *s)
48 {
49     ByteIOContext *pb = s->pb;
50     uint8_t *streaminfo = s->streams[0]->codec->extradata;
51     int len = s->streams[0]->codec->extradata_size;
52     int64_t file_size;
53
54     if (streaminfo && len > 0 && !url_is_streamed(s->pb)) {
55         file_size = url_ftell(pb);
56         url_fseek(pb, 8, SEEK_SET);
57         put_buffer(pb, streaminfo, len);
58         url_fseek(pb, file_size, SEEK_SET);
59         put_flush_packet(pb);
60     }
61     return 0;
62 }
63 #endif
64
65 #if CONFIG_ROQ_MUXER
66 static int roq_write_header(struct AVFormatContext *s)
67 {
68     static const uint8_t header[] = {
69         0x84, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0x1E, 0x00
70     };
71
72     put_buffer(s->pb, header, 8);
73     put_flush_packet(s->pb);
74
75     return 0;
76 }
77 #endif
78
79 #if CONFIG_NULL_MUXER
80 static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
81 {
82     return 0;
83 }
84 #endif
85
86 #if CONFIG_MUXERS
87 static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt)
88 {
89     put_buffer(s->pb, pkt->data, pkt->size);
90     put_flush_packet(s->pb);
91     return 0;
92 }
93 #endif
94
95 #if CONFIG_DEMUXERS
96 /* raw input */
97 static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
98 {
99     AVStream *st;
100     int id;
101
102     st = av_new_stream(s, 0);
103     if (!st)
104         return AVERROR(ENOMEM);
105
106         id = s->iformat->value;
107         if (id == CODEC_ID_RAWVIDEO) {
108             st->codec->codec_type = CODEC_TYPE_VIDEO;
109         } else {
110             st->codec->codec_type = CODEC_TYPE_AUDIO;
111         }
112         st->codec->codec_id = id;
113
114         switch(st->codec->codec_type) {
115         case CODEC_TYPE_AUDIO:
116             st->codec->sample_rate = ap->sample_rate;
117             if(ap->channels) st->codec->channels = ap->channels;
118             else             st->codec->channels = 1;
119             av_set_pts_info(st, 64, 1, st->codec->sample_rate);
120             break;
121         case CODEC_TYPE_VIDEO:
122             if(ap->time_base.num)
123                 av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
124             else
125                 av_set_pts_info(st, 64, 1, 25);
126             st->codec->width = ap->width;
127             st->codec->height = ap->height;
128             st->codec->pix_fmt = ap->pix_fmt;
129             if(st->codec->pix_fmt == PIX_FMT_NONE)
130                 st->codec->pix_fmt= PIX_FMT_YUV420P;
131             break;
132         default:
133             return -1;
134         }
135     return 0;
136 }
137
138 #define RAW_PACKET_SIZE 1024
139
140 static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
141 {
142     int ret, size, bps;
143     //    AVStream *st = s->streams[0];
144
145     size= RAW_PACKET_SIZE;
146
147     ret= av_get_packet(s->pb, pkt, size);
148
149     pkt->stream_index = 0;
150     if (ret <= 0) {
151         return AVERROR(EIO);
152     }
153     /* note: we need to modify the packet size here to handle the last
154        packet */
155     pkt->size = ret;
156
157     bps= av_get_bits_per_sample(s->streams[0]->codec->codec_id);
158     assert(bps); // if false there IS a bug elsewhere (NOT in this function)
159     pkt->dts=
160     pkt->pts= pkt->pos*8 / (bps * s->streams[0]->codec->channels);
161
162     return ret;
163 }
164
165 static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
166 {
167     int ret, size;
168
169     size = RAW_PACKET_SIZE;
170
171     if (av_new_packet(pkt, size) < 0)
172         return AVERROR(EIO);
173
174     pkt->pos= url_ftell(s->pb);
175     pkt->stream_index = 0;
176     ret = get_partial_buffer(s->pb, pkt->data, size);
177     if (ret <= 0) {
178         av_free_packet(pkt);
179         return AVERROR(EIO);
180     }
181     pkt->size = ret;
182     return ret;
183 }
184 #endif
185
186 #if CONFIG_RAWVIDEO_DEMUXER
187 static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
188 {
189     int packet_size, ret, width, height;
190     AVStream *st = s->streams[0];
191
192     width = st->codec->width;
193     height = st->codec->height;
194
195     packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
196     if (packet_size < 0)
197         return -1;
198
199     ret= av_get_packet(s->pb, pkt, packet_size);
200     pkt->pts=
201     pkt->dts= pkt->pos / packet_size;
202
203     pkt->stream_index = 0;
204     if (ret != packet_size) {
205         return AVERROR(EIO);
206     } else {
207         return 0;
208     }
209 }
210 #endif
211
212 #if CONFIG_INGENIENT_DEMUXER
213 // http://www.artificis.hu/files/texts/ingenient.txt
214 static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt)
215 {
216     int ret, size, w, h, unk1, unk2;
217
218     if (get_le32(s->pb) != MKTAG('M', 'J', 'P', 'G'))
219         return AVERROR(EIO); // FIXME
220
221     size = get_le32(s->pb);
222
223     w = get_le16(s->pb);
224     h = get_le16(s->pb);
225
226     url_fskip(s->pb, 8); // zero + size (padded?)
227     url_fskip(s->pb, 2);
228     unk1 = get_le16(s->pb);
229     unk2 = get_le16(s->pb);
230     url_fskip(s->pb, 22); // ASCII timestamp
231
232     av_log(NULL, AV_LOG_DEBUG, "Ingenient packet: size=%d, width=%d, height=%d, unk1=%d unk2=%d\n",
233         size, w, h, unk1, unk2);
234
235     if (av_new_packet(pkt, size) < 0)
236         return AVERROR(EIO);
237
238     pkt->pos = url_ftell(s->pb);
239     pkt->stream_index = 0;
240     ret = get_buffer(s->pb, pkt->data, size);
241     if (ret <= 0) {
242         av_free_packet(pkt);
243         return AVERROR(EIO);
244     }
245     pkt->size = ret;
246     return ret;
247 }
248 #endif
249
250 #if CONFIG_DEMUXERS
251 int pcm_read_seek(AVFormatContext *s,
252                   int stream_index, int64_t timestamp, int flags)
253 {
254     AVStream *st;
255     int block_align, byte_rate, ret;
256     int64_t pos;
257
258     st = s->streams[0];
259
260     block_align = st->codec->block_align ? st->codec->block_align :
261         (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3;
262     byte_rate = st->codec->bit_rate ? st->codec->bit_rate >> 3 :
263         block_align * st->codec->sample_rate;
264
265     if (block_align <= 0 || byte_rate <= 0)
266         return -1;
267
268     /* compute the position by aligning it to block_align */
269     pos = av_rescale_rnd(timestamp * byte_rate,
270                          st->time_base.num,
271                          st->time_base.den * (int64_t)block_align,
272                          (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
273     pos *= block_align;
274
275     /* recompute exact position */
276     st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
277     if ((ret = url_fseek(s->pb, pos + s->data_offset, SEEK_SET)) < 0)
278         return ret;
279     return 0;
280 }
281
282 static int audio_read_header(AVFormatContext *s,
283                              AVFormatParameters *ap)
284 {
285     AVStream *st = av_new_stream(s, 0);
286     if (!st)
287         return AVERROR(ENOMEM);
288     st->codec->codec_type = CODEC_TYPE_AUDIO;
289     st->codec->codec_id = s->iformat->value;
290     st->need_parsing = AVSTREAM_PARSE_FULL;
291     /* the parameters will be extracted from the compressed bitstream */
292     return 0;
293 }
294
295 /* MPEG-1/H.263 input */
296 static int video_read_header(AVFormatContext *s,
297                              AVFormatParameters *ap)
298 {
299     AVStream *st;
300
301     st = av_new_stream(s, 0);
302     if (!st)
303         return AVERROR(ENOMEM);
304
305     st->codec->codec_type = CODEC_TYPE_VIDEO;
306     st->codec->codec_id = s->iformat->value;
307     st->need_parsing = AVSTREAM_PARSE_FULL;
308
309     /* for MJPEG, specify frame rate */
310     /* for MPEG-4 specify it, too (most MPEG-4 streams do not have the fixed_vop_rate set ...)*/
311     if (ap->time_base.num) {
312         av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
313     } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
314                 st->codec->codec_id == CODEC_ID_MPEG4 ||
315                 st->codec->codec_id == CODEC_ID_DIRAC ||
316                 st->codec->codec_id == CODEC_ID_H264) {
317         av_set_pts_info(st, 64, 1, 25);
318     }
319
320     return 0;
321 }
322 #endif
323
324 #if CONFIG_MPEGVIDEO_DEMUXER
325 #define SEQ_START_CODE          0x000001b3
326 #define GOP_START_CODE          0x000001b8
327 #define PICTURE_START_CODE      0x00000100
328 #define SLICE_START_CODE        0x00000101
329 #define PACK_START_CODE         0x000001ba
330 #define VIDEO_ID                0x000001e0
331 #define AUDIO_ID                0x000001c0
332
333 static int mpegvideo_probe(AVProbeData *p)
334 {
335     uint32_t code= -1;
336     int pic=0, seq=0, slice=0, pspack=0, pes=0;
337     int i;
338
339     for(i=0; i<p->buf_size; i++){
340         code = (code<<8) + p->buf[i];
341         if ((code & 0xffffff00) == 0x100) {
342             switch(code){
343             case     SEQ_START_CODE:   seq++; break;
344             case PICTURE_START_CODE:   pic++; break;
345             case   SLICE_START_CODE: slice++; break;
346             case    PACK_START_CODE: pspack++; break;
347             }
348             if     ((code & 0x1f0) == VIDEO_ID)   pes++;
349             else if((code & 0x1e0) == AUDIO_ID)   pes++;
350         }
351     }
352     if(seq && seq*9<=pic*10 && pic*9<=slice*10 && !pspack && !pes)
353         return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
354     return 0;
355 }
356 #endif
357
358 #if CONFIG_M4V_DEMUXER
359 #define VISUAL_OBJECT_START_CODE       0x000001b5
360 #define VOP_START_CODE                 0x000001b6
361
362 static int mpeg4video_probe(AVProbeData *probe_packet)
363 {
364     uint32_t temp_buffer= -1;
365     int VO=0, VOL=0, VOP = 0, VISO = 0, res=0;
366     int i;
367
368     for(i=0; i<probe_packet->buf_size; i++){
369         temp_buffer = (temp_buffer<<8) + probe_packet->buf[i];
370         if ((temp_buffer & 0xffffff00) != 0x100)
371             continue;
372
373         if (temp_buffer == VOP_START_CODE)                         VOP++;
374         else if (temp_buffer == VISUAL_OBJECT_START_CODE)          VISO++;
375         else if (temp_buffer < 0x120)                              VO++;
376         else if (temp_buffer < 0x130)                              VOL++;
377         else if (   !(0x1AF < temp_buffer && temp_buffer < 0x1B7)
378                  && !(0x1B9 < temp_buffer && temp_buffer < 0x1C4)) res++;
379     }
380
381     if ( VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res==0)
382         return AVPROBE_SCORE_MAX/2;
383     return 0;
384 }
385 #endif
386
387 #if CONFIG_H264_DEMUXER
388 static int h264_probe(AVProbeData *p)
389 {
390     uint32_t code= -1;
391     int sps=0, pps=0, idr=0, res=0, sli=0;
392     int i;
393
394     for(i=0; i<p->buf_size; i++){
395         code = (code<<8) + p->buf[i];
396         if ((code & 0xffffff00) == 0x100) {
397             int ref_idc= (code>>5)&3;
398             int type   = code & 0x1F;
399             static const int8_t ref_zero[32]={
400                 2, 0, 0, 0, 0,-1, 1,-1,
401                -1, 1, 1, 1, 1,-1, 2, 2,
402                 2, 2, 2, 0, 2, 2, 2, 2,
403                 2, 2, 2, 2, 2, 2, 2, 2
404             };
405
406             if(code & 0x80) //forbidden bit
407                 return 0;
408
409             if(ref_zero[type] == 1 && ref_idc)
410                 return 0;
411             if(ref_zero[type] ==-1 && !ref_idc)
412                 return 0;
413             if(ref_zero[type] == 2)
414                 res++;
415
416             switch(type){
417             case     1:   sli++; break;
418             case     5:   idr++; break;
419             case     7:
420                 if(p->buf[i+2]&0x0F)
421                     return 0;
422                 sps++;
423                 break;
424             case     8:   pps++; break;
425             }
426         }
427     }
428     if(sps && pps && (idr||sli>3) && res<(sps+pps+idr))
429         return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
430     return 0;
431 }
432 #endif
433
434 #if CONFIG_H263_DEMUXER
435 static int h263_probe(AVProbeData *p)
436 {
437     int code;
438     const uint8_t *d;
439
440     d = p->buf;
441     code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2);
442     if (code == 0x20) {
443         return 50;
444     }
445     return 0;
446 }
447 #endif
448
449 #if CONFIG_H261_DEMUXER
450 static int h261_probe(AVProbeData *p)
451 {
452     int code;
453     const uint8_t *d;
454
455     d = p->buf;
456     code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4);
457     if (code == 0x10) {
458         return 50;
459     }
460     return 0;
461 }
462 #endif
463
464 #if CONFIG_DTS_DEMUXER
465 #define DCA_MARKER_14B_BE 0x1FFFE800
466 #define DCA_MARKER_14B_LE 0xFF1F00E8
467 #define DCA_MARKER_RAW_BE 0x7FFE8001
468 #define DCA_MARKER_RAW_LE 0xFE7F0180
469 static int dts_probe(AVProbeData *p)
470 {
471     const uint8_t *buf, *bufp;
472     uint32_t state = -1;
473
474     buf = p->buf;
475
476     for(; buf < (p->buf+p->buf_size)-2; buf+=2) {
477         bufp = buf;
478         state = (state << 16) | bytestream_get_be16(&bufp);
479
480         /* regular bitstream */
481         if (state == DCA_MARKER_RAW_BE || state == DCA_MARKER_RAW_LE)
482             return AVPROBE_SCORE_MAX/2+1;
483
484         /* 14 bits big-endian bitstream */
485         if (state == DCA_MARKER_14B_BE)
486             if ((bytestream_get_be16(&bufp) & 0xFFF0) == 0x07F0)
487                 return AVPROBE_SCORE_MAX/2+1;
488
489         /* 14 bits little-endian bitstream */
490         if (state == DCA_MARKER_14B_LE)
491             if ((bytestream_get_be16(&bufp) & 0xF0FF) == 0xF007)
492                 return AVPROBE_SCORE_MAX/2+1;
493     }
494
495     return 0;
496 }
497 #endif
498
499 #if CONFIG_DIRAC_DEMUXER
500 static int dirac_probe(AVProbeData *p)
501 {
502     if (AV_RL32(p->buf) == MKTAG('B', 'B', 'C', 'D'))
503         return AVPROBE_SCORE_MAX;
504     else
505         return 0;
506 }
507 #endif
508
509 #if CONFIG_DNXHD_DEMUXER
510 static int dnxhd_probe(AVProbeData *p)
511 {
512     static const uint8_t header[] = {0x00,0x00,0x02,0x80,0x01};
513     if (!memcmp(p->buf, header, 5))
514         return AVPROBE_SCORE_MAX;
515     else
516         return 0;
517 }
518 #endif
519
520 #if CONFIG_AC3_DEMUXER || CONFIG_EAC3_DEMUXER
521 static int ac3_eac3_probe(AVProbeData *p, enum CodecID expected_codec_id)
522 {
523     int max_frames, first_frames = 0, frames;
524     uint8_t *buf, *buf2, *end;
525     AC3HeaderInfo hdr;
526     GetBitContext gbc;
527     enum CodecID codec_id = CODEC_ID_AC3;
528
529     max_frames = 0;
530     buf = p->buf;
531     end = buf + p->buf_size;
532
533     for(; buf < end; buf++) {
534         buf2 = buf;
535
536         for(frames = 0; buf2 < end; frames++) {
537             init_get_bits(&gbc, buf2, 54);
538             if(ff_ac3_parse_header(&gbc, &hdr) < 0)
539                 break;
540             if(buf2 + hdr.frame_size > end ||
541                av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2))
542                 break;
543             if (hdr.bitstream_id > 10)
544                 codec_id = CODEC_ID_EAC3;
545             buf2 += hdr.frame_size;
546         }
547         max_frames = FFMAX(max_frames, frames);
548         if(buf == p->buf)
549             first_frames = frames;
550     }
551     if(codec_id != expected_codec_id) return 0;
552     if   (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4;
553     else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2;
554     else if(max_frames>=1) return 1;
555     else                   return 0;
556 }
557 #endif
558
559 #if CONFIG_AC3_DEMUXER
560 static int ac3_probe(AVProbeData *p)
561 {
562     return ac3_eac3_probe(p, CODEC_ID_AC3);
563 }
564 #endif
565
566 #if CONFIG_EAC3_DEMUXER
567 static int eac3_probe(AVProbeData *p)
568 {
569     return ac3_eac3_probe(p, CODEC_ID_EAC3);
570 }
571 #endif
572
573 #if CONFIG_FLAC_DEMUXER
574 static int flac_probe(AVProbeData *p)
575 {
576     if(memcmp(p->buf, "fLaC", 4)) return 0;
577     else                          return AVPROBE_SCORE_MAX / 2;
578 }
579 #endif
580
581 #if CONFIG_AAC_DEMUXER
582 static int adts_aac_probe(AVProbeData *p)
583 {
584     int max_frames = 0, first_frames = 0;
585     int fsize, frames;
586     uint8_t *buf0 = p->buf;
587     uint8_t *buf2;
588     uint8_t *buf;
589     uint8_t *end = buf0 + p->buf_size - 7;
590
591     if (ff_id3v2_match(buf0)) {
592         buf0 += ff_id3v2_tag_len(buf0);
593     }
594     buf = buf0;
595
596     for(; buf < end; buf= buf2+1) {
597         buf2 = buf;
598
599         for(frames = 0; buf2 < end; frames++) {
600             uint32_t header = AV_RB16(buf2);
601             if((header&0xFFF6) != 0xFFF0)
602                 break;
603             fsize = (AV_RB32(buf2+3)>>13) & 0x8FFF;
604             if(fsize < 7)
605                 break;
606             buf2 += fsize;
607         }
608         max_frames = FFMAX(max_frames, frames);
609         if(buf == buf0)
610             first_frames= frames;
611     }
612     if   (first_frames>=3) return AVPROBE_SCORE_MAX/2+1;
613     else if(max_frames>500)return AVPROBE_SCORE_MAX/2;
614     else if(max_frames>=3) return AVPROBE_SCORE_MAX/4;
615     else if(max_frames>=1) return 1;
616     else                   return 0;
617 }
618 #endif
619
620 /* Note: Do not forget to add new entries to the Makefile as well. */
621
622 #if CONFIG_AAC_DEMUXER
623 AVInputFormat aac_demuxer = {
624     "aac",
625     NULL_IF_CONFIG_SMALL("ADTS AAC"),
626     0,
627     adts_aac_probe,
628     audio_read_header,
629     raw_read_partial_packet,
630     .flags= AVFMT_GENERIC_INDEX,
631     .extensions = "aac",
632     .value = CODEC_ID_AAC,
633 };
634 #endif
635
636 #if CONFIG_AC3_DEMUXER
637 AVInputFormat ac3_demuxer = {
638     "ac3",
639     NULL_IF_CONFIG_SMALL("raw AC-3"),
640     0,
641     ac3_probe,
642     audio_read_header,
643     raw_read_partial_packet,
644     .flags= AVFMT_GENERIC_INDEX,
645     .extensions = "ac3",
646     .value = CODEC_ID_AC3,
647 };
648 #endif
649
650 #if CONFIG_AC3_MUXER
651 AVOutputFormat ac3_muxer = {
652     "ac3",
653     NULL_IF_CONFIG_SMALL("raw AC-3"),
654     "audio/x-ac3",
655     "ac3",
656     0,
657     CODEC_ID_AC3,
658     CODEC_ID_NONE,
659     NULL,
660     raw_write_packet,
661     .flags= AVFMT_NOTIMESTAMPS,
662 };
663 #endif
664
665 #if CONFIG_DIRAC_DEMUXER
666 AVInputFormat dirac_demuxer = {
667     "dirac",
668     NULL_IF_CONFIG_SMALL("raw Dirac"),
669     0,
670     dirac_probe,
671     video_read_header,
672     raw_read_partial_packet,
673     .flags= AVFMT_GENERIC_INDEX,
674     .value = CODEC_ID_DIRAC,
675 };
676 #endif
677
678 #if CONFIG_DIRAC_MUXER
679 AVOutputFormat dirac_muxer = {
680     "dirac",
681     NULL_IF_CONFIG_SMALL("raw Dirac"),
682     NULL,
683     "drc",
684     0,
685     CODEC_ID_NONE,
686     CODEC_ID_DIRAC,
687     NULL,
688     raw_write_packet,
689     .flags= AVFMT_NOTIMESTAMPS,
690 };
691 #endif
692
693 #if CONFIG_DNXHD_DEMUXER
694 AVInputFormat dnxhd_demuxer = {
695     "dnxhd",
696     NULL_IF_CONFIG_SMALL("raw DNxHD (SMPTE VC-3)"),
697     0,
698     dnxhd_probe,
699     video_read_header,
700     raw_read_partial_packet,
701     .flags= AVFMT_GENERIC_INDEX,
702     .value = CODEC_ID_DNXHD,
703 };
704 #endif
705
706 #if CONFIG_DNXHD_MUXER
707 AVOutputFormat dnxhd_muxer = {
708     "dnxhd",
709     NULL_IF_CONFIG_SMALL("raw DNxHD (SMPTE VC-3)"),
710     NULL,
711     "dnxhd",
712     0,
713     CODEC_ID_NONE,
714     CODEC_ID_DNXHD,
715     NULL,
716     raw_write_packet,
717     .flags= AVFMT_NOTIMESTAMPS,
718 };
719 #endif
720
721 #if CONFIG_DTS_DEMUXER
722 AVInputFormat dts_demuxer = {
723     "dts",
724     NULL_IF_CONFIG_SMALL("raw DTS"),
725     0,
726     dts_probe,
727     audio_read_header,
728     raw_read_partial_packet,
729     .flags= AVFMT_GENERIC_INDEX,
730     .extensions = "dts",
731     .value = CODEC_ID_DTS,
732 };
733 #endif
734
735 #if CONFIG_DTS_MUXER
736 AVOutputFormat dts_muxer = {
737     "dts",
738     NULL_IF_CONFIG_SMALL("raw DTS"),
739     "audio/x-dca",
740     "dts",
741     0,
742     CODEC_ID_DTS,
743     CODEC_ID_NONE,
744     NULL,
745     raw_write_packet,
746     .flags= AVFMT_NOTIMESTAMPS,
747 };
748 #endif
749
750 #if CONFIG_EAC3_DEMUXER
751 AVInputFormat eac3_demuxer = {
752     "eac3",
753     NULL_IF_CONFIG_SMALL("raw E-AC-3"),
754     0,
755     eac3_probe,
756     audio_read_header,
757     raw_read_partial_packet,
758     .flags= AVFMT_GENERIC_INDEX,
759     .extensions = "eac3",
760     .value = CODEC_ID_EAC3,
761 };
762 #endif
763
764 #if CONFIG_EAC3_MUXER
765 AVOutputFormat eac3_muxer = {
766     "eac3",
767     NULL_IF_CONFIG_SMALL("raw E-AC-3"),
768     "audio/x-eac3",
769     "eac3",
770     0,
771     CODEC_ID_EAC3,
772     CODEC_ID_NONE,
773     NULL,
774     raw_write_packet,
775     .flags= AVFMT_NOTIMESTAMPS,
776 };
777 #endif
778
779 #if CONFIG_FLAC_DEMUXER
780 AVInputFormat flac_demuxer = {
781     "flac",
782     NULL_IF_CONFIG_SMALL("raw FLAC"),
783     0,
784     flac_probe,
785     audio_read_header,
786     raw_read_partial_packet,
787     .flags= AVFMT_GENERIC_INDEX,
788     .extensions = "flac",
789     .value = CODEC_ID_FLAC,
790 };
791 #endif
792
793 #if CONFIG_FLAC_MUXER
794 AVOutputFormat flac_muxer = {
795     "flac",
796     NULL_IF_CONFIG_SMALL("raw FLAC"),
797     "audio/x-flac",
798     "flac",
799     0,
800     CODEC_ID_FLAC,
801     CODEC_ID_NONE,
802     flac_write_header,
803     raw_write_packet,
804     flac_write_trailer,
805     .flags= AVFMT_NOTIMESTAMPS,
806 };
807 #endif
808
809 #if CONFIG_GSM_DEMUXER
810 AVInputFormat gsm_demuxer = {
811     "gsm",
812     NULL_IF_CONFIG_SMALL("GSM"),
813     0,
814     NULL,
815     audio_read_header,
816     raw_read_partial_packet,
817     .flags= AVFMT_GENERIC_INDEX,
818     .extensions = "gsm",
819     .value = CODEC_ID_GSM,
820 };
821 #endif
822
823 #if CONFIG_H261_DEMUXER
824 AVInputFormat h261_demuxer = {
825     "h261",
826     NULL_IF_CONFIG_SMALL("raw H.261"),
827     0,
828     h261_probe,
829     video_read_header,
830     raw_read_partial_packet,
831     .flags= AVFMT_GENERIC_INDEX,
832     .extensions = "h261",
833     .value = CODEC_ID_H261,
834 };
835 #endif
836
837 #if CONFIG_H261_MUXER
838 AVOutputFormat h261_muxer = {
839     "h261",
840     NULL_IF_CONFIG_SMALL("raw H.261"),
841     "video/x-h261",
842     "h261",
843     0,
844     CODEC_ID_NONE,
845     CODEC_ID_H261,
846     NULL,
847     raw_write_packet,
848     .flags= AVFMT_NOTIMESTAMPS,
849 };
850 #endif
851
852 #if CONFIG_H263_DEMUXER
853 AVInputFormat h263_demuxer = {
854     "h263",
855     NULL_IF_CONFIG_SMALL("raw H.263"),
856     0,
857     h263_probe,
858     video_read_header,
859     raw_read_partial_packet,
860     .flags= AVFMT_GENERIC_INDEX,
861 //    .extensions = "h263", //FIXME remove after writing mpeg4_probe
862     .value = CODEC_ID_H263,
863 };
864 #endif
865
866 #if CONFIG_H263_MUXER
867 AVOutputFormat h263_muxer = {
868     "h263",
869     NULL_IF_CONFIG_SMALL("raw H.263"),
870     "video/x-h263",
871     "h263",
872     0,
873     CODEC_ID_NONE,
874     CODEC_ID_H263,
875     NULL,
876     raw_write_packet,
877     .flags= AVFMT_NOTIMESTAMPS,
878 };
879 #endif
880
881 #if CONFIG_H264_DEMUXER
882 AVInputFormat h264_demuxer = {
883     "h264",
884     NULL_IF_CONFIG_SMALL("raw H.264 video format"),
885     0,
886     h264_probe,
887     video_read_header,
888     raw_read_partial_packet,
889     .flags= AVFMT_GENERIC_INDEX,
890     .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
891     .value = CODEC_ID_H264,
892 };
893 #endif
894
895 #if CONFIG_H264_MUXER
896 AVOutputFormat h264_muxer = {
897     "h264",
898     NULL_IF_CONFIG_SMALL("raw H.264 video format"),
899     NULL,
900     "h264",
901     0,
902     CODEC_ID_NONE,
903     CODEC_ID_H264,
904     NULL,
905     raw_write_packet,
906     .flags= AVFMT_NOTIMESTAMPS,
907 };
908 #endif
909
910 #if CONFIG_INGENIENT_DEMUXER
911 AVInputFormat ingenient_demuxer = {
912     "ingenient",
913     NULL_IF_CONFIG_SMALL("Ingenient MJPEG"),
914     0,
915     NULL,
916     video_read_header,
917     ingenient_read_packet,
918     .flags= AVFMT_GENERIC_INDEX,
919     .extensions = "cgi", // FIXME
920     .value = CODEC_ID_MJPEG,
921 };
922 #endif
923
924 #if CONFIG_M4V_DEMUXER
925 AVInputFormat m4v_demuxer = {
926     "m4v",
927     NULL_IF_CONFIG_SMALL("raw MPEG-4 video format"),
928     0,
929     mpeg4video_probe, /** probing for MPEG-4 data */
930     video_read_header,
931     raw_read_partial_packet,
932     .flags= AVFMT_GENERIC_INDEX,
933     .extensions = "m4v",
934     .value = CODEC_ID_MPEG4,
935 };
936 #endif
937
938 #if CONFIG_M4V_MUXER
939 AVOutputFormat m4v_muxer = {
940     "m4v",
941     NULL_IF_CONFIG_SMALL("raw MPEG-4 video format"),
942     NULL,
943     "m4v",
944     0,
945     CODEC_ID_NONE,
946     CODEC_ID_MPEG4,
947     NULL,
948     raw_write_packet,
949     .flags= AVFMT_NOTIMESTAMPS,
950 };
951 #endif
952
953 #if CONFIG_MJPEG_DEMUXER
954 AVInputFormat mjpeg_demuxer = {
955     "mjpeg",
956     NULL_IF_CONFIG_SMALL("MJPEG video"),
957     0,
958     NULL,
959     video_read_header,
960     raw_read_partial_packet,
961     .flags= AVFMT_GENERIC_INDEX,
962     .extensions = "mjpg,mjpeg",
963     .value = CODEC_ID_MJPEG,
964 };
965 #endif
966
967 #if CONFIG_MJPEG_MUXER
968 AVOutputFormat mjpeg_muxer = {
969     "mjpeg",
970     NULL_IF_CONFIG_SMALL("MJPEG video"),
971     "video/x-mjpeg",
972     "mjpg,mjpeg",
973     0,
974     CODEC_ID_NONE,
975     CODEC_ID_MJPEG,
976     NULL,
977     raw_write_packet,
978     .flags= AVFMT_NOTIMESTAMPS,
979 };
980 #endif
981
982 #if CONFIG_MLP_DEMUXER
983 AVInputFormat mlp_demuxer = {
984     "mlp",
985     NULL_IF_CONFIG_SMALL("raw MLP"),
986     0,
987     NULL,
988     audio_read_header,
989     raw_read_partial_packet,
990     .flags= AVFMT_GENERIC_INDEX,
991     .extensions = "mlp",
992     .value = CODEC_ID_MLP,
993 };
994 #endif
995
996 #if CONFIG_MPEG1VIDEO_MUXER
997 AVOutputFormat mpeg1video_muxer = {
998     "mpeg1video",
999     NULL_IF_CONFIG_SMALL("MPEG video"),
1000     "video/x-mpeg",
1001     "mpg,mpeg,m1v",
1002     0,
1003     CODEC_ID_NONE,
1004     CODEC_ID_MPEG1VIDEO,
1005     NULL,
1006     raw_write_packet,
1007     .flags= AVFMT_NOTIMESTAMPS,
1008 };
1009 #endif
1010
1011 #if CONFIG_MPEG2VIDEO_MUXER
1012 AVOutputFormat mpeg2video_muxer = {
1013     "mpeg2video",
1014     NULL_IF_CONFIG_SMALL("MPEG-2 video"),
1015     NULL,
1016     "m2v",
1017     0,
1018     CODEC_ID_NONE,
1019     CODEC_ID_MPEG2VIDEO,
1020     NULL,
1021     raw_write_packet,
1022     .flags= AVFMT_NOTIMESTAMPS,
1023 };
1024 #endif
1025
1026 #if CONFIG_MPEGVIDEO_DEMUXER
1027 AVInputFormat mpegvideo_demuxer = {
1028     "mpegvideo",
1029     NULL_IF_CONFIG_SMALL("MPEG video"),
1030     0,
1031     mpegvideo_probe,
1032     video_read_header,
1033     raw_read_partial_packet,
1034     .flags= AVFMT_GENERIC_INDEX,
1035     .value = CODEC_ID_MPEG1VIDEO,
1036 };
1037 #endif
1038
1039 #if CONFIG_NULL_MUXER
1040 AVOutputFormat null_muxer = {
1041     "null",
1042     NULL_IF_CONFIG_SMALL("null video format"),
1043     NULL,
1044     NULL,
1045     0,
1046 #ifdef WORDS_BIGENDIAN
1047     CODEC_ID_PCM_S16BE,
1048 #else
1049     CODEC_ID_PCM_S16LE,
1050 #endif
1051     CODEC_ID_RAWVIDEO,
1052     NULL,
1053     null_write_packet,
1054     .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
1055 };
1056 #endif
1057
1058 #if CONFIG_RAWVIDEO_DEMUXER
1059 AVInputFormat rawvideo_demuxer = {
1060     "rawvideo",
1061     NULL_IF_CONFIG_SMALL("raw video format"),
1062     0,
1063     NULL,
1064     raw_read_header,
1065     rawvideo_read_packet,
1066     .flags= AVFMT_GENERIC_INDEX,
1067     .extensions = "yuv,cif,qcif,rgb",
1068     .value = CODEC_ID_RAWVIDEO,
1069 };
1070 #endif
1071
1072 #if CONFIG_RAWVIDEO_MUXER
1073 AVOutputFormat rawvideo_muxer = {
1074     "rawvideo",
1075     NULL_IF_CONFIG_SMALL("raw video format"),
1076     NULL,
1077     "yuv,rgb",
1078     0,
1079     CODEC_ID_NONE,
1080     CODEC_ID_RAWVIDEO,
1081     NULL,
1082     raw_write_packet,
1083     .flags= AVFMT_NOTIMESTAMPS,
1084 };
1085 #endif
1086
1087 #if CONFIG_ROQ_MUXER
1088 AVOutputFormat roq_muxer =
1089 {
1090     "RoQ",
1091     NULL_IF_CONFIG_SMALL("id RoQ format"),
1092     NULL,
1093     "roq",
1094     0,
1095     CODEC_ID_ROQ_DPCM,
1096     CODEC_ID_ROQ,
1097     roq_write_header,
1098     raw_write_packet,
1099 };
1100 #endif
1101
1102 #if CONFIG_SHORTEN_DEMUXER
1103 AVInputFormat shorten_demuxer = {
1104     "shn",
1105     NULL_IF_CONFIG_SMALL("raw Shorten"),
1106     0,
1107     NULL,
1108     audio_read_header,
1109     raw_read_partial_packet,
1110     .flags= AVFMT_GENERIC_INDEX,
1111     .extensions = "shn",
1112     .value = CODEC_ID_SHORTEN,
1113 };
1114 #endif
1115
1116 #if CONFIG_VC1_DEMUXER
1117 AVInputFormat vc1_demuxer = {
1118     "vc1",
1119     NULL_IF_CONFIG_SMALL("raw VC-1"),
1120     0,
1121     NULL /* vc1_probe */,
1122     video_read_header,
1123     raw_read_partial_packet,
1124     .extensions = "vc1",
1125     .value = CODEC_ID_VC1,
1126 };
1127 #endif
1128
1129 /* PCM formats */
1130
1131 #define PCMINPUTDEF(name, long_name, ext, codec) \
1132 AVInputFormat pcm_ ## name ## _demuxer = {\
1133     #name,\
1134     NULL_IF_CONFIG_SMALL(long_name),\
1135     0,\
1136     NULL,\
1137     raw_read_header,\
1138     raw_read_packet,\
1139     NULL,\
1140     pcm_read_seek,\
1141     .flags= AVFMT_GENERIC_INDEX,\
1142     .extensions = ext,\
1143     .value = codec,\
1144 };
1145
1146 #define PCMOUTPUTDEF(name, long_name, ext, codec) \
1147 AVOutputFormat pcm_ ## name ## _muxer = {\
1148     #name,\
1149     NULL_IF_CONFIG_SMALL(long_name),\
1150     NULL,\
1151     ext,\
1152     0,\
1153     codec,\
1154     CODEC_ID_NONE,\
1155     NULL,\
1156     raw_write_packet,\
1157     .flags= AVFMT_NOTIMESTAMPS,\
1158 };
1159
1160
1161 #if  !CONFIG_MUXERS && CONFIG_DEMUXERS
1162 #define PCMDEF(name, long_name, ext, codec) \
1163         PCMINPUTDEF(name, long_name, ext, codec)
1164 #elif CONFIG_MUXERS && !CONFIG_DEMUXERS
1165 #define PCMDEF(name, long_name, ext, codec) \
1166         PCMOUTPUTDEF(name, long_name, ext, codec)
1167 #elif CONFIG_MUXERS && CONFIG_DEMUXERS
1168 #define PCMDEF(name, long_name, ext, codec) \
1169         PCMINPUTDEF(name, long_name, ext, codec)\
1170         PCMOUTPUTDEF(name, long_name, ext, codec)
1171 #else
1172 #define PCMDEF(name, long_name, ext, codec)
1173 #endif
1174
1175 #ifdef WORDS_BIGENDIAN
1176 #define BE_DEF(s) s
1177 #define LE_DEF(s) NULL
1178 #else
1179 #define BE_DEF(s) NULL
1180 #define LE_DEF(s) s
1181 #endif
1182
1183 PCMDEF(f64be, "PCM 64 bit floating-point big-endian format",
1184        NULL, CODEC_ID_PCM_F64BE)
1185
1186 PCMDEF(f64le, "PCM 64 bit floating-point little-endian format",
1187        NULL, CODEC_ID_PCM_F64LE)
1188
1189 PCMDEF(f32be, "PCM 32 bit floating-point big-endian format",
1190        NULL, CODEC_ID_PCM_F32BE)
1191
1192 PCMDEF(f32le, "PCM 32 bit floating-point little-endian format",
1193        NULL, CODEC_ID_PCM_F32LE)
1194
1195 PCMDEF(s32be, "PCM signed 32 bit big-endian format",
1196        NULL, CODEC_ID_PCM_S32BE)
1197
1198 PCMDEF(s32le, "PCM signed 32 bit little-endian format",
1199        NULL, CODEC_ID_PCM_S32LE)
1200
1201 PCMDEF(s24be, "PCM signed 24 bit big-endian format",
1202        NULL, CODEC_ID_PCM_S24BE)
1203
1204 PCMDEF(s24le, "PCM signed 24 bit little-endian format",
1205        NULL, CODEC_ID_PCM_S24LE)
1206
1207 PCMDEF(s16be, "PCM signed 16 bit big-endian format",
1208        BE_DEF("sw"), CODEC_ID_PCM_S16BE)
1209
1210 PCMDEF(s16le, "PCM signed 16 bit little-endian format",
1211        LE_DEF("sw"), CODEC_ID_PCM_S16LE)
1212
1213 PCMDEF(s8, "PCM signed 8 bit format",
1214        "sb", CODEC_ID_PCM_S8)
1215
1216 PCMDEF(u32be, "PCM unsigned 32 bit big-endian format",
1217        NULL, CODEC_ID_PCM_U32BE)
1218
1219 PCMDEF(u32le, "PCM unsigned 32 bit little-endian format",
1220        NULL, CODEC_ID_PCM_U32LE)
1221
1222 PCMDEF(u24be, "PCM unsigned 24 bit big-endian format",
1223        NULL, CODEC_ID_PCM_U24BE)
1224
1225 PCMDEF(u24le, "PCM unsigned 24 bit little-endian format",
1226        NULL, CODEC_ID_PCM_U24LE)
1227
1228 PCMDEF(u16be, "PCM unsigned 16 bit big-endian format",
1229        BE_DEF("uw"), CODEC_ID_PCM_U16BE)
1230
1231 PCMDEF(u16le, "PCM unsigned 16 bit little-endian format",
1232        LE_DEF("uw"), CODEC_ID_PCM_U16LE)
1233
1234 PCMDEF(u8, "PCM unsigned 8 bit format",
1235        "ub", CODEC_ID_PCM_U8)
1236
1237 PCMDEF(alaw, "PCM A-law format",
1238        "al", CODEC_ID_PCM_ALAW)
1239
1240 PCMDEF(mulaw, "PCM mu-law format",
1241        "ul", CODEC_ID_PCM_MULAW)