PHP wrapper around the mediainfo
command
You should install mediainfo:
$ sudo apt-get install mediainfo
$ brew install mediainfo
To use this library install it through Composer, run:
$ composer require mhor/php-mediainfo
<?php
//...
use Mhor\MediaInfo\MediaInfo;
//...
$mediaInfo = new MediaInfo();
$mediaInfoContainer = $mediaInfo->getInfo('music.mp3');
//...
$general = $mediaInfoContainer->getGeneral();
$videos = $mediaInfoContainer->getVideos();
foreach ($videos as $video) {
// ... do something
}
$audios = $mediaInfoContainer->getAudios();
foreach ($audios as $audio) {
// ... do something
}
$subtitles = $mediaInfoContainer->getSubtitles();
foreach ($subtitles as $subtitle) {
// ... do something
}
$images = $mediaInfoContainer->getImages();
foreach ($images as $image) {
// ... do something
}
$menus = $mediaInfoContainer->getMenus();
foreach ($menus as $menu) {
// ... do something
}
<?php
require './vendor/autoload.php';
use Mhor\MediaInfo\MediaInfo;
$mediaInfo = new MediaInfo();
$mediaInfoContainer = $mediaInfo->getInfo('./SampleVideo_1280x720_5mb.mkv');
echo "Videos channel: \n";
echo "=======================\n";
foreach ($mediaInfoContainer->getVideos() as $video) {
echo 'format: '.(string)$video->get('format')."\n";
echo 'height: '.$video->get('height')->getAbsoluteValue()."\n";
echo "\n---------------------\n";
}
echo "Audios channel: \n";
echo "=======================\n";
foreach ($mediaInfoContainer->getAudios() as $audio) {
echo 'unique_id: '.$audio->get('unique_id') . "\n";
echo 'format: '.$audio->get('format');
echo "\n---------------------\n";
}
By default unknown type throw an error this, to avoid this behavior, you can do:
$mediaInfo = new MediaInfo();
$mediaInfoContainer = $mediaInfo->getInfo('music.mp3', false);
$others = $mediaInfoContainer->getOthers();
foreach ($others as $other) {
// ... do something
}
$informationArray = $general->get();
Field Name are in lower case separated by "_"
$oneInformation = $general->get('count_of_audio_streams');
For field:
- cover_data
Cover type will be applied
For fields:
- duration
- delay_relative_to_video
- video0_delay
- delay
Duration type will be applied
For fields:
- overall_bit_rate_mode
- overall_bit_rate
- bit_rate_mode
- compression_mode
- codec
- format
- kind_of_stream
- writing_library
- id
- format_settings_sbr
- channel_positions
- default
- forced
- delay_origin
- scan_type
- interlacement
- scan_type
- frame_rate_mode
- format_settings_cabac
- unique_id
Mode type will be applied
For fields:
- channel_s
- bit_rate
- sampling_rate
- bit_depth
- width
- nominal_bit_rate
- frame_rate
- format_settings_reframes
- height
- resolution
- maximum_bit_rate
Rate type will be applied
For fields:
- display_aspect_ratio
- original_display_aspect_ratio
Ratio type will be applied
For fields:
- file_size
- stream_size
Size type will be applied
- All date fields will be transformed into
Datetime
php object
$mediaInfo = new MediaInfo();
$mediaInfo->setConfig('command', '/usr/local/bin/mediainfo');
$mediaInfoContainer = $mediaInfo->getInfo('music.mp3');
$mediaInfo = new MediaInfo();
$mediaInfoContainer = $mediaInfo->getInfo('http://example.org/music/test.mp3');
$mediaInfo = new MediaInfo();
$mediaInfoContainer = $mediaInfo->getInfo('music.mp3');
$json = json_encode($mediaInfoContainer);
$array = $mediaInfoContainer->__toArray();
$xml = $mediaInfoContainer->__toXML();
Download MediaInfo CLI from here. Extract zip-archive and place MediaInfo.exe somewhere. Use it:
$mediaInfo = new MediaInfo();
$mediaInfo->setConfig('command', 'C:\path\to\directory\MediaInfo.exe');
$mediaInfoContainer = $mediaInfo->getInfo('music.mp3');
Look at this bundle: MhorMediaInfoBunde
Look at this to use composer with Codeigniter
See LICENSE
for more information