raw.c 21.6 KB
Newer Older
1
/*
2
 * RAW muxer and demuxer
F
Fabrice Bellard 已提交
3
 * Copyright (c) 2001 Fabrice Bellard.
4
 * Copyright (c) 2005 Alex Beregszaszi
F
Fabrice Bellard 已提交
5
 *
6 7 8
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
F
Fabrice Bellard 已提交
9 10
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
F
Fabrice Bellard 已提交
12
 *
13
 * FFmpeg is distributed in the hope that it will be useful,
F
Fabrice Bellard 已提交
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
F
Fabrice Bellard 已提交
15 16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
F
Fabrice Bellard 已提交
17
 *
F
Fabrice Bellard 已提交
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with FFmpeg; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
F
Fabrice Bellard 已提交
21 22
 */
#include "avformat.h"
23
#include "ac3_parser.h"
24
#include "raw.h"
25
#include "crc.h"
26
#include "bitstream.h"
F
Fabrice Bellard 已提交
27

28
#ifdef CONFIG_MUXERS
F
Fabrice Bellard 已提交
29
/* simple formats */
30 31 32 33 34 35 36 37
static int flac_write_header(struct AVFormatContext *s)
{
    static const uint8_t header[8] = {
        0x66, 0x4C, 0x61, 0x43, 0x80, 0x00, 0x00, 0x22
    };
    uint8_t *streaminfo = s->streams[0]->codec->extradata;
    int len = s->streams[0]->codec->extradata_size;
    if(streaminfo != NULL && len > 0) {
38 39
        put_buffer(s->pb, header, 8);
        put_buffer(s->pb, streaminfo, len);
40 41 42 43
    }
    return 0;
}

44 45 46 47 48 49 50

static int roq_write_header(struct AVFormatContext *s)
{
    static const uint8_t header[] = {
        0x84, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0x1E, 0x00
    };

51 52
    put_buffer(s->pb, header, 8);
    put_flush_packet(s->pb);
53 54 55 56

    return 0;
}

57
static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt)
F
Fabrice Bellard 已提交
58
{
59 60
    put_buffer(s->pb, pkt->data, pkt->size);
    put_flush_packet(s->pb);
F
Fabrice Bellard 已提交
61 62
    return 0;
}
63
#endif //CONFIG_MUXERS
F
Fabrice Bellard 已提交
64 65

/* raw input */
66
static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
F
Fabrice Bellard 已提交
67 68
{
    AVStream *st;
F
Fabrice Bellard 已提交
69
    int id;
F
Fabrice Bellard 已提交
70

F
Fabrice Bellard 已提交
71
    st = av_new_stream(s, 0);
F
Fabrice Bellard 已提交
72
    if (!st)
73
        return AVERROR(ENOMEM);
74

F
Fabrice Bellard 已提交
75 76
        id = s->iformat->value;
        if (id == CODEC_ID_RAWVIDEO) {
77
            st->codec->codec_type = CODEC_TYPE_VIDEO;
F
Fabrice Bellard 已提交
78
        } else {
79
            st->codec->codec_type = CODEC_TYPE_AUDIO;
F
Fabrice Bellard 已提交
80
        }
81
        st->codec->codec_id = id;
F
Fabrice Bellard 已提交
82

83
        switch(st->codec->codec_type) {
F
Fabrice Bellard 已提交
84
        case CODEC_TYPE_AUDIO:
85 86 87
            st->codec->sample_rate = ap->sample_rate;
            st->codec->channels = ap->channels;
            av_set_pts_info(st, 64, 1, st->codec->sample_rate);
F
Fabrice Bellard 已提交
88 89
            break;
        case CODEC_TYPE_VIDEO:
90 91 92 93
            if(ap->time_base.num)
                av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
            else
                av_set_pts_info(st, 64, 1, 25);
94 95 96 97 98
            st->codec->width = ap->width;
            st->codec->height = ap->height;
            st->codec->pix_fmt = ap->pix_fmt;
            if(st->codec->pix_fmt == PIX_FMT_NONE)
                st->codec->pix_fmt= PIX_FMT_YUV420P;
F
Fabrice Bellard 已提交
99 100
            break;
        default:
F
Fabrice Bellard 已提交
101
            return -1;
F
Fabrice Bellard 已提交
102 103 104 105
        }
    return 0;
}

F
Fabrice Bellard 已提交
106
#define RAW_PACKET_SIZE 1024
F
Fabrice Bellard 已提交
107

