Statistics
| Branch: | Revision:

ffmpeg / libavformat / raw.c @ d2062ff6

History | View | Annotate | Download (20.8 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
    max_frames = 0;
413
    buf = p->buf;
414 ecc8fc11 Justin Ruggles
    end = buf + p->buf_size;
415 f8b9830b Justin Ruggles
416
    for(; buf < end; buf++) {
417
        buf2 = buf;
418 7156aeb9 Justin Ruggles
419 f8b9830b Justin Ruggles
        for(frames = 0; buf2 < end; frames++) {
420
            if(ff_ac3_parse_header(buf2, &hdr) < 0)
421
                break;
422
            buf2 += hdr.frame_size;
423
        }
424
        max_frames = FFMAX(max_frames, frames);
425
        if(buf == p->buf)
426
            first_frames = frames;
427
    }
428
    if   (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4;
429 2477ce23 Justin Ruggles
    else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2;
430 f8b9830b Justin Ruggles
    else if(max_frames>=1) return 1;
431
    else                   return 0;
432 7156aeb9 Justin Ruggles
}
433
434 e020dbd2 Michael Niedermayer
static int flac_probe(AVProbeData *p)
435
{
436
    if(memcmp(p->buf, "fLaC", 4)) return 0;
437 fbd69f51 Michael Niedermayer
    else                          return AVPROBE_SCORE_MAX / 2;
438 e020dbd2 Michael Niedermayer
}
439
440 d2a067d1 Måns Rullgård
AVInputFormat shorten_demuxer = {
441 85ad5695 Michael Niedermayer
    "shn",
442 84c63c01 Alex Beregszaszi
    "raw shorten",
443 85ad5695 Michael Niedermayer
    0,
444
    NULL,
445
    shorten_read_header,
446
    raw_read_partial_packet,
447
    raw_read_close,
448 e9b78eeb Michael Niedermayer
    .flags= AVFMT_GENERIC_INDEX,
449 85ad5695 Michael Niedermayer
    .extensions = "shn",
450
};
451
452 d2a067d1 Måns Rullgård
AVInputFormat flac_demuxer = {
453 89ca8c49 Benjamin Larsson
    "flac",
454
    "raw flac",
455
    0,
456 e020dbd2 Michael Niedermayer
    flac_probe,
457 89ca8c49 Benjamin Larsson
    flac_read_header,
458
    raw_read_partial_packet,
459
    raw_read_close,
460 e9b78eeb Michael Niedermayer
    .flags= AVFMT_GENERIC_INDEX,
461 89ca8c49 Benjamin Larsson
    .extensions = "flac",
462
};
463
464 ce1d2a95 Justin Ruggles
#ifdef CONFIG_MUXERS
465 d2a067d1 Måns Rullgård
AVOutputFormat flac_muxer = {
466 ce1d2a95 Justin Ruggles
    "flac",
467
    "raw flac",
468
    "audio/x-flac",
469
    "flac",
470
    0,
471
    CODEC_ID_FLAC,
472
    0,
473
    flac_write_header,
474
    raw_write_packet,
475 494bbf58 Michael Niedermayer
    .flags= AVFMT_NOTIMESTAMPS,
476 ce1d2a95 Justin Ruggles
};
477
#endif //CONFIG_MUXERS
478
479 cefd4907 Diego Biurrun
#ifdef CONFIG_AC3_DEMUXER
480 d2a067d1 Måns Rullgård
AVInputFormat ac3_demuxer = {
481 c9a65ca8 Fabrice Bellard
    "ac3",
482
    "raw ac3",
483
    0,
484 7156aeb9 Justin Ruggles
    ac3_probe,
485 cd66005d Fabrice Bellard
    ac3_read_header,
486 e15dec10 Leon van Stuivenberg
    raw_read_partial_packet,
487 de6d9b64 Fabrice Bellard
    raw_read_close,
488 e9b78eeb Michael Niedermayer
    .flags= AVFMT_GENERIC_INDEX,
489 bb76a117 Måns Rullgård
    .extensions = "ac3",
490 de6d9b64 Fabrice Bellard
};
491 cefd4907 Diego Biurrun
#endif
492 de6d9b64 Fabrice Bellard
493 a9e35095 Diego Biurrun
#ifdef CONFIG_MUXERS
494 d2a067d1 Måns Rullgård
AVOutputFormat ac3_muxer = {
495 de6d9b64 Fabrice Bellard
    "ac3",
496
    "raw ac3",
497 115329f1 Diego Biurrun
    "audio/x-ac3",
498 de6d9b64 Fabrice Bellard
    "ac3",
499 c9a65ca8 Fabrice Bellard
    0,
500 de6d9b64 Fabrice Bellard
    CODEC_ID_AC3,
501
    0,
502 7a97dd84 Baptiste Coudurier
    NULL,
503 de6d9b64 Fabrice Bellard
    raw_write_packet,
504 494bbf58 Michael Niedermayer
    .flags= AVFMT_NOTIMESTAMPS,
505 de6d9b64 Fabrice Bellard
};
506 a9e35095 Diego Biurrun
#endif //CONFIG_MUXERS
507 de6d9b64 Fabrice Bellard
508 d2a067d1 Måns Rullgård
AVInputFormat dts_demuxer = {
509 23c99253 Michael Niedermayer
    "dts",
510
    "raw dts",
511
    0,
512
    NULL,
513
    dts_read_header,
514
    raw_read_partial_packet,
515
    raw_read_close,
516 e9b78eeb Michael Niedermayer
    .flags= AVFMT_GENERIC_INDEX,
517 23c99253 Michael Niedermayer
    .extensions = "dts",
518
};
519
520 d2a067d1 Måns Rullgård
AVInputFormat aac_demuxer = {
521 fda885c7 Måns Rullgård
    "aac",
522
    "ADTS AAC",
523
    0,
524
    NULL,
525
    aac_read_header,
526
    raw_read_partial_packet,
527
    raw_read_close,
528 e9b78eeb Michael Niedermayer
    .flags= AVFMT_GENERIC_INDEX,
529 fda885c7 Måns Rullgård
    .extensions = "aac",
530
};
531
532 13dec857 Vitor Sessak
#ifdef CONFIG_ROQ_MUXER
533
AVOutputFormat roq_muxer =
534
{
535
    "RoQ",
536
    "Id RoQ format",
537
    NULL,
538
    "roq",
539
    0,
540
    CODEC_ID_ROQ_DPCM,
541
    CODEC_ID_ROQ,
542
    roq_write_header,
543
    raw_write_packet,
544
};
545
#endif //CONFIG_ROQ_MUXER
546
547 d2a067d1 Måns Rullgård
AVInputFormat h261_demuxer = {
548 c6148de2 Michael Niedermayer
    "h261",
549
    "raw h261",
550
    0,
551
    h261_probe,
552
    video_read_header,
553
    raw_read_partial_packet,
554
    raw_read_close,
555 e9b78eeb Michael Niedermayer
    .flags= AVFMT_GENERIC_INDEX,
556 c6148de2 Michael Niedermayer
    .extensions = "h261",
557
    .value = CODEC_ID_H261,
558
};
559
560 a9e35095 Diego Biurrun
#ifdef CONFIG_MUXERS
561 d2a067d1 Måns Rullgård
AVOutputFormat h261_muxer = {
562 1c3990db Michael Niedermayer
    "h261",
563
    "raw h261",
564
    "video/x-h261",
565
    "h261",
566
    0,
567
    0,
568
    CODEC_ID_H261,
569 7a97dd84 Baptiste Coudurier
    NULL,
570 1c3990db Michael Niedermayer
    raw_write_packet,
571 494bbf58 Michael Niedermayer
    .flags= AVFMT_NOTIMESTAMPS,
572 1c3990db Michael Niedermayer
};
573 a9e35095 Diego Biurrun
#endif //CONFIG_MUXERS
574 1c3990db Michael Niedermayer
575 d2a067d1 Måns Rullgård
AVInputFormat h263_demuxer = {
576 d07f9043 Michael Niedermayer
    "h263",
577
    "raw h263",
578
    0,
579
    h263_probe,
580
    video_read_header,
581 e15dec10 Leon van Stuivenberg
    raw_read_partial_packet,
582 d07f9043 Michael Niedermayer
    raw_read_close,
583 e9b78eeb Michael Niedermayer
    .flags= AVFMT_GENERIC_INDEX,
584 d07f9043 Michael Niedermayer
//    .extensions = "h263", //FIXME remove after writing mpeg4_probe
585
    .value = CODEC_ID_H263,
586
};
587
588 a9e35095 Diego Biurrun
#ifdef CONFIG_MUXERS
589 d2a067d1 Måns Rullgård
AVOutputFormat h263_muxer = {
590 de6d9b64 Fabrice Bellard
    "h263",
591
    "raw h263",
592
    "video/x-h263",
593
    "h263",
594
    0,
595 c9a65ca8 Fabrice Bellard
    0,
596 de6d9b64 Fabrice Bellard
    CODEC_ID_H263,
597 7a97dd84 Baptiste Coudurier
    NULL,
598 de6d9b64 Fabrice Bellard
    raw_write_packet,
599 494bbf58 Michael Niedermayer
    .flags= AVFMT_NOTIMESTAMPS,
600 c9a65ca8 Fabrice Bellard
};
601 a9e35095 Diego Biurrun
#endif //CONFIG_MUXERS
602 c9a65ca8 Fabrice Bellard
603 d2a067d1 Måns Rullgård
AVInputFormat m4v_demuxer = {
604 7866eeff Michael Niedermayer
    "m4v",
605
    "raw MPEG4 video format",
606
    0,
607 8f57cc5a Thijs Vermeir
    mpeg4video_probe, /** probing for mpeg4 data */
608 7866eeff Michael Niedermayer
    video_read_header,
609 e15dec10 Leon van Stuivenberg
    raw_read_partial_packet,
610 7866eeff Michael Niedermayer
    raw_read_close,
611 e9b78eeb Michael Niedermayer
    .flags= AVFMT_GENERIC_INDEX,
612 bb76a117 Måns Rullgård
    .extensions = "m4v", //FIXME remove after writing mpeg4_probe
613
    .value = CODEC_ID_MPEG4,
614 7866eeff Michael Niedermayer
};
615
616 a9e35095 Diego Biurrun
#ifdef CONFIG_MUXERS
617 d2a067d1 Måns Rullgård
AVOutputFormat m4v_muxer = {
618 89b3d7c9 Max Krasnyansky
    "m4v",
619
    "raw MPEG4 video format",
620
    NULL,
621
    "m4v",
622
    0,
623
    CODEC_ID_NONE,
624
    CODEC_ID_MPEG4,
625 7a97dd84 Baptiste Coudurier
    NULL,
626 89b3d7c9 Max Krasnyansky
    raw_write_packet,
627 494bbf58 Michael Niedermayer
    .flags= AVFMT_NOTIMESTAMPS,
628 89b3d7c9 Max Krasnyansky
};
629 a9e35095 Diego Biurrun
#endif //CONFIG_MUXERS
630 89b3d7c9 Max Krasnyansky
631 d2a067d1 Måns Rullgård
AVInputFormat h264_demuxer = {
632 0da71265 Michael Niedermayer
    "h264",
633
    "raw H264 video format",
634
    0,
635
    NULL /*mpegvideo_probe*/,
636
    video_read_header,
637 e15dec10 Leon van Stuivenberg
    raw_read_partial_packet,
638 0da71265 Michael Niedermayer
    raw_read_close,
639 e9b78eeb Michael Niedermayer
    .flags= AVFMT_GENERIC_INDEX,
640 ba5697d5 Michael Niedermayer
    .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
641 0da71265 Michael Niedermayer
    .value = CODEC_ID_H264,
642
};
643
644 a9e35095 Diego Biurrun
#ifdef CONFIG_MUXERS
645 d2a067d1 Måns Rullgård
AVOutputFormat h264_muxer = {
646 0da71265 Michael Niedermayer
    "h264",
647
    "raw H264 video format",
648
    NULL,
649
    "h264",
650
    0,
651
    CODEC_ID_NONE,
652
    CODEC_ID_H264,
653 7a97dd84 Baptiste Coudurier
    NULL,
654 0da71265 Michael Niedermayer
    raw_write_packet,
655 494bbf58 Michael Niedermayer
    .flags= AVFMT_NOTIMESTAMPS,
656 0da71265 Michael Niedermayer
};
657 a9e35095 Diego Biurrun
#endif //CONFIG_MUXERS
658 0da71265 Michael Niedermayer
659 d2a067d1 Måns Rullgård
AVInputFormat mpegvideo_demuxer = {
660 c9a65ca8 Fabrice Bellard
    "mpegvideo",
661
    "MPEG video",
662
    0,
663
    mpegvideo_probe,
664 de6d9b64 Fabrice Bellard
    video_read_header,
665 e15dec10 Leon van Stuivenberg
    raw_read_partial_packet,
666 de6d9b64 Fabrice Bellard
    raw_read_close,
667 e9b78eeb Michael Niedermayer
    .flags= AVFMT_GENERIC_INDEX,
668 bb76a117 Måns Rullgård
    .value = CODEC_ID_MPEG1VIDEO,
669 de6d9b64 Fabrice Bellard
};
670
671 a9e35095 Diego Biurrun
#ifdef CONFIG_MUXERS
672 d2a067d1 Måns Rullgård
AVOutputFormat mpeg1video_muxer = {
673 c9a65ca8 Fabrice Bellard
    "mpeg1video",
674 de6d9b64 Fabrice Bellard
    "MPEG video",
675
    "video/x-mpeg",
676 e0827ba4 Michael Niedermayer
    "mpg,mpeg,m1v",
677 de6d9b64 Fabrice Bellard
    0,
678 c9a65ca8 Fabrice Bellard
    0,
679 de6d9b64 Fabrice Bellard
    CODEC_ID_MPEG1VIDEO,
680 7a97dd84 Baptiste Coudurier
    NULL,
681 de6d9b64 Fabrice Bellard
    raw_write_packet,
682 494bbf58 Michael Niedermayer
    .flags= AVFMT_NOTIMESTAMPS,
683 de6d9b64 Fabrice Bellard
};
684 a9e35095 Diego Biurrun
#endif //CONFIG_MUXERS
685 de6d9b64 Fabrice Bellard
686 a9e35095 Diego Biurrun
#ifdef CONFIG_MUXERS
687 d2a067d1 Måns Rullgård
AVOutputFormat mpeg2video_muxer = {
688 6ec864da Michael Niedermayer
    "mpeg2video",
689
    "MPEG2 video",
690
    NULL,
691
    "m2v",
692
    0,
693
    0,
694
    CODEC_ID_MPEG2VIDEO,
695 7a97dd84 Baptiste Coudurier
    NULL,
696 6ec864da Michael Niedermayer
    raw_write_packet,
697 494bbf58 Michael Niedermayer
    .flags= AVFMT_NOTIMESTAMPS,
698 6ec864da Michael Niedermayer
};
699 a9e35095 Diego Biurrun
#endif //CONFIG_MUXERS
700 6ec864da Michael Niedermayer
701 d2a067d1 Måns Rullgård
AVInputFormat mjpeg_demuxer = {
702 27e084bd Fabrice Bellard
    "mjpeg",
703
    "MJPEG video",
704
    0,
705 c9a65ca8 Fabrice Bellard
    NULL,
706 27e084bd Fabrice Bellard
    video_read_header,
707 e15dec10 Leon van Stuivenberg
    raw_read_partial_packet,
708 27e084bd Fabrice Bellard
    raw_read_close,
709 e9b78eeb Michael Niedermayer
    .flags= AVFMT_GENERIC_INDEX,
710 bb76a117 Måns Rullgård
    .extensions = "mjpg,mjpeg",
711
    .value = CODEC_ID_MJPEG,
712 27e084bd Fabrice Bellard
};
713
714 d2a067d1 Måns Rullgård
AVInputFormat ingenient_demuxer = {
715 84c63c01 Alex Beregszaszi
    "ingenient",
716
    "Ingenient MJPEG",
717
    0,
718
    NULL,
719
    video_read_header,
720
    ingenient_read_packet,
721
    raw_read_close,
722 e9b78eeb Michael Niedermayer
    .flags= AVFMT_GENERIC_INDEX,
723 84c63c01 Alex Beregszaszi
    .extensions = "cgi", // FIXME
724
    .value = CODEC_ID_MJPEG,
725
};
726
727 a9e35095 Diego Biurrun
#ifdef CONFIG_MUXERS
728 d2a067d1 Måns Rullgård
AVOutputFormat mjpeg_muxer = {
729 c9a65ca8 Fabrice Bellard
    "mjpeg",
730
    "MJPEG video",
731
    "video/x-mjpeg",
732
    "mjpg,mjpeg",
733 5ed8fafc Fabrice Bellard
    0,
734
    0,
735 c9a65ca8 Fabrice Bellard
    CODEC_ID_MJPEG,
736 7a97dd84 Baptiste Coudurier
    NULL,
737 5ed8fafc Fabrice Bellard
    raw_write_packet,
738 494bbf58 Michael Niedermayer
    .flags= AVFMT_NOTIMESTAMPS,
739 5ed8fafc Fabrice Bellard
};
740 a9e35095 Diego Biurrun
#endif //CONFIG_MUXERS
741 5ed8fafc Fabrice Bellard
742 7bb5c2a6 Kostya Shishkov
AVInputFormat vc1_demuxer = {
743
    "vc1",
744
    "raw vc1",
745
    0,
746
    NULL /* vc1_probe */,
747
    video_read_header,
748
    raw_read_partial_packet,
749
    raw_read_close,
750
    .extensions = "vc1",
751
    .value = CODEC_ID_VC1,
752
};
753
754 c9a65ca8 Fabrice Bellard
/* pcm formats */
755 764ef400 Mike Melanson
756 4986a429 Fabrice Bellard
#define PCMINPUTDEF(name, long_name, ext, codec) \
757 d2a067d1 Måns Rullgård
AVInputFormat pcm_ ## name ## _demuxer = {\
758 764ef400 Mike Melanson
    #name,\
759
    long_name,\
760
    0,\
761
    NULL,\
762
    raw_read_header,\
763
    raw_read_packet,\
764
    raw_read_close,\
765 4986a429 Fabrice Bellard
    pcm_read_seek,\
766 e9b78eeb Michael Niedermayer
    .flags= AVFMT_GENERIC_INDEX,\
767 764ef400 Mike Melanson
    .extensions = ext,\
768
    .value = codec,\
769
};
770
771 2c8e2014 Diego Biurrun
#define PCMOUTPUTDEF(name, long_name, ext, codec) \
772 d2a067d1 Måns Rullgård
AVOutputFormat pcm_ ## name ## _muxer = {\
773 c9a65ca8 Fabrice Bellard
    #name,\
