Statistics
| Branch: | Revision:

ffmpeg / libavformat / raw.c @ 47772399

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