Revision 316d6c15 libavformat/matroskaenc.c

View differences:

libavformat/matroskaenc.c
65 65
    int             write_dts;
66 66
} mkv_track;
67 67

  
68
#define MODE_MATROSKAv2 0x01
69
#define MODE_WEBM       0x02
70

  
68 71
typedef struct MatroskaMuxContext {
72
    int             mode;
69 73
    ByteIOContext   *dyn_bc;
70 74
    ebml_master     segment;
71 75
    int64_t         segment_offset;
......
565 569
            }
566 570
        }
567 571

  
572
        if (mkv->mode == MODE_WEBM && !(codec->codec_id == CODEC_ID_VP8 ||
573
                                        codec->codec_id == CODEC_ID_VORBIS)) {
574
            av_log(s, AV_LOG_ERROR,
575
                   "Only VP8 video and Vorbis audio are supported for WebM.\n");
576
            return AVERROR(EINVAL);
577
        }
578

  
568 579
        switch (codec->codec_type) {
569 580
            case AVMEDIA_TYPE_VIDEO:
570 581
                put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_VIDEO);
......
686 697
    AVMetadataTag *tag;
687 698
    int ret;
688 699

  
700
    if (!strcmp(s->oformat->name, "webm")) mkv->mode = MODE_WEBM;
701
    else                                   mkv->mode = MODE_MATROSKAv2;
702

  
689 703
    mkv->md5_ctx = av_mallocz(av_md5_size);
690 704
    av_md5_init(mkv->md5_ctx);
691 705
    mkv->tracks = av_mallocz(s->nb_streams * sizeof(*mkv->tracks));
......
695 709
    put_ebml_uint   (pb, EBML_ID_EBMLREADVERSION    ,           1);
696 710
    put_ebml_uint   (pb, EBML_ID_EBMLMAXIDLENGTH    ,           4);
697 711
    put_ebml_uint   (pb, EBML_ID_EBMLMAXSIZELENGTH  ,           8);
698
    put_ebml_string (pb, EBML_ID_DOCTYPE            ,  "matroska");
712
    put_ebml_string (pb, EBML_ID_DOCTYPE            , s->oformat->name);
699 713
    put_ebml_uint   (pb, EBML_ID_DOCTYPEVERSION     ,           2);
700 714
    put_ebml_uint   (pb, EBML_ID_DOCTYPEREADVERSION ,           2);
701 715
    end_ebml_master(pb, ebml_header);
......
738 752
    ret = mkv_write_tracks(s);
739 753
    if (ret < 0) return ret;
740 754

  
741
    ret = mkv_write_chapters(s);
742
    if (ret < 0) return ret;
755
    if (mkv->mode != MODE_WEBM) {
756
        ret = mkv_write_chapters(s);
757
        if (ret < 0) return ret;
758
    }
743 759

  
744 760
    if (url_is_streamed(s->pb))
745 761
        mkv_write_seekhead(pb, mkv->main_seekhead);
......
1035 1051
    return 0;
1036 1052
}
1037 1053

  
1054
#if CONFIG_MATROSKA_MUXER
1038 1055
AVOutputFormat matroska_muxer = {
1039 1056
    "matroska",
1040 1057
    NULL_IF_CONFIG_SMALL("Matroska file format"),
......
1050 1067
    .codec_tag = (const AVCodecTag* const []){ff_codec_bmp_tags, ff_codec_wav_tags, 0},
1051 1068
    .subtitle_codec = CODEC_ID_TEXT,
1052 1069
};
1070
#endif
1071

  
1072
#if CONFIG_WEBM_MUXER
1073
AVOutputFormat webm_muxer = {
1074
    "webm",
1075
    NULL_IF_CONFIG_SMALL("WebM file format"),
1076
    "video/webm",
1077
    "webm",
1078
    sizeof(MatroskaMuxContext),
1079
    CODEC_ID_VORBIS,
1080
    CODEC_ID_VP8,
1081
    mkv_write_header,
1082
    mkv_write_packet,
1083
    mkv_write_trailer,
1084
    .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
1085
};
1086
#endif
1053 1087

  
1088
#if CONFIG_MATROSKA_AUDIO_MUXER
1054 1089
AVOutputFormat matroska_audio_muxer = {
1055 1090
    "matroska",
1056 1091
    NULL_IF_CONFIG_SMALL("Matroska file format"),
......
1065 1100
    .flags = AVFMT_GLOBALHEADER,
1066 1101
    .codec_tag = (const AVCodecTag* const []){ff_codec_wav_tags, 0},
1067 1102
};
1103
#endif

Also available in: Unified diff