108
static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
F
Fabrice Bellard 已提交
109
{
110
    int ret, size, bps;
F
Fabrice Bellard 已提交
111
    //    AVStream *st = s->streams[0];
112

113
    size= RAW_PACKET_SIZE;
F
Fabrice Bellard 已提交
114

115
    ret= av_get_packet(s->pb, pkt, size);
F
Fabrice Bellard 已提交
116 117

    pkt->stream_index = 0;
F
Fabrice Bellard 已提交
118
    if (ret <= 0) {
119
        return AVERROR(EIO);
F
Fabrice Bellard 已提交
120 121 122 123
    }
    /* note: we need to modify the packet size here to handle the last
       packet */
    pkt->size = ret;
124 125 126 127 128 129

    bps= av_get_bits_per_sample(s->streams[0]->codec->codec_id);
    assert(bps); // if false there IS a bug elsewhere (NOT in this function)
    pkt->dts=
    pkt->pts= pkt->pos*8 / (bps * s->streams[0]->codec->channels);

F
Fabrice Bellard 已提交
130 131 132
    return ret;
}

133 134 135 136 137 138 139
static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
{
    int ret, size;

    size = RAW_PACKET_SIZE;

    if (av_new_packet(pkt, size) < 0)
140
        return AVERROR(EIO);
141

142
    pkt->pos= url_ftell(s->pb);
143
    pkt->stream_index = 0;
144
    ret = get_partial_buffer(s->pb, pkt->data, size);
145 146
    if (ret <= 0) {
        av_free_packet(pkt);
147
        return AVERROR(EIO);
148 149 150 151 152
    }
    pkt->size = ret;
    return ret;
}

153 154 155 156
// http://www.artificis.hu/files/texts/ingenient.txt
static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt)
{
    int ret, size, w, h, unk1, unk2;
157

158
    if (get_le32(s->pb) != MKTAG('M', 'J', 'P', 'G'))
159
        return AVERROR(EIO); // FIXME
160

161
    size = get_le32(s->pb);
162

163 164
    w = get_le16(s->pb);
    h = get_le16(s->pb);
165

166 167 168 169 170
    url_fskip(s->pb, 8); // zero + size (padded?)
    url_fskip(s->pb, 2);
    unk1 = get_le16(s->pb);
    unk2 = get_le16(s->pb);
    url_fskip(s->pb, 22); // ascii timestamp
171

172
    av_log(NULL, AV_LOG_DEBUG, "Ingenient packet: size=%d, width=%d, height=%d, unk1=%d unk2=%d\n",
173
        size, w, h, unk1, unk2);
174 175

    if (av_new_packet(pkt, size) < 0)
176
        return AVERROR(EIO);
177

178
    pkt->pos = url_ftell(s->pb);
179
    pkt->stream_index = 0;
180
    ret = get_buffer(s->pb, pkt->data, size);
181 182
    if (ret <= 0) {
        av_free_packet(pkt);
183
        return AVERROR(EIO);
184 185 186 187 188
    }
    pkt->size = ret;
    return ret;
}

189
static int raw_read_close(AVFormatContext *s)
F
Fabrice Bellard 已提交
190 191 192 193
{
    return 0;
}

194
int pcm_read_seek(AVFormatContext *s,
195
                  int stream_index, int64_t timestamp, int flags)
