@@ -53,6 +53,13 @@ const FORMAT_NAME_TO_SHORT_TYPE = {
5353 'wav' : 'audio/wav' ,
5454}
5555
56+ // https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Containers#webm says that only
57+ // the following codecs are supported for webm:
58+ // - video: AV1, VP8, VP9
59+ // - audio: Opus, Vorbis
60+ const WEBM_AUDIO_CODECS = [ 'opus' , 'vorbis' ] ;
61+ const WEBM_VIDEO_CODECS = [ 'av1' , 'vp8' , 'vp9' ] ;
62+
5663/**
5764 * TODO: Reconcile this with file/sniffer.js findMimeType() which does signature matching.
5865 * @param {ProbeInfo } info
@@ -94,9 +101,16 @@ export function getShortMIMEString(info) {
94101 case 'ogg' :
95102 subType = 'ogg' ;
96103 break ;
97- // Should we detect .mkv files as x-matroska?
98104 case 'matroska,webm' :
99- subType = 'webm' ;
105+ let isWebM = true ;
106+ for ( const stream of info . streams ) {
107+ if ( ( stream . codec_type === 'audio' && ! WEBM_AUDIO_CODECS . includes ( stream . codec_name ) )
108+ || ( stream . codec_type === 'video' && ! WEBM_VIDEO_CODECS . includes ( stream . codec_name ) ) ) {
109+ isWebM = false ;
110+ break ;
111+ }
112+ }
113+ subType = isWebM ? 'webm' : 'x-matroska' ;
100114 break ;
101115 default :
102116 throw `Cannot handle format ${ formatName } yet. ` +
@@ -132,11 +146,12 @@ export function getFullMIMEString(info) {
132146 default :
133147 switch ( stream . codec_name ) {
134148 case 'aac' : codecFrags . add ( getMP4ACodecString ( stream ) ) ; break ;
135- case 'vorbis' : codecFrags . add ( 'vorbis' ) ; break ;
136- case 'opus' : codecFrags . add ( 'opus' ) ; break ;
137149 // I'm going off of what Chromium calls this one, with the dash.
138150 case 'ac3' : codecFrags . add ( 'ac-3' ) ; break ;
151+ case 'dts' : codecFrags . add ( 'dts' ) ; break ;
139152 case 'flac' : codecFrags . add ( 'flac' ) ; break ;
153+ case 'opus' : codecFrags . add ( 'opus' ) ; break ;
154+ case 'vorbis' : codecFrags . add ( 'vorbis' ) ; break ;
140155 default :
141156 throw `Could not handle audio codec_name ${ stream . codec_name } , ` +
142157 `codec_tag_string ${ stream . codec_tag_string } for file ${ info . format . filename } yet. ` +
@@ -153,10 +168,12 @@ export function getFullMIMEString(info) {
153168 case 'png' : continue ;
154169 default :
155170 switch ( stream . codec_name ) {
171+ case 'av1' : codecFrags . add ( 'av1' ) ; break ;
156172 case 'h264' : codecFrags . add ( getAVC1CodecString ( stream ) ) ; break ;
157- case 'mpeg2video' : codecFrags . add ( 'mpeg2video' ) ; break ;
158173 // Skip mjpeg as a video stream for the codecs string.
159174 case 'mjpeg' : break ;
175+ case 'mpeg2video' : codecFrags . add ( 'mpeg2video' ) ; break ;
176+ case 'vp8' : codecFrags . add ( 'vp8' ) ; break ;
160177 case 'vp9' : codecFrags . add ( getVP09CodecString ( stream ) ) ; break ;
161178 default :
162179 throw `Could not handle video codec_name ${ stream . codec_name } , ` +
0 commit comments