774
    long_name,\
775
    NULL,\
776
    ext,\
777
    0,\
778
    codec,\
779
    0,\
780 7a97dd84 Baptiste Coudurier
    NULL,\
781 c9a65ca8 Fabrice Bellard
    raw_write_packet,\
782 494bbf58 Michael Niedermayer
    .flags= AVFMT_NOTIMESTAMPS,\
783 5ed8fafc Fabrice Bellard
};
784 2c8e2014 Diego Biurrun
785
786
#if !defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
787
#define PCMDEF(name, long_name, ext, codec) \
788
        PCMINPUTDEF(name, long_name, ext, codec)
789
#elif defined(CONFIG_MUXERS) && !defined(CONFIG_DEMUXERS)
790
#define PCMDEF(name, long_name, ext, codec) \
791
        PCMOUTPUTDEF(name, long_name, ext, codec)
792
#elif defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
793
#define PCMDEF(name, long_name, ext, codec) \
794
        PCMINPUTDEF(name, long_name, ext, codec)\
795
        PCMOUTPUTDEF(name, long_name, ext, codec)
796
#else
797
#define PCMDEF(name, long_name, ext, codec)
798
#endif
799 5ed8fafc Fabrice Bellard
800
#ifdef WORDS_BIGENDIAN
801 c9a65ca8 Fabrice Bellard
#define BE_DEF(s) s
802
#define LE_DEF(s) NULL
803 5ed8fafc Fabrice Bellard
#else
804 c9a65ca8 Fabrice Bellard
#define BE_DEF(s) NULL
805
#define LE_DEF(s) s
806 5ed8fafc Fabrice Bellard
#endif
807
808
809 115329f1 Diego Biurrun
PCMDEF(s16le, "pcm signed 16 bit little endian format",
810 c9a65ca8 Fabrice Bellard
       LE_DEF("sw"), CODEC_ID_PCM_S16LE)