F
Fabrice Bellard 已提交
196 197 198 199 200 201
{
    AVStream *st;
    int block_align, byte_rate;
    int64_t pos;

    st = s->streams[0];
202 203 204 205 206

    block_align = st->codec->block_align ? st->codec->block_align :
        (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3;
    byte_rate = st->codec->bit_rate ? st->codec->bit_rate >> 3 :
        block_align * st->codec->sample_rate;
207

F
Fabrice Bellard 已提交
208 209 210 211
    if (block_align <= 0 || byte_rate <= 0)
        return -1;

    /* compute the position by aligning it to block_align */
212 213
    pos = av_rescale_rnd(timestamp * byte_rate,
                         st->time_base.num,
214 215 216
                         st->time_base.den * (int64_t)block_align,
                         (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
    pos *= block_align;
F
Fabrice Bellard 已提交
217 218

    /* recompute exact position */
M
Michael Niedermayer 已提交
219
    st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
220
    url_fseek(s->pb, pos + s->data_offset, SEEK_SET);
F
Fabrice Bellard 已提交
221 222 223
    return 0;
}

224 225 226 227 228 229 230 231
/* ac3 read */
static int ac3_read_header(AVFormatContext *s,
                           AVFormatParameters *ap)
{
    AVStream *st;

    st = av_new_stream(s, 0);
    if (!st)
232
        return AVERROR(ENOMEM);
233

234 235
    st->codec->codec_type = CODEC_TYPE_AUDIO;
    st->codec->codec_id = CODEC_ID_AC3;
A
Aurelien Jacobs 已提交
236
    st->need_parsing = AVSTREAM_PARSE_FULL;
237 238 239 240
    /* the parameters will be extracted from the compressed bitstream */
    return 0;
}

241 242 243 244 245 246 247
static int shorten_read_header(AVFormatContext *s,
                               AVFormatParameters *ap)
{
    AVStream *st;

    st = av_new_stream(s, 0);
    if (!st)
248
        return AVERROR(ENOMEM);
249 250
    st->codec->codec_type = CODEC_TYPE_AUDIO;
    st->codec->codec_id = CODEC_ID_SHORTEN;
A
Aurelien Jacobs 已提交
251
    st->need_parsing = AVSTREAM_PARSE_FULL;
252 253 254 255
    /* the parameters will be extracted from the compressed bitstream */
    return 0;
}

256 257 258 259 260 261 262 263
/* flac read */
static int flac_read_header(AVFormatContext *s,
                            AVFormatParameters *ap)
{
    AVStream *st;

    st = av_new_stream(s, 0);
    if (!st)
264
        return AVERROR(ENOMEM);
265 266
    st->codec->codec_type = CODEC_TYPE_AUDIO;
    st->codec->codec_id = CODEC_ID_FLAC;
A
Aurelien Jacobs 已提交
267
    st->need_parsing = AVSTREAM_PARSE_FULL;
268 269 270 271
    /* the parameters will be extracted from the compressed bitstream */
    return 0;
}

272 273 274 275 276 277 278 279
/* dts read */
static int dts_read_header(AVFormatContext *s,
                           AVFormatParameters *ap)
{
    AVStream *st;

    st = av_new_stream(s, 0);
    if (!st)
280
        return AVERROR(ENOMEM);
281

282 283
    st->codec->codec_type = CODEC_TYPE_AUDIO;
    st->codec->codec_id = CODEC_ID_DTS;
A
Aurelien Jacobs 已提交
284
    st->need_parsing = AVSTREAM_PARSE_FULL;
285 286 287 288
    /* the parameters will be extracted from the compressed bitstream */
    return 0;
}

M
Måns Rullgård 已提交
289 290 291 292 293 294 295 296
/* aac read */
static int aac_read_header(AVFormatContext *s,
                           AVFormatParameters *ap)
{
    AVStream *st;

    st = av_new_stream(s, 0);
    if (!st)
297
        return AVERROR(ENOMEM);
M
Måns Rullgård 已提交
298 299 300

    st->codec->codec_type = CODEC_TYPE_AUDIO;
    st->codec->codec_id = CODEC_ID_AAC;
A
Aurelien Jacobs 已提交
301
    st->need_parsing = AVSTREAM_PARSE_FULL;
M
Måns Rullgård 已提交
302 303 304 305
    /* the parameters will be extracted from the compressed bitstream */
    return 0;
}

F
Fabrice Bellard 已提交
306 307 308 309 310 311
/* mpeg1/h263 input */
static int video_read_header(AVFormatContext *s,
                             AVFormatParameters *ap)
{
    AVStream *st;

F
Fabrice Bellard 已提交
312
    st = av_new_stream(s, 0);
F
Fabrice Bellard 已提交
313
    if (!st)
314
        return AVERROR(ENOMEM);
F
Fabrice Bellard 已提交
315

316 317
    st->codec->codec_type = CODEC_TYPE_VIDEO;
    st->codec->codec_id = s->iformat->value;
A
Aurelien Jacobs 已提交
318
    st->need_parsing = AVSTREAM_PARSE_FULL;
F
Fabrice Bellard 已提交
319

F
Fabrice Bellard 已提交
320
    /* for mjpeg, specify frame rate */
D
Diego Biurrun 已提交
321
    /* for mpeg4 specify it too (most mpeg4 streams do not have the fixed_vop_rate set ...)*/
322
    if (ap->time_base.num) {
323
        av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
324
    } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
325 326
                st->codec->codec_id == CODEC_ID_MPEG4 ||
                st->codec->codec_id == CODEC_ID_H264) {
327
        av_set_pts_info(st, 64, 1, 25);
F
Fabrice Bellard 已提交
328
    }
329

F
Fabrice Bellard 已提交
330 331 332
    return 0;
}

333 334 335
#define SEQ_START_CODE          0x000001b3
#define GOP_START_CODE          0x000001b8
#define PICTURE_START_CODE      0x00000100
336 337
#define SLICE_START_CODE        0x00000101
#define PACK_START_CODE         0x000001ba
338 339
#define VIDEO_ID                0x000001e0
#define AUDIO_ID                0x000001c0
F
Fabrice Bellard 已提交
340 341 342

static int mpegvideo_probe(AVProbeData *p)
{
343
    uint32_t code= -1;
344
    int pic=0, seq=0, slice=0, pspack=0, pes=0;
345 346 347 348 349 350 351 352 353 354 355
    int i;

    for(i=0; i<p->buf_size; i++){
        code = (code<<8) + p->buf[i];
        if ((code & 0xffffff00) == 0x100) {
            switch(code){
            case     SEQ_START_CODE:   seq++; break;
            case PICTURE_START_CODE:   pic++; break;
            case   SLICE_START_CODE: slice++; break;
            case    PACK_START_CODE: pspack++; break;
            }
356 357
            if     ((code & 0x1f0) == VIDEO_ID)   pes++;
            else if((code & 0x1e0) == AUDIO_ID)   pes++;
358
        }
F
Fabrice Bellard 已提交
359
    }
360
    if(seq && seq*9<=pic*10 && pic*9<=slice*10 && !pspack && !pes)
361
        return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
F
Fabrice Bellard 已提交
362 363 364
    return 0;
}

365 366 367 368 369 370
#define VISUAL_OBJECT_START_CODE       0x000001b5
#define VOP_START_CODE                 0x000001b6

static int mpeg4video_probe(AVProbeData *probe_packet)
{
    uint32_t temp_buffer= -1;
371
    int VO=0, VOL=0, VOP = 0, VISO = 0, res=0;
372 373 374 375
    int i;

    for(i=0; i<probe_packet->buf_size; i++){
        temp_buffer = (temp_buffer<<8) + probe_packet->buf[i];
376 377 378 379 380 381 382 383 384
        if ((temp_buffer & 0xffffff00) != 0x100)
            continue;

        if (temp_buffer == VOP_START_CODE)                         VOP++;
        else if (temp_buffer == VISUAL_OBJECT_START_CODE)          VISO++;
        else if (temp_buffer < 0x120)                              VO++;
        else if (temp_buffer < 0x130)                              VOL++;
        else if (   !(0x1AF < temp_buffer && temp_buffer < 0x1B7)
                 && !(0x1B9 < temp_buffer && temp_buffer < 0x1C4)) res++;
385 386
    }

387
    if ( VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res==0)
388 389 390 391
        return AVPROBE_SCORE_MAX/2;
    return 0;
}

392 393 394 395 396 397 398 399 400 401 402 403 404
static int h263_probe(AVProbeData *p)
{
    int code;
    const uint8_t *d;

    d = p->buf;
    code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2);
    if (code == 0x20) {
        return 50;
    }
    return 0;
}

405 406 407 408 409 410 411 412 413 414 415 416 417
static int h261_probe(AVProbeData *p)
{
    int code;
    const uint8_t *d;

    d = p->buf;
    code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4);
    if (code == 0x10) {
        return 50;
    }
    return 0;
}

