Statistics
| Branch: | Revision:

ffmpeg / libavformat / raw.c @ 1afdcdf1

History | View | Annotate | Download (20.2 KB)

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