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