418 419
static int ac3_probe(AVProbeData *p)
{
420
    int max_frames, first_frames = 0, frames;
421 422
    uint8_t *buf, *buf2, *end;
    AC3HeaderInfo hdr;
423
    GetBitContext gbc;
424

425 426
    max_frames = 0;
    buf = p->buf;
427
    end = buf + p->buf_size;
428 429 430

    for(; buf < end; buf++) {
        buf2 = buf;
431

432
        for(frames = 0; buf2 < end; frames++) {
433 434
            init_get_bits(&gbc, buf2, 54);
            if(ff_ac3_parse_header(&gbc, &hdr) < 0)
435
                break;
436 437 438
            if(buf2 + hdr.frame_size > end ||
               av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2))
                break;
439 440 441 442 443 444 445
            buf2 += hdr.frame_size;
        }
        max_frames = FFMAX(max_frames, frames);
        if(buf == p->buf)
            first_frames = frames;
    }
    if   (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4;
446
    else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2;
447 448
    else if(max_frames>=1) return 1;
    else                   return 0;
449 450
}

M
Michael Niedermayer 已提交
451 452 453
static int flac_probe(AVProbeData *p)
{
    if(memcmp(p->buf, "fLaC", 4)) return 0;
M
Michael Niedermayer 已提交
454
    else                          return AVPROBE_SCORE_MAX / 2;
M
Michael Niedermayer 已提交
455 456
}

457
AVInputFormat shorten_demuxer = {
458
    "shn",
459
    "raw shorten",
460 461 462 463 464
    0,
    NULL,
    shorten_read_header,
    raw_read_partial_packet,
    raw_read_close,
465
    .flags= AVFMT_GENERIC_INDEX,
466 467 468
    .extensions = "shn",
};

