Statistics
| Branch: | Revision:

ffmpeg / libavformat / raw.c @ 3abe5fbd

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