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