469
AVInputFormat flac_demuxer = {
470 471 472
    "flac",
    "raw flac",
    0,
M
Michael Niedermayer 已提交
473
    flac_probe,
474 475 476
    flac_read_header,
    raw_read_partial_packet,
    raw_read_close,
477
    .flags= AVFMT_GENERIC_INDEX,
478 479 480
    .extensions = "flac",
};

481
#ifdef CONFIG_MUXERS
482
AVOutputFormat flac_muxer = {
483 484 485 486 487 488 489 490 491
    "flac",
    "raw flac",
    "audio/x-flac",
    "flac",
    0,
    CODEC_ID_FLAC,
    0,
    flac_write_header,
    raw_write_packet,
492
    .flags= AVFMT_NOTIMESTAMPS,
493 494 495
};
#endif //CONFIG_MUXERS

496
#ifdef CONFIG_AC3_DEMUXER
497
AVInputFormat ac3_demuxer = {
F
Fabrice Bellard 已提交
498 499 500
    "ac3",
    "raw ac3",
    0,
501
    ac3_probe,
502
    ac3_read_header,
503
    raw_read_partial_packet,
F
Fabrice Bellard 已提交
504
    raw_read_close,
505
    .flags= AVFMT_GENERIC_INDEX,
506
    .extensions = "ac3",
F
Fabrice Bellard 已提交
507
};
508
#endif
F
Fabrice Bellard 已提交
509

510
#ifdef CONFIG_MUXERS
511
AVOutputFormat ac3_muxer = {
F
Fabrice Bellard 已提交
512 513
    "ac3",
    "raw ac3",
514
    "audio/x-ac3",
F
Fabrice Bellard 已提交
515
    "ac3",
F
Fabrice Bellard 已提交
516
    0,
F
Fabrice Bellard 已提交
517 518
    CODEC_ID_AC3,
    0,
519
    NULL,
F
Fabrice Bellard 已提交
520
    raw_write_packet,
521
    .flags= AVFMT_NOTIMESTAMPS,
F
Fabrice Bellard 已提交
522
};
B
Benjamin Larsson 已提交
523 524 525 526 527 528 529 530 531 532 533 534 535 536

AVOutputFormat dts_muxer = {
    "dts",
    "raw dts",
    "audio/x-dca",
    "dts",
    0,
    CODEC_ID_DTS,
    0,
    NULL,
    raw_write_packet,
    .flags= AVFMT_NOTIMESTAMPS,
};

537
#endif //CONFIG_MUXERS
F
Fabrice Bellard 已提交
538

539
AVInputFormat dts_demuxer = {
540 541 542 543 544 545 546
    "dts",
    "raw dts",
    0,
    NULL,
    dts_read_header,
    raw_read_partial_packet,
    raw_read_close,
547
    .flags= AVFMT_GENERIC_INDEX,
548 549 550
    .extensions = "dts",
};

551
AVInputFormat aac_demuxer = {
M
Måns Rullgård 已提交
552 553 554 555 556 557 558
    "aac",
    "ADTS AAC",
    0,
    NULL,
    aac_read_header,
    raw_read_partial_packet,
    raw_read_close,
559
    .flags= AVFMT_GENERIC_INDEX,
M
Måns Rullgård 已提交
560 561 562
    .extensions = "aac",
};

563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
#ifdef CONFIG_ROQ_MUXER
AVOutputFormat roq_muxer =
{
    "RoQ",
    "Id RoQ format",
    NULL,
    "roq",
    0,
    CODEC_ID_ROQ_DPCM,
    CODEC_ID_ROQ,
    roq_write_header,
    raw_write_packet,
};
#endif //CONFIG_ROQ_MUXER

578
AVInputFormat h261_demuxer = {
579 580 581 582 583 584 585
    "h261",
    "raw h261",
    0,
    h261_probe,
    video_read_header,
    raw_read_partial_packet,
    raw_read_close,
586
    .flags= AVFMT_GENERIC_INDEX,
587 588 589 590
    .extensions = "h261",
    .value = CODEC_ID_H261,
};

591
#ifdef CONFIG_MUXERS
592
AVOutputFormat h261_muxer = {
593 594 595 596 597 598 599
    "h261",
    "raw h261",
    "video/x-h261",
    "h261",
    0,
    0,
    CODEC_ID_H261,
600
    NULL,
601
    raw_write_packet,
602
    .flags= AVFMT_NOTIMESTAMPS,
603
};
604
#endif //CONFIG_MUXERS
605

606
AVInputFormat h263_demuxer = {
607 608 609 610 611
    "h263",
    "raw h263",
    0,
    h263_probe,
    video_read_header,
612
    raw_read_partial_packet,
613
    raw_read_close,
614
    .flags= AVFMT_GENERIC_INDEX,
615 616 617 618
//    .extensions = "h263", //FIXME remove after writing mpeg4_probe
    .value = CODEC_ID_H263,
};