811 5ed8fafc Fabrice Bellard
812 115329f1 Diego Biurrun
PCMDEF(s16be, "pcm signed 16 bit big endian format",
813 c9a65ca8 Fabrice Bellard
       BE_DEF("sw"), CODEC_ID_PCM_S16BE)
814 5ed8fafc Fabrice Bellard
815 115329f1 Diego Biurrun
PCMDEF(u16le, "pcm unsigned 16 bit little endian format",
816 c9a65ca8 Fabrice Bellard
       LE_DEF("uw"), CODEC_ID_PCM_U16LE)
817 5ed8fafc Fabrice Bellard
818 115329f1 Diego Biurrun
PCMDEF(u16be, "pcm unsigned 16 bit big endian format",
819 c9a65ca8 Fabrice Bellard
       BE_DEF("uw"), CODEC_ID_PCM_U16BE)
820 5ed8fafc Fabrice Bellard
821 115329f1 Diego Biurrun
PCMDEF(s8, "pcm signed 8 bit format",
822 c9a65ca8 Fabrice Bellard
       "sb", CODEC_ID_PCM_S8)
823 5ed8fafc Fabrice Bellard
824 115329f1 Diego Biurrun
PCMDEF(u8, "pcm unsigned 8 bit format",
825 c9a65ca8 Fabrice Bellard
       "ub", CODEC_ID_PCM_U8)
