meotimdihia
meotimdihia

Reputation: 4299

PHP : How check movie format is MKV or WMV

I use finfo_file and mime_content_type, it return on MKV and WMV: application/octet-stream PHP can't determine 2 this video format ?

If must use FFMPEG determime ( i dont know it possible or not) . then what is command to check format .

Upvotes: 3

Views: 2852

Answers (3)

nico
nico

Reputation: 51680

One thing you could do is to read the first few bytes of the file to check if they correspond to known file signatures.

The MKV file signature, in particular, is (in hex):

1a 45 df a3

As for WMV it should be:

30 26 b2 75

See for reference:

Extensible Binary Meta Language

Advanced Systems Format

Upvotes: 1

Marc B
Marc B

Reputation: 360862

Recent versions of magic_mime database can identify mkv/wmv files without trouble. Most like your shared host has an ancient version of the database.

You can force the use of a different database file (with the mkv/wmv definitions included) by doing:

$handle = finfo_open('FILEINFO_MIME_TYPE', '/path/to/updated/database/file').

You should be able to extract the updated database file from an Linux distro's fileinfo-type package.

Upvotes: 0

Oliver A.
Oliver A.

Reputation: 2900

Using the file extension:

http://www.php.net/manual/en/function.mime-content-type.php#94279

On Apache you just have to add to entrys to the mime.types file (Apache/conf/mime.types). Just open the file with any edito and add two lines.

your/mimetype      mkv
another/type       mvw 

If you are on a shared host or do not want to mess with the server settings, you can copy the file to a location where your script can access it, and pass the path as second parameter of mime_content_type.

Analysing the file content:

If you have to validate if it REALLY is a mkv/mvm there is another sollution but it wont work on shared hosts:

http://www.php.net/manual/de/function.mime-content-type.php#91646

Upvotes: 0

Related Questions