619
#ifdef CONFIG_MUXERS
620
AVOutputFormat h263_muxer = {
F
Fabrice Bellard 已提交
621 622 623 624 625
    "h263",
    "raw h263",
    "video/x-h263",
    "h263",
    0,
F
Fabrice Bellard 已提交
626
    0,
F
Fabrice Bellard 已提交
627
    CODEC_ID_H263,
628
    NULL,
F
Fabrice Bellard 已提交
629
    raw_write_packet,
630
    .flags= AVFMT_NOTIMESTAMPS,
F
Fabrice Bellard 已提交
631
};
632
#endif //CONFIG_MUXERS
F
Fabrice Bellard 已提交
633

634
AVInputFormat m4v_demuxer = {
M
Michael Niedermayer 已提交
635 636 637
    "m4v",
    "raw MPEG4 video format",
    0,
638
    mpeg4video_probe, /** probing for mpeg4 data */
M
Michael Niedermayer 已提交
639
    video_read_header,
640
    raw_read_partial_packet,
M
Michael Niedermayer 已提交
641
    raw_read_close,
642
    .flags= AVFMT_GENERIC_INDEX,
643 644
    .extensions = "m4v", //FIXME remove after writing mpeg4_probe
    .value = CODEC_ID_MPEG4,
M
Michael Niedermayer 已提交
645 646
};

647
#ifdef CONFIG_MUXERS
648
AVOutputFormat m4v_muxer = {
649 650 651 652 653 654 655
    "m4v",
    "raw MPEG4 video format",
    NULL,
    "m4v",
    0,
    CODEC_ID_NONE,
    CODEC_ID_MPEG4,
656
    NULL,
657
    raw_write_packet,
658
    .flags= AVFMT_NOTIMESTAMPS,
659
};
660
#endif //CONFIG_MUXERS
661

662
AVInputFormat h264_demuxer = {
M
Michael Niedermayer 已提交
663 664 665 666 667
    "h264",
    "raw H264 video format",
    0,
    NULL /*mpegvideo_probe*/,
    video_read_header,
668
    raw_read_partial_packet,
M
Michael Niedermayer 已提交
669
    raw_read_close,
670
    .flags= AVFMT_GENERIC_INDEX,
M
.264  
Michael Niedermayer 已提交
671
    .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
M
Michael Niedermayer 已提交
672 673 674
    .value = CODEC_ID_H264,
};

675
#ifdef CONFIG_MUXERS
676
AVOutputFormat h264_muxer = {
M
Michael Niedermayer 已提交
677 678 679 680 681 682 683
    "h264",
    "raw H264 video format",
    NULL,
    "h264",
    0,
    CODEC_ID_NONE,
    CODEC_ID_H264,
684
    NULL,
M
Michael Niedermayer 已提交
685
    raw_write_packet,
686
    .flags= AVFMT_NOTIMESTAMPS,
M
Michael Niedermayer 已提交
687
};
688
#endif //CONFIG_MUXERS
M
Michael Niedermayer 已提交
689

690
AVInputFormat mpegvideo_demuxer = {
F
Fabrice Bellard 已提交
691 692 693 694
    "mpegvideo",
    "MPEG video",
    0,
    mpegvideo_probe,
F
Fabrice Bellard 已提交
695
    video_read_header,
696
    raw_read_partial_packet,
F
Fabrice Bellard 已提交
697
    raw_read_close,
698
    .flags= AVFMT_GENERIC_INDEX,
699
    .value = CODEC_ID_MPEG1VIDEO,
F
Fabrice Bellard 已提交
700 701
};

702
#ifdef CONFIG_MUXERS
703
AVOutputFormat mpeg1video_muxer = {
F
Fabrice Bellard 已提交
704
    "mpeg1video",
F
Fabrice Bellard 已提交
705 706
    "MPEG video",
    "video/x-mpeg",
707
    "mpg,mpeg,m1v",
F
Fabrice Bellard 已提交
708
    0,
F
Fabrice Bellard 已提交
709
    0,
F
Fabrice Bellard 已提交
710
    CODEC_ID_MPEG1VIDEO,
711
    NULL,
F
Fabrice Bellard 已提交
712
    raw_write_packet,
713
    .flags= AVFMT_NOTIMESTAMPS,
F
Fabrice Bellard 已提交
714
};
715
#endif //CONFIG_MUXERS
F
Fabrice Bellard 已提交
716

