Statistics
| Branch: | Revision:

ffmpeg / libavformat / raw.c @ 7e1720de

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