Recognize webm and matroska files. See also Bug 23888

Currently all webm files are stored as video/webm. It is not possible to detect 
wether this file is an audio file without using a full parser. This is why We should 
really move mime and mediatype accessors to the MediaHandlers.

Using video/x-matroska for MKV files. There is no official mime for MKV (though the 
webm isn't official either, but everyone is already using it apparently).
This commit is contained in:
Derk-Jan Hartman 2010-07-28 19:24:00 +00:00
parent 40df199e9e
commit bcd3dd1943
3 changed files with 28 additions and 1 deletions

View file

@ -396,7 +396,8 @@ class MimeMagic {
'xbm',
// Formats we recognize magic numbers for
'djvu', 'ogx', 'ogg', 'ogv', 'oga', 'spx', 'mid', 'pdf', 'wmf', 'xcf',
'djvu', 'ogx', 'ogg', 'ogv', 'oga', 'spx',
'mid', 'pdf', 'wmf', 'xcf', 'webm', 'mkv', 'mka',
// XML formats we sure hope we recognize reliably
'svg',
@ -468,6 +469,24 @@ class MimeMagic {
}
}
/* Look for WebM and Matroska files */
if( strncmp( $head, pack( "C4", 0x1a, 0x45, 0xdf, 0xa3 ), 4 ) == 0 ) {
$doctype = strpos( $head, "\x42\x82" );
if( $doctype ) {
// Next byte is datasize, then data (sizes larger than 1 byte are very stupid muxers)
$data = substr($head, $doctype+3, 8);
if( strncmp( $data, "matroska", 8 ) == 0 ) {
wfDebug( __METHOD__ . ": recognized file as video/x-matroska\n" );
return "video/x-matroska";
} else if ( strncmp( $data, "webm", 4 ) == 0 ) {
wfDebug( __METHOD__ . ": recognized file as video/webm\n" );
return "video/webm";
}
}
wfDebug( __METHOD__ . ": unknown EBML file\n" );
return "unknown/unknown";
}
/*
* Look for PHP. Check for this before HTML/XML... Warning: this is a
* heuristic, and won't match a file with a lot of non-PHP before. It

View file

@ -35,11 +35,15 @@ audio/ogg [AUDIO]
audio/x-aiff [AUDIO]
audio/x-pn-realaudio [AUDIO]
audio/x-realaudio [AUDIO]
audio/webm [AUDIO]
audio/x-matroska [AUDIO]
video/mpeg application/mpeg [VIDEO]
video/ogg [VIDEO]
video/x-sgi-video [VIDEO]
video/x-flv [VIDEO]
video/webm [VIDEO]
video/x-matroska [VIDEO]
application/ogg application/x-ogg audio/ogg audio/x-ogg video/ogg video/x-ogg [MULTIMEDIA]

View file

@ -64,7 +64,9 @@ audio/basic au snd
audio/midi mid midi kar
audio/mpeg mpga mp2 mp3
audio/ogg oga ogg spx
audio/webm webm
audio/x-aiff aif aiff aifc
audio/x-matroska mka mkv
audio/x-mpegurl m3u
audio/x-ogg oga ogg spx
audio/x-pn-realaudio ram rm
@ -114,7 +116,9 @@ video/mpeg mpeg mpg mpe
video/ogg ogv ogm ogg
video/quicktime qt mov
video/vnd.mpegurl mxu
video/webm webm
video/x-flv flv
video/x-matroska mkv mka
video/x-msvideo avi
video/x-ogg ogv ogm ogg
video/x-sgi-movie movie