717
#ifdef CONFIG_MUXERS
718
AVOutputFormat mpeg2video_muxer = {
719 720 721 722 723 724 725
    "mpeg2video",
    "MPEG2 video",
    NULL,
    "m2v",
    0,
    0,
    CODEC_ID_MPEG2VIDEO,
726
    NULL,
727
    raw_write_packet,
728
    .flags= AVFMT_NOTIMESTAMPS,
729
};
730
#endif //CONFIG_MUXERS
731

732
AVInputFormat mjpeg_demuxer = {
F
Fabrice Bellard 已提交
733 734 735
    "mjpeg",
    "MJPEG video",
    0,
F
Fabrice Bellard 已提交
736
    NULL,
F
Fabrice Bellard 已提交
737
    video_read_header,
738
    raw_read_partial_packet,
F
Fabrice Bellard 已提交
739
    raw_read_close,
740
    .flags= AVFMT_GENERIC_INDEX,
741 742
    .extensions = "mjpg,mjpeg",
    .value = CODEC_ID_MJPEG,
F
Fabrice Bellard 已提交
743 744
};

745
AVInputFormat ingenient_demuxer = {
746 747 748 749 750 751 752
    "ingenient",
    "Ingenient MJPEG",
    0,
    NULL,
    video_read_header,
    ingenient_read_packet,
    raw_read_close,
753
    .flags= AVFMT_GENERIC_INDEX,
754 755 756 757
    .extensions = "cgi", // FIXME
    .value = CODEC_ID_MJPEG,
};

758
#ifdef CONFIG_MUXERS
759
AVOutputFormat mjpeg_muxer = {
F
Fabrice Bellard 已提交
760 761 762 763
    "mjpeg",
    "MJPEG video",
    "video/x-mjpeg",
    "mjpg,mjpeg",
F
Fabrice Bellard 已提交
764 765
    0,
    0,
F
Fabrice Bellard 已提交
766
    CODEC_ID_MJPEG,
767
    NULL,
F
Fabrice Bellard 已提交
768
    raw_write_packet,
769
    .flags= AVFMT_NOTIMESTAMPS,
F
Fabrice Bellard 已提交
770
};
771
#endif //CONFIG_MUXERS
F
Fabrice Bellard 已提交
772

K
Kostya Shishkov 已提交
773 774 775 776 777 778 779 780 781 782 783 784
AVInputFormat vc1_demuxer = {
    "vc1",
    "raw vc1",
    0,
    NULL /* vc1_probe */,
    video_read_header,
    raw_read_partial_packet,
    raw_read_close,
    .extensions = "vc1",
    .value = CODEC_ID_VC1,
};

F
Fabrice Bellard 已提交
785
/* pcm formats */
786

F
Fabrice Bellard 已提交
787
#define PCMINPUTDEF(name, long_name, ext, codec) \
788
AVInputFormat pcm_ ## name ## _demuxer = {\
789 790 791 792 793 794 795
    #name,\
    long_name,\
    0,\
    NULL,\
    raw_read_header,\
    raw_read_packet,\
    raw_read_close,\
F
Fabrice Bellard 已提交
796
    pcm_read_seek,\
797
    .flags= AVFMT_GENERIC_INDEX,\
798 799 800 801
    .extensions = ext,\
    .value = codec,\
};

802
#define PCMOUTPUTDEF(name, long_name, ext, codec) \
803
AVOutputFormat pcm_ ## name ## _muxer = {\
F
Fabrice Bellard 已提交
804 805 806 807 808 809 810
    #name,\
    long_name,\
    NULL,\
    ext,\
    0,\
    codec,\
    0,\
811
    NULL,\
F
Fabrice Bellard 已提交
812
    raw_write_packet,\
813
    .flags= AVFMT_NOTIMESTAMPS,\
F
Fabrice Bellard 已提交
814
};
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829


#if !defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
#define PCMDEF(name, long_name, ext, codec) \
        PCMINPUTDEF(name, long_name, ext, codec)
#elif defined(CONFIG_MUXERS) && !defined(CONFIG_DEMUXERS)
#define PCMDEF(name, long_name, ext, codec) \
        PCMOUTPUTDEF(name, long_name, ext, codec)
#elif defined(CONFIG_MUXERS) && defined(CONFIG_DEMUXERS)
#define PCMDEF(name, long_name, ext, codec) \
        PCMINPUTDEF(name, long_name, ext, codec)\
        PCMOUTPUTDEF(name, long_name, ext, codec)
#else
#define PCMDEF(name, long_name, ext, codec)
#endif
F
Fabrice Bellard 已提交
830 831

#ifdef WORDS_BIGENDIAN
F
Fabrice Bellard 已提交
832 833
#define BE_DEF(s) s
#define LE_DEF(s) NULL
F
Fabrice Bellard 已提交
834
#else
F
Fabrice Bellard 已提交
835 836
#define BE_DEF(s) NULL
#define LE_DEF(s) s
F
Fabrice Bellard 已提交
837 838 839
#endif