826 5ed8fafc Fabrice Bellard
827 115329f1 Diego Biurrun
PCMDEF(mulaw, "pcm mu law format",
828 c9a65ca8 Fabrice Bellard
       "ul", CODEC_ID_PCM_MULAW)
829 de6d9b64 Fabrice Bellard
830 115329f1 Diego Biurrun
PCMDEF(alaw, "pcm A law format",
831 c9a65ca8 Fabrice Bellard
       "al", CODEC_ID_PCM_ALAW)
832 de6d9b64 Fabrice Bellard
833 5c91a675 Zdenek Kabelac
static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
834 de6d9b64 Fabrice Bellard
{
835
    int packet_size, ret, width, height;
836
    AVStream *st = s->streams[0];
837
838 01f4895c Michael Niedermayer
    width = st->codec->width;
839
    height = st->codec->height;
840 de6d9b64 Fabrice Bellard
841 01f4895c Michael Niedermayer
    packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
842 63167088 Roman Shaposhnik
    if (packet_size < 0)
843 71c32f19 Michael Niedermayer
        return -1;
844 de6d9b64 Fabrice Bellard
845 2692067a Michael Niedermayer
    ret= av_get_packet(&s->pb, pkt, packet_size);
846 de6d9b64 Fabrice Bellard
847
    pkt->stream_index = 0;
848 2692067a Michael Niedermayer
    if (ret != packet_size) {
849 6f3e0b21 Panagiotis Issaris
        return AVERROR(EIO);
850 de6d9b64 Fabrice Bellard
    } else {
851
        return 0;
852
    }
853
}
854
855 d2a067d1 Måns Rullgård
AVInputFormat rawvideo_demuxer = {
856 c9a65ca8 Fabrice Bellard
    "rawvideo",
857
    "raw video format",
858
    0,
859
    NULL,
860
    raw_read_header,
861
    rawvideo_read_packet,
862
    raw_read_close,
863 e9b78eeb Michael Niedermayer
    .flags= AVFMT_GENERIC_INDEX,
864 5faf2d36 Benoit Fouet
    .extensions = "yuv,cif,qcif,rgb",
865 bb76a117 Måns Rullgård
    .value = CODEC_ID_RAWVIDEO,
866 c9a65ca8 Fabrice Bellard
};
867
868 a9e35095 Diego Biurrun
#ifdef CONFIG_MUXERS
869 d2a067d1 Måns Rullgård
AVOutputFormat rawvideo_muxer = {
870 de6d9b64 Fabrice Bellard
    "rawvideo",
871
    "raw video format",
872
    NULL,
873 b47f86c4 Benoit Fouet
    "yuv,rgb",
874 c9a65ca8 Fabrice Bellard
    0,
875 de6d9b64 Fabrice Bellard
    CODEC_ID_NONE,
876
    CODEC_ID_RAWVIDEO,
877 7a97dd84 Baptiste Coudurier
    NULL,
878 de6d9b64 Fabrice Bellard
    raw_write_packet,
879 494bbf58 Michael Niedermayer
    .flags= AVFMT_NOTIMESTAMPS,
880 de6d9b64 Fabrice Bellard
};
881 a9e35095 Diego Biurrun
#endif //CONFIG_MUXERS
882 c9a65ca8 Fabrice Bellard
883 a9e35095 Diego Biurrun
#ifdef CONFIG_MUXERS
884 e928649b Michael Niedermayer
static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
885 87bdd3e5 Fabrice Bellard
{
886
    return 0;
887
}
888
889 d2a067d1 Måns Rullgård
AVOutputFormat null_muxer = {
890 87bdd3e5 Fabrice Bellard
    "null",
891
    "null video format",
892
    NULL,
893
    NULL,
894
    0,
895
#ifdef WORDS_BIGENDIAN
896
    CODEC_ID_PCM_S16BE,
897
#else
898
    CODEC_ID_PCM_S16LE,
899
#endif
900
    CODEC_ID_RAWVIDEO,
901 7a97dd84 Baptiste Coudurier
    NULL,
902 87bdd3e5 Fabrice Bellard
    null_write_packet,
903 494bbf58 Michael Niedermayer
    .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
904 87bdd3e5 Fabrice Bellard
};
905 a9e35095 Diego Biurrun
#endif //CONFIG_MUXERS