1. Go to this page and download the library: Download mhor/php-mediainfo library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mhor / php-mediainfo example snippets
//...
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
}
$mediaInfo = new MediaInfo();
$mediaInfo->setConfig('command', 'C:\path\to\directory\MediaInfo.exe');
$mediaInfoContainer = $mediaInfo->getInfo('music.mp3');
$mediaInfo = new MediaInfo();
$mediaInfo->setConfig('urlencode', true);
$mediaInfoContainer = $mediaInfo->getInfo('https://demo.us-west-1.amazonaws.com/video.mp4?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ABC%2F123%2Fus-west-1%2Fs3%2Faws4_request&X-Amz-Date=20200721T114451Z&X-Amz-SignedHeaders=host&X-Amz-Expires=600&X-Amz-Signature=123');
$mediaInfo = new MediaInfo();
$mediaInfo->setConfig('');
$general = $mediaInfoContainer->getGeneral();
if ($general->has('cover_data')) {
$attributeCover = $general->get('cover_data');
$base64EncodedImage = $attributeCover->getBinaryCover();
}
class CustomDurationChecker extends \Mhor\MediaInfo\Checker\DurationChecker
{
public function create($durations): \Mhor\MediaInfo\Attribute\Duration
{
return new CustomDuration($durations[0]);
}
public function getMembersFields(): array
{
return [
'duration',
];
}
}
class CustomDuration extends \Mhor\MediaInfo\Attribute\Duration
{
public function getSeconds()
{
return $this->getMilliseconds() / 1000;
}
}
$mediaInfo = new MediaInfo();
$mediaInfo->setConfig('attribute_checkers', [new CustomDurationChecker()]);
$mediaInfoContainer = $mediaInfo->getInfo(
'./SampleVideo_1280x720_5mb.mkv'
);
foreach ($mediaInfoContainer->getAudios() as $audio) {
echo $audio->get('duration')->getSeconds();
}
bash
$ composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.