840
PCMDEF(s16le, "pcm signed 16 bit little endian format",
F
Fabrice Bellard 已提交
841
       LE_DEF("sw"), CODEC_ID_PCM_S16LE)
F
Fabrice Bellard 已提交
842

843
PCMDEF(s16be, "pcm signed 16 bit big endian format",
F
Fabrice Bellard 已提交
844
       BE_DEF("sw"), CODEC_ID_PCM_S16BE)
F
Fabrice Bellard 已提交
845

846
PCMDEF(u16le, "pcm unsigned 16 bit little endian format",
F
Fabrice Bellard 已提交
847
       LE_DEF("uw"), CODEC_ID_PCM_U16LE)
F
Fabrice Bellard 已提交
848

849
PCMDEF(u16be, "pcm unsigned 16 bit big endian format",
F
Fabrice Bellard 已提交
850
       BE_DEF("uw"), CODEC_ID_PCM_U16BE)
F
Fabrice Bellard 已提交
851

852
PCMDEF(s8, "pcm signed 8 bit format",
F
Fabrice Bellard 已提交
853
       "sb", CODEC_ID_PCM_S8)
F
Fabrice Bellard 已提交
854

855
PCMDEF(u8, "pcm unsigned 8 bit format",
F
Fabrice Bellard 已提交
856
       "ub", CODEC_ID_PCM_U8)
F
Fabrice Bellard 已提交
857

858
PCMDEF(mulaw, "pcm mu law format",
F
Fabrice Bellard 已提交
859
       "ul", CODEC_ID_PCM_MULAW)
F
Fabrice Bellard 已提交
860

861
PCMDEF(alaw, "pcm A law format",
F
Fabrice Bellard 已提交
862
       "al", CODEC_ID_PCM_ALAW)
F
Fabrice Bellard 已提交
863

864
static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
F
Fabrice Bellard 已提交
865 866 867 868
{
    int packet_size, ret, width, height;
    AVStream *st = s->streams[0];

869 870
    width = st->codec->width;
    height = st->codec->height;
F
Fabrice Bellard 已提交
871

872
    packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
873
    if (packet_size < 0)
M
Michael Niedermayer 已提交
874
        return -1;
F
Fabrice Bellard 已提交
875

876
    ret= av_get_packet(s->pb, pkt, packet_size);
877 878
    pkt->pts=
    pkt->dts= pkt->pos / packet_size;
F
Fabrice Bellard 已提交
879 880

    pkt->stream_index = 0;
M
Michael Niedermayer 已提交
881
    if (ret != packet_size) {
882
        return AVERROR(EIO);
F
Fabrice Bellard 已提交
883 884 885 886 887
    } else {
        return 0;
    }
}

888
AVInputFormat rawvideo_demuxer = {
F
Fabrice Bellard 已提交
889 890 891 892 893 894 895
    "rawvideo",
    "raw video format",
    0,
    NULL,
    raw_read_header,
    rawvideo_read_packet,
    raw_read_close,
896
    .flags= AVFMT_GENERIC_INDEX,
897
    .extensions = "yuv,cif,qcif,rgb",
898
    .value = CODEC_ID_RAWVIDEO,
F
Fabrice Bellard 已提交
899 900
};

901
#ifdef CONFIG_MUXERS
902
AVOutputFormat rawvideo_muxer = {
F
Fabrice Bellard 已提交
903 904 905
    "rawvideo",
    "raw video format",
    NULL,
B
Benoit Fouet 已提交
906
    "yuv,rgb",
F
Fabrice Bellard 已提交
907
    0,
F
Fabrice Bellard 已提交
908 909
    CODEC_ID_NONE,
    CODEC_ID_RAWVIDEO,
910
    NULL,
F
Fabrice Bellard 已提交
911
    raw_write_packet,
912
    .flags= AVFMT_NOTIMESTAMPS,
F
Fabrice Bellard 已提交
913
};
914
#endif //CONFIG_MUXERS
F
Fabrice Bellard 已提交
915

916
#ifdef CONFIG_MUXERS
917
static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
918 919 920 921
{
    return 0;
}

922
AVOutputFormat null_muxer = {
923 924 925 926 927 928 929 930 931 932 933
    "null",
    "null video format",
    NULL,
    NULL,
    0,
#ifdef WORDS_BIGENDIAN
    CODEC_ID_PCM_S16BE,
#else
    CODEC_ID_PCM_S16LE,
#endif
    CODEC_ID_RAWVIDEO,
934
    NULL,
935
    null_write_packet,
936
    .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
937
};
938
#endif //CONFIG_MUXERS