Statistics
| Branch: | Revision:

ffmpeg / libavformat / raw.c @ 8509fc7b

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