Code Monkey home page Code Monkey logo

php-mediainfo's Introduction

Php-MediaInfo Coverage Status Packagist Packagist Code Checks

Introduction

PHP wrapper around the mediainfo command

Table of contents:

Installation

1 - Install mediainfo

You should install mediainfo:

On linux:

$ sudo apt-get install mediainfo

On Mac:

$ brew install mediainfo

2 - Integration in your php project

To use this library install it through Composer, run:

$ composer require mhor/php-mediainfo

How to use

Retrieve media information container

<?php
//...
use Mhor\MediaInfo\MediaInfo;
//...
$mediaInfo = new MediaInfo();
$mediaInfoContainer = $mediaInfo->getInfo('music.mp3');
//...

Get general information from media information container

$general = $mediaInfoContainer->getGeneral();

Get videos information from media information container

$videos = $mediaInfoContainer->getVideos();

foreach ($videos as $video) {
    // ... do something
}

Get audios information from media information container

$audios = $mediaInfoContainer->getAudios();

foreach ($audios as $audio) {
    // ... do something
}

Get subtitles information from media information container

$subtitles = $mediaInfoContainer->getSubtitles();

foreach ($subtitles as $subtitle) {
    // ... do something
}

Get images information from media information container

$images = $mediaInfoContainer->getImages();

foreach ($images as $image) {
    // ... do something
}

Get menus information from media information container

$menus = $mediaInfoContainer->getMenus();

foreach ($menus as $menu) {
    // ... do something
}

Example

<?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) {
    if ($video->has('format')) {
        echo 'format: '.(string)$video->get('format')."\n";
    }

    if ($video->has('height')) {
        echo 'height: '.$video->get('height')->getAbsoluteValue()."\n";
    }

    echo "\n---------------------\n";
}

echo "Audios channel: \n";
echo "=======================\n";
foreach ($mediaInfoContainer->getAudios() as $audio) {
    $availableInfo = $audio->list();
    foreach ($availableInfo as $key) {
        echo $audio->get($key);
    }
    echo "\n---------------------\n";
}

Ignore unknown types

By default, unknown type throw an error this, to avoid this behavior, you can do:

$mediaInfo = new MediaInfo();
$mediaInfo->setConfig('ignore_unknown_track_types', true);

$mediaInfoContainer = $mediaInfo->getInfo('music.mp3');

$others = $mediaInfoContainer->getOthers();
foreach ($others as $other) {
    // ... do something
}

Access to information

Get all information into an array

$informationArray = $general->get();

Get one information by field name

Field Name are in lower case separated by "_"

$oneInformation = $general->get('count_of_audio_streams');

Check if information exists

Field Name are in lower case separated by "_"

if ($general->has('count_of_audio_streams')) {
    echo $general->get('count_of_audio_streams');
}

List available information

$availableInfo = $general->list();
foreach ($availableInfo as $key) {
    echo $general->get($key);
}

Specials types

Cover

For field:

  • cover_data

Cover type will be applied

Duration

For fields:

  • duration
  • delay_relative_to_video
  • video0_delay
  • delay

Duration type will be applied

Mode

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

Rate

For fields:

  • channel_s
  • bit_rate
  • sampling_rate
  • bit_depth
  • width
  • nominal_bit_rate
  • format_settings_reframes
  • height
  • resolution
  • maximum_bit_rate

Rate type will be applied

FloatRate

For fields:

  • frame_rate

FloatRate type will be applied

Ratio

For fields:

  • display_aspect_ratio
  • original_display_aspect_ratio

Ratio type will be applied

Size

For fields:

  • file_size
  • stream_size

Size type will be applied

Others

  • All date fields will be transformed into Datetime php object

Extra

Use custom mediainfo path

$mediaInfo = new MediaInfo();
$mediaInfo->setConfig('command', '/usr/local/bin/mediainfo');
$mediaInfoContainer = $mediaInfo->getInfo('music.mp3');

Support old mediainfo version (<17.10)

$mediaInfo = new MediaInfo();
$mediaInfo->setConfig('use_oldxml_mediainfo_output_format', false);
$mediaInfoContainer = $mediaInfo->getInfo('music.mp3');

Use url as filepath

$mediaInfo = new MediaInfo();
$mediaInfoContainer = $mediaInfo->getInfo('http://example.org/music/test.mp3');

MediaInfoContainer to JSON, Array or XML

$mediaInfo = new MediaInfo();
$mediaInfoContainer = $mediaInfo->getInfo('music.mp3');

$json = json_encode($mediaInfoContainer);
$array = $mediaInfoContainer->__toArray();
$xml = $mediaInfoContainer->__toXML();

Usage for WindowsOS

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');

Urlencode Config

By default, MediaInfo tries to detect if a URL is already percent-encode and encodes the URL when it's not. Setting the 'urlencode' config setting to true forces MediaInfo to encode the URL despite the presence of percentage signs in the URL. This is for example required when using pre-signed URLs for AWS S3 objects.

$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');

This setting requires MediaInfo 20.03 minimum

Cover data

Recent versions of MediaInfo don't include cover data by default, without passing an additional flag. To include any available cover data, set the 'include_cover_data' config setting to true. See the cover type for details on retrieving the base64 encoded image from cover_data.

Originally this cover data was always included in the MediaInfo output, so this option is unnecessary for older versions. But around version 18 cover data was removed from the output by default, unless you also pass the --Cover_Data=base64 flag.

$mediaInfo = new MediaInfo();
$mediaInfo->setConfig('include_cover_data', true);
$mediaInfoContainer = $mediaInfo->getInfo('music.mp3');

$general = $mediaInfoContainer->getGeneral();
if ($general->has('cover_data')) {
    $attributeCover = $general->get('cover_data');
    $base64EncodedImage = $attributeCover->getBinaryCover();
}

Note: Older versions of MediaInfo will print the following error if passed this flag:

$ mediainfo ./music.mp3 -f --OUTPUT=OLDXML --Cover_Data=base64
Option not known

Override attribute checkers/types

This configuration allows you to customize the return values of attributes in php-mediainfo by creating custom checker and attribute classes. You can extend existing classes, override methods, and add additional functionality to provide more comprehensive or specialized information in the attribute objects returned by php-mediainfo.

  1. Create a new class that implements the AttributeCheckerInterface
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',
        ];
    }
}
  1. Create a new class that implements the AttributeInterface
class CustomDuration extends \Mhor\MediaInfo\Attribute\Duration
{
    public function getSeconds()
    {
        return $this->getMilliseconds() / 1000;
    }
}
  1. Set the new list of attribute checkers into the config
$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();
}

Symfony integration

Look at this bundle: MhorMediaInfoBunde

Codeigniter integration

Look at this to use composer with Codeigniter

License

See LICENSE for more information

php-mediainfo's People

Contributors

amardeokar23 avatar cklm avatar danog avatar dariusiii avatar fvilpoix avatar grahamcampbell avatar javiertrejo avatar mhor avatar mitchellklijs avatar nek- avatar nicholi avatar padre avatar philo23 avatar rhertogh avatar timgels avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-mediainfo's Issues

Type doesn't exist: Menu

can you please add a new Type for "Menu" (chappters in mkv)


object(Mhor\MediaInfo\Exception\UnknownTrackTypeException)[83]
  private 'trackType' => string 'Menu' (length=4)
  protected 'message' => string 'Type doesn't exist: Menu' (length=24)
  private 'string' (Exception) => string '' (length=0)
  protected 'code' => int 0
  protected 'file' => string '/var/www/medialibrary/vendor/mhor/php-mediainfo/src/Factory/TypeFactory.php' (length=75)
  protected 'line' => int 46
  private 'trace' (Exception) => 
    array (size=9)
      0 => 
        array (size=6)
          'file' => string '/var/www/medialibrary/vendor/mhor/php-mediainfo/src/Builder/MediaInfoContainerBuilder.php' (length=89)
          'line' => int 52
          'function' => string 'create' (length=6)
          'class' => string 'Mhor\MediaInfo\Factory\TypeFactory' (length=34)
          'type' => string '->' (length=2)
          'args' => 
            array (size=1)
              0 => string 'Menu' (length=4)
      1 => 
        array (size=6)
          'file' => string '/var/www/medialibrary/vendor/mhor/php-mediainfo/src/Parser/MediaInfoOutputParser.php' (length=84)
          'line' => int 43
          'function' => string 'addTrackType' (length=12)
          'class' => string 'Mhor\MediaInfo\Builder\MediaInfoContainerBuilder' (length=48)
          'type' => string '->' (length=2)
          'args' => 
            array (size=2)
              0 => string 'Menu' (length=4)
              1 => 
                array (size=27)
                  '@attributes' => 
                    array (size=1)
                      'type' => string 'Menu' (length=4)
                  'Count' => string '97' (length=2)
                  'Count_of_stream_of_this_kind' => string '1' (length=1)
                  'Kind_of_stream' => 
                    array (size=2)
                      0 => string 'Menu' (length=4)
                      1 => string 'Menu' (length=4)
                  'Stream_identifier' => string '0' (length=1)
                  'Chapters_Pos_Begin' => string '77' (length=2)
                  'Chapters_Pos_End' => string '97' (length=2)
                  '_00_00_00000' => string ':00:00:00.000' (length=13)
                  '_00_04_13587' => string ':00:04:13.587' (length=13)
                  '_00_08_38309' => string ':00:08:38.309' (length=13)
                  '_00_16_11929' => string ':00:16:11.929' (length=13)
                  '_00_21_43135' => string ':00:21:43.135' (length=13)
                  '_00_33_22459' => string ':00:33:22.459' (length=13)
                  '_00_41_48798' => string ':00:41:48.798' (length=13)
                  '_00_47_58000' => string ':00:47:58.000' (length=13)
                  '_00_53_40592' => string ':00:53:40.592' (length=13)
                  '_01_04_46674' => string ':01:04:46.674' (length=13)
                  '_01_12_59709' => string ':01:12:59.709' (length=13)
                  '_01_20_47885' => string ':01:20:47.885' (length=13)
                  '_01_26_18965' => string ':01:26:18.965' (length=13)
                  '_01_31_53383' => string ':01:31:53.383' (length=13)
                  '_01_42_23637' => string ':01:42:23.637' (length=13)
                  '_01_50_52271' => string ':01:50:52.271' (length=13)
                  '_01_52_13936' => string ':01:52:13.936' (length=13)
                  '_01_58_10875' => string ':01:58:10.875' (length=13)
                  '_01_59_51601' => string ':01:59:51.601' (length=13)
                  '_02_01_56434' => string ':02:01:56.434' (length=13)

Error in MediaInfoOutputParser.php

Whenever I try to run this method

$mediaInfo = new Mhor\MediaInfo\MediaInfo();
$mediaInfo->getInfo($path);

it throws this error

Undefined array key "track"
Illuminate\Foundation\Bootstrap\HandleExceptions::handleError
vendor/mhor/php-mediainfo/src/Parser/MediaInfoOutputParser.php:46

foreach ($this->parsedOutput['File']['track'] as $trackType)

I've already installed mediainfo via brew on my machine currently on version v20.09
I'm also currently on php version 8.0.3 & Laravel 8.16

Remote file Support

Would it be possible to add remote file support to the libary?
Mediainfo supports native AWS S3 files. But from the libary I get a error "File doesn't exist ".

Commeting out the file exist check in de MediaInfoCommandBuilder gets the job done for now

if Video, Audio Track->format is string, value is invalid.

my video file's video, audio track's format is string.

/src/Checker/ModeChecker.php

    public function create($rateMode)
    {
        if (is_string($rateMode)) $rateMode = array($rateMode); // <- add this line
        if (!isset($rateMode[1])) {
            $rateMode[1] = $rateMode[0];
        }
        $mode = new Mode($rateMode[0], $rateMode[1]);

        return $mode;
    }

XML format of mediainfo command has changed

When used with the latest version of mediainfo (17.10), the parser fails with the error "Undefined index: File" because the new XML format has replaced the 'File' element with a 'media' element.

Possible fixes include detecting the new version of mediainfo and changing the command line to use "--Output=OLDXML", or to adapt the parser module to use the new XML format.

fix php8 require deps

Hi,
php-mediainfo can't be upgraded via composer and php8 with message:

    - mhor/php-mediainfo dev-master requires php ^7.2 -> your php version (8.0.0) does not satisfy that requirement.
    - mhor/php-mediainfo 6.0.x-dev is an alias of mhor/php-mediainfo dev-master and thus requires it to be installed too.
    - Root composer.json requires mhor/php-mediainfo ^6.0@dev -> satisfiable by mhor/php-mediainfo[6.0.x-dev (alias of dev-master)].

don't know how to check php8 compatibility but maybe this simple change can be made?

diff --git "a/composer.json" "b/composer.json"
index bf0f5f7..6fcefc2 100644
--- "a/composer.json"
+++ "b/composer.json"
@@ -16,7 +16,7 @@
         }
     ],
     "require": {
-        "php": "^7.2",
+        "php": ">=7.2",
         "symfony/process": "~3.4|~4.0|~5.0",
         "symfony/filesystem": "~3.4|~4.0|~5.0"
     },

Support symfony/filesystem v7.0

I'm getting this error while installing:

composer require mhor/php-mediainfo ^5.5
The "5.5" constraint for "mhor/php-mediainfo" appears too strict and will likely not match what you want. See https://getcomposer.org/constraints
./composer.json has been updated
Running composer update mhor/php-mediainfo
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Root composer.json requires mhor/php-mediainfo 5.5 -> satisfiable by mhor/php-mediainfo[5.5.0].
- mhor/php-mediainfo 5.5.0 requires symfony/filesystem ~3.4|~4.0|~5.0|~6.0 -> found symfony/filesystem[v3.4.0-BETA1, ..., 3.4.x-dev, v4.0.0-BETA1, ..., 4.4.x-dev, v5.0.0-BETA1, ..., 5.4.x-dev, v6.0.0-BETA1, ..., 6.4.x-dev] but the package is fixed to v7.0.0 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

Process does not work on Windows / wrong ENV-definition

The command syntax on windows is slightly different as on linux/mac os.

linux/mac os: mediainfo "$MEDIAINFO_VAR_0" "$MEDIAINFO_VAR_1" "$MEDIAINFO_VAR_2"

windows: MediaInfo.exe "%MEDIAINFO_VAR_0%" "%MEDIAINFO_VAR_1%" "%MEDIAINFO_VAR_2%"

Parsing MediaInfo fails on Chinese chars in XML

In the following XML between the tags there are some Chinese chars. SimpleXML doesn't seem to like those and crashes the process.

<Copyright>�꤀ 刀漀渀 䠀愀爀爀椀猀</Copyright>

   ErrorException  : simplexml_load_string(): Entity: line 54: parser error : Char 0xFFFE out of allowed range

  at /var/www/removed/vendor/mhor/php-mediainfo/src/Parser/AbstractXmlOutputParser.php:18
    14|         if (mb_detect_encoding($xmlString, 'UTF-8', true) === false) {
    15|             $xmlString = utf8_encode($xmlString);
    16|         }
    17|
  > 18|         $xml = simplexml_load_string($xmlString);
    19|         $json = json_encode($xml);
    20|
    21|         return json_decode($json, true);
    22|     }

  Exception trace:

  1   simplexml_load_string("<?xml version="1.0" encoding="UTF-8"?>
<Mediainfo version="19.09">
<File>
<track type="General">
<Count>331</Count>
<Count_of_stream_of_this_kind>1</Count_of_stream_of_this_kind>
<Kind_of_stream>General</Kind_of_stream>
<Kind_of_stream>General</Kind_of_stream>
<Stream_identifier>0</Stream_identifier>
<Count_of_video_streams>1</Count_of_video_streams>
<Count_of_audio_streams>1</Count_of_audio_streams>
<Video_Format_List>VC-1</Video_Format_List>
<Video_Format_WithHint_List>VC-1 (WMV3)</Video_Format_WithHint_List>
<Codecs_Video>VC-1</Codecs_Video>
<Audio_Format_List>WMA</Audio_Format_List>
<Audio_Format_WithHint_List>WMA</Audio_Format_WithHint_List>
<Audio_codecs>WMA</Audio_codecs>
<Complete_name>/mnt/ramdisk/5/54c9f93b-8550-4100-8eeb-328841dc00d6/782247_ohrly-rh131aaso.wmv</Complete_name>
<Folder_name>/mnt/ramdisk/5/54c9f93b-8550-4100-8eeb-328841dc00d6</Folder_name>
<File_name_extension>782247_ohrly-rh131aaso.wmv</File_name_extension>
<File_name>782247_ohrly-rh131aaso</File_name>
<File_extension>wmv</File_extension>
<Format>Windows Media</Format>
<Format>Windows Media</Format>
<Format_Extensions_usually_used>asf dvr-ms wma wmv</Format_Extensions_usually_used>
<Commercial_name>Windows Media</Commercial_name>
<Internet_media_type>video/x-ms-wmv</Internet_media_type>
<File_size>760169</File_size>
<File_size>742 KiB</File_size>
<File_size>742 KiB</File_size>
<File_size>742 KiB</File_size>
<File_size>742 KiB</File_size>
<File_size>742.4 KiB</File_size>
<Duration>489056</Duration>
<Duration>8 min 9 s</Duration>
<Duration>8 min 9 s 56 ms</Duration>
<Duration>8 min 9 s</Duration>
<Duration>00:08:09.056</Duration>
<Duration>00:08:09;03</Duration>
<Duration>00:08:09.056 (00:08:09;03)</Duration>
<Overall_bit_rate>12435</Overall_bit_rate>
<Overall_bit_rate>12.4 kb/s</Overall_bit_rate>
<Maximum_Overall_bit_rate>5136894</Maximum_Overall_bit_rate>
<Maximum_Overall_bit_rate>5 137 kb/s</Maximum_Overall_bit_rate>
<Frame_rate>29.970</Frame_rate>
<Frame_rate>29.970 FPS</Frame_rate>
<Frame_count>14657</Frame_count>
<HeaderSize>1046</HeaderSize>
<DataSize>759123</DataSize>
<Performer>Ron Harris</Performer>
<Encoded_date>UTC 2012-05-14 00:53:44.000</Encoded_date>
<File_last_modification_date>UTC 2019-12-17 17:20:55</File_last_modification_date>
<File_last_modification_date__local_>2019-12-17 18:20:55</File_last_modification_date__local_>
<Copyright>�꤀ 刀漀渀 䠀愀爀爀椀猀</Copyright>
<Comment>HD Videos</Comment>
</track>
<track type="Video">
<Count>377</Count>
<Count_of_stream_of_this_kind>1</Count_of_stream_of_this_kind>
<Kind_of_stream>Video</Kind_of_stream>
<Kind_of_stream>Video</Kind_of_stream>
<Stream_identifier>0</Stream_identifier>
<StreamOrder>0</StreamOrder>
<ID>1</ID>
<ID>1</ID>
<Format>VC-1</Format>
<Format>VC-1</Format>
<Commercial_name>VC-1</Commercial_name>
<Format_profile>Main</Format_profile>
<Internet_media_type>video/vc1</Internet_media_type>
<Codec_ID>WMV3</Codec_ID>
<Codec_ID_Info>Windows Media Video 9</Codec_ID_Info>
<Codec_ID_Hint>WMV3</Codec_ID_Hint>
<Codec_ID_Url>http://www.microsoft.com/windows/windowsmedia/format/codecdownload.aspx</Codec_ID_Url>
<Description_of_the_codec>Windows Media Video 9 - 2-pass VBR</Description_of_the_codec>
<Duration>489056</Duration>
<Duration>8 min 9 s</Duration>
<Duration>8 min 9 s 56 ms</Duration>
<Duration>8 min 9 s</Duration>
<Duration>00:08:09.056</Duration>
<Duration>00:08:09;03</Duration>
<Duration>00:08:09.056 (00:08:09;03)</Duration>
<Bit_rate>5000000</Bit_rate>
<Bit_rate>5 000 kb/s</Bit_rate>
<Width>1920</Width>
<Width>1 920 pixels</Width>
<Height>1080</Height>
<Height>1 080 pixels</Height>
<Pixel_aspect_ratio>1.000</Pixel_aspect_ratio>
<Display_aspect_ratio>1.778</Display_aspect_ratio>
<Display_aspect_ratio>16:9</Display_aspect_ratio>
<Frame_rate>29.970</Frame_rate>
<Frame_rate>29.970 (29970/1000) FPS</Frame_rate>
<FrameRate_Num>29970</FrameRate_Num>
<FrameRate_Den>1000</FrameRate_Den>
<Frame_count>14657</Frame_count>
<Color_space>YUV</Color_space>
<Chroma_subsampling>4:2:0</Chroma_subsampling>
<Chroma_subsampling>4:2:0</Chroma_subsampling>
<Bit_depth>8</Bit_depth>
<Bit_depth>8 bits</Bit_depth>
<Scan_type>Progressive</Scan_type>
<Scan_type>Progressive</Scan_type>
<Compression_mode>Lossy</Compression_mode>
<Compression_mode>Lossy</Compression_mode>
<Bits__Pixel_Frame_>0.080</Bits__Pixel_Frame_>
<Stream_size>305660000</Stream_size>
<Stream_size>292 MiB</Stream_size>
<Stream_size>292 MiB</Stream_size>
<Stream_size>292 MiB</Stream_size>
<Stream_size>292 MiB</Stream_size>
<Stream_size>291.5 MiB</Stream_size>
</track>
<track type="Audio">
<Count>280</Count>
<Count_of_stream_of_this_kind>1</Count_of_stream_of_this_kind>
<Kind_of_stream>Audio</Kind_of_stream>
<Kind_of_stream>Audio</Kind_of_stream>
<Stream_identifier>0</Stream_identifier>
<StreamOrder>1</StreamOrder>
<ID>2</ID>
<ID>2</ID>
<Format>WMA</Format>
<Format>WMA</Format>
<Commercial_name>WMA</Commercial_name>
<Format_version>Version 2</Format_version>
<Codec_ID>161</Codec_ID>
<Codec_ID_Info>Windows Media Audio</Codec_ID_Info>
<Codec_ID_Url>http://www.microsoft.com/windows/windowsmedia/format/codecdownload.aspx</Codec_ID_Url>
<Description_of_the_codec>Windows Media Audio 9 - 128 kbps, 44 kHz, stereo CBR</Description_of_the_codec>
<Duration>489056</Duration>
<Duration>8 min 9 s</Duration>
<Duration>8 min 9 s 56 ms</Duration>
<Duration>8 min 9 s</Duration>
<Duration>00:08:09.056</Duration>
<Duration>00:08:09.056</Duration>
<Bit_rate>128000</Bit_rate>
<Bit_rate>128 kb/s</Bit_rate>
<Channel_s_>2</Channel_s_>
<Channel_s_>2 channels</Channel_s_>
<Sampling_rate>44100</Sampling_rate>
<Sampling_rate>44.1 kHz</Sampling_rate>
<Samples_count>21567370</Samples_count>
<Bit_depth>16</Bit_depth>
<Bit_depth>16 bits</Bit_depth>
<Stream_size>7824896</Stream_size>
<Stream_size>7.46 MiB</Stream_size>
<Stream_size>7 MiB</Stream_size>
<Stream_size>7.5 MiB</Stream_size>
<Stream_size>7.46 MiB</Stream_size>
<Stream_size>7.462 MiB</Stream_size>
</track>
</File>
</Mediainfo>

")
      /var/www/removed/vendor/mhor/php-mediainfo/src/Parser/AbstractXmlOutputParser.php:18

  2   Mhor\MediaInfo\Parser\AbstractXmlOutputParser::transformXmlToArray("<?xml version="1.0" encoding="UTF-8"?>
<Mediainfo version="19.09">
<File>
<track type="General">
<Count>331</Count>
<Count_of_stream_of_this_kind>1</Count_of_stream_of_this_kind>
<Kind_of_stream>General</Kind_of_stream>
<Kind_of_stream>General</Kind_of_stream>
<Stream_identifier>0</Stream_identifier>
<Count_of_video_streams>1</Count_of_video_streams>
<Count_of_audio_streams>1</Count_of_audio_streams>
<Video_Format_List>VC-1</Video_Format_List>
<Video_Format_WithHint_List>VC-1 (WMV3)</Video_Format_WithHint_List>
<Codecs_Video>VC-1</Codecs_Video>
<Audio_Format_List>WMA</Audio_Format_List>
<Audio_Format_WithHint_List>WMA</Audio_Format_WithHint_List>
<Audio_codecs>WMA</Audio_codecs>
<Complete_name>/mnt/ramdisk/5/54c9f93b-8550-4100-8eeb-328841dc00d6/782247_ohrly-rh131aaso.wmv</Complete_name>
<Folder_name>/mnt/ramdisk/5/54c9f93b-8550-4100-8eeb-328841dc00d6</Folder_name>
<File_name_extension>782247_ohrly-rh131aaso.wmv</File_name_extension>
<File_name>782247_ohrly-rh131aaso</File_name>
<File_extension>wmv</File_extension>
<Format>Windows Media</Format>
<Format>Windows Media</Format>
<Format_Extensions_usually_used>asf dvr-ms wma wmv</Format_Extensions_usually_used>
<Commercial_name>Windows Media</Commercial_name>
<Internet_media_type>video/x-ms-wmv</Internet_media_type>
<File_size>760169</File_size>
<File_size>742 KiB</File_size>
<File_size>742 KiB</File_size>
<File_size>742 KiB</File_size>
<File_size>742 KiB</File_size>
<File_size>742.4 KiB</File_size>
<Duration>489056</Duration>
<Duration>8 min 9 s</Duration>
<Duration>8 min 9 s 56 ms</Duration>
<Duration>8 min 9 s</Duration>
<Duration>00:08:09.056</Duration>
<Duration>00:08:09;03</Duration>
<Duration>00:08:09.056 (00:08:09;03)</Duration>
<Overall_bit_rate>12435</Overall_bit_rate>
<Overall_bit_rate>12.4 kb/s</Overall_bit_rate>
<Maximum_Overall_bit_rate>5136894</Maximum_Overall_bit_rate>
<Maximum_Overall_bit_rate>5 137 kb/s</Maximum_Overall_bit_rate>
<Frame_rate>29.970</Frame_rate>
<Frame_rate>29.970 FPS</Frame_rate>
<Frame_count>14657</Frame_count>
<HeaderSize>1046</HeaderSize>
<DataSize>759123</DataSize>
<Performer>Ron Harris</Performer>
<Encoded_date>UTC 2012-05-14 00:53:44.000</Encoded_date>
<File_last_modification_date>UTC 2019-12-17 17:20:55</File_last_modification_date>
<File_last_modification_date__local_>2019-12-17 18:20:55</File_last_modification_date__local_>
<Copyright>�꤀ 刀漀渀 䠀愀爀爀椀猀</Copyright>
<Comment>HD Videos</Comment>
</track>
<track type="Video">
<Count>377</Count>
<Count_of_stream_of_this_kind>1</Count_of_stream_of_this_kind>
<Kind_of_stream>Video</Kind_of_stream>
<Kind_of_stream>Video</Kind_of_stream>
<Stream_identifier>0</Stream_identifier>
<StreamOrder>0</StreamOrder>
<ID>1</ID>
<ID>1</ID>
<Format>VC-1</Format>
<Format>VC-1</Format>
<Commercial_name>VC-1</Commercial_name>
<Format_profile>Main</Format_profile>
<Internet_media_type>video/vc1</Internet_media_type>
<Codec_ID>WMV3</Codec_ID>
<Codec_ID_Info>Windows Media Video 9</Codec_ID_Info>
<Codec_ID_Hint>WMV3</Codec_ID_Hint>
<Codec_ID_Url>http://www.microsoft.com/windows/windowsmedia/format/codecdownload.aspx</Codec_ID_Url>
<Description_of_the_codec>Windows Media Video 9 - 2-pass VBR</Description_of_the_codec>
<Duration>489056</Duration>
<Duration>8 min 9 s</Duration>
<Duration>8 min 9 s 56 ms</Duration>
<Duration>8 min 9 s</Duration>
<Duration>00:08:09.056</Duration>
<Duration>00:08:09;03</Duration>
<Duration>00:08:09.056 (00:08:09;03)</Duration>
<Bit_rate>5000000</Bit_rate>
<Bit_rate>5 000 kb/s</Bit_rate>
<Width>1920</Width>
<Width>1 920 pixels</Width>
<Height>1080</Height>
<Height>1 080 pixels</Height>
<Pixel_aspect_ratio>1.000</Pixel_aspect_ratio>
<Display_aspect_ratio>1.778</Display_aspect_ratio>
<Display_aspect_ratio>16:9</Display_aspect_ratio>
<Frame_rate>29.970</Frame_rate>
<Frame_rate>29.970 (29970/1000) FPS</Frame_rate>
<FrameRate_Num>29970</FrameRate_Num>
<FrameRate_Den>1000</FrameRate_Den>
<Frame_count>14657</Frame_count>
<Color_space>YUV</Color_space>
<Chroma_subsampling>4:2:0</Chroma_subsampling>
<Chroma_subsampling>4:2:0</Chroma_subsampling>
<Bit_depth>8</Bit_depth>
<Bit_depth>8 bits</Bit_depth>
<Scan_type>Progressive</Scan_type>
<Scan_type>Progressive</Scan_type>
<Compression_mode>Lossy</Compression_mode>
<Compression_mode>Lossy</Compression_mode>
<Bits__Pixel_Frame_>0.080</Bits__Pixel_Frame_>
<Stream_size>305660000</Stream_size>
<Stream_size>292 MiB</Stream_size>
<Stream_size>292 MiB</Stream_size>
<Stream_size>292 MiB</Stream_size>
<Stream_size>292 MiB</Stream_size>
<Stream_size>291.5 MiB</Stream_size>
</track>
<track type="Audio">
<Count>280</Count>
<Count_of_stream_of_this_kind>1</Count_of_stream_of_this_kind>
<Kind_of_stream>Audio</Kind_of_stream>
<Kind_of_stream>Audio</Kind_of_stream>
<Stream_identifier>0</Stream_identifier>
<StreamOrder>1</StreamOrder>
<ID>2</ID>
<ID>2</ID>
<Format>WMA</Format>
<Format>WMA</Format>
<Commercial_name>WMA</Commercial_name>
<Format_version>Version 2</Format_version>
<Codec_ID>161</Codec_ID>
<Codec_ID_Info>Windows Media Audio</Codec_ID_Info>
<Codec_ID_Url>http://www.microsoft.com/windows/windowsmedia/format/codecdownload.aspx</Codec_ID_Url>
<Description_of_the_codec>Windows Media Audio 9 - 128 kbps, 44 kHz, stereo CBR</Description_of_the_codec>
<Duration>489056</Duration>
<Duration>8 min 9 s</Duration>
<Duration>8 min 9 s 56 ms</Duration>
<Duration>8 min 9 s</Duration>
<Duration>00:08:09.056</Duration>
<Duration>00:08:09.056</Duration>
<Bit_rate>128000</Bit_rate>
<Bit_rate>128 kb/s</Bit_rate>
<Channel_s_>2</Channel_s_>
<Channel_s_>2 channels</Channel_s_>
<Sampling_rate>44100</Sampling_rate>
<Sampling_rate>44.1 kHz</Sampling_rate>
<Samples_count>21567370</Samples_count>
<Bit_depth>16</Bit_depth>
<Bit_depth>16 bits</Bit_depth>
<Stream_size>7824896</Stream_size>
<Stream_size>7.46 MiB</Stream_size>
<Stream_size>7 MiB</Stream_size>
<Stream_size>7.5 MiB</Stream_size>
<Stream_size>7.46 MiB</Stream_size>
<Stream_size>7.462 MiB</Stream_size>
</track>
</File>
</Mediainfo>

")
      /var/www/removed/vendor/mhor/php-mediainfo/src/Parser/MediaInfoOutputParser.php:22

  Please use the argument -v to see more details.

Windows

I installed this on Laravel 8,

            $mediaInfo = new MediaInfo();
            $mediaInfo->setConfig('command', 'C:\Program Files\MediaInfo\MediaInfo.exe');
            $mediaInfoContainer = $mediaInfo->getInfo(url);

This opens the Mediainfo, reads the file but it gets stuck with Mediainfo open and the page keeps loading until I close the mediainfo instance then trows "Return value of Mhor\MediaInfo\Parser\AbstractXmlOutputParser::transformXmlToArray() must be of the type array, bool returned"

How can I use it?

Runtime exception for version 4.1.1 due to latest fix - Wrap every command argument in quotes

Fatal error: Uncaught RuntimeException in /vendor/mhor/php-mediainfo/src/Runner/MediaInfoCommandRunner.php:98
Stack trace:
#0 /vendor/mhor/php-mediainfo/src/MediaInfo.php(37): Mhor\MediaInfo\Runner\MediaInfoCommandRunner->run()
#1 /test.php(21): Mhor\MediaInfo\MediaInfo->getInfo('/tmp/300x250.jp...')
#2 {main}
thrown in /vendor/mhor/php-mediainfo/src/Runner/MediaInfoCommandRunner.php on line 98

Symfony 6 components

Is support for Symfony 6 components planned? Both symfony/process and symfony/filesystem have a 6.0.0 release now.

Thanks for you work!

Encoding issues related to simplexml_load_string

simplexml_load_string in AbstractXmlOutputParser:transformXmlToArray method doesn't work for some files based on the encoding/charset.

Sample error (it says warning but it basically is an error since it makes the code not work at all):

Warning: simplexml_load_string(): Entity: line 54: parser error : Input is not proper UTF-8, indicate encoding !
Bytes: 0xFC 0x73 0x6E 0xFC in /Users/taylankasap/Sites/T/vendor/mhor/php-mediainfo/src/Parser/AbstractXmlOutputParser.php on line 14

Replacing line 14 with one of these makes it work but I'm not sure if this won't break anything else and work for all encodings. Writing tests for different encodings might be a good idea

// This
$xml = simplexml_load_string(str_replace('encoding="UTF-8"', 'encoding="ISO-8859-1"', $xmlString));
// or this
$xml = simplexml_load_string(utf8_encode($xmlString));

Example code & mp3 file that's not working:

$mediaInfo = new \Mhor\MediaInfo\MediaInfo();
$mediaInfoContainer = $mediaInfo->getInfo("track-7f01c33918c6070efca7851b14bb31a3.mp3");

track-7f01c33918c6070efca7851b14bb31a3.mp3.zip
Bytes 0xFC 0x73 0x6E 0xFC in the warning corresponds to the bold part of the artist name: "Erdal Hüsnü Kizilçay"

Exception when using getInfo function

I am getting the following exception thrown when getInfo function is called:

Argument 1 passed to Mhor\MediaInfo\Attribute\Mode::__construct() must be of the type string, array given, called in vendor/mhor/php-mediainfo/src/Checker/ModeChecker.php on line 22

sh: 1: mediainfo: not found

Hello Sir/Medam,

I am getting below error on .3gp file.
sh: 1: mediainfo: not found

Please help me for the same.
Thanks

[Question]How to use php-mediainfo

I have a question about 'How to use php-mediainfo'.

There are no any require php in code.
How can I use the class in code?
There are too much class need to be required.

Error when trying to parse result of __toXML()

After I got MediaInfoContainer I am trying to store result into DB to be able to restore state later.

$mediaInfo = new MediaInfo();
$info = $mediaInfo->getInfo($url);

var_dump($info->getGeneral()); // all right

$xml = (string) $this->container->__toXML()->asXML();

The I try to restore the state:

$mediaInfoOutputParser = new MediaInfoOutputParser();
$mediaInfoOutputParser->parse($xml);

Getting such warning: Warning: simplexml_load_string(): Entity: line 2: parser error : Opening and ending tag mismatch: MediaInfoContainer line 2 and codec_id

Because of the such part:

...
<internet_media_type>video/mp4</internet_media_type>
 <codec_id>
    <0>qt  </0>
    <1>qt   0000.02 (qt  )</1>
</codec_id>
<codec_id_url>http://www.apple.com/quicktime/download/standalone.html</codec_id_url>
...

Mediainfo >= 17.10 changed XML Format

https://mediaarea.net/MediaInfo/ChangeLog / Version 17.10, 2017-11-02

  • New MediaInfo XML output, with XSD, more suitable for automatic parsing. Use Option("Inform", "OLDXML") for keeping previous behavior

Quick and Dirty solution -> change in Runner\MediaInfoCommandRunner.php

  • protected $arguments = ['--OUTPUT=XML', '-f'];
  • protected $arguments = ['--OUTPUT=OLDXML', '-f'];

A way to save modified information

So the question is pretty much in the title of this issue.

Is there a way to save information to the opened file?

For example, i have a library of 50 mkv files, and i know that each of them has 2 audio tracks, first track is for Russian language and second one is for English, however, these tracks are not 'labeled', so there is no 'language' attribute present on the Audio class.

The following piece of code is used to add missing feature to the audio track:

$locales = [
        0   =>  [
            'ru',
            'Russian',
            'Russian',
            'ru',
            'rus',
            'ru'
        ],
        1   =>  [
            'en',
            'English',
            'English',
            'en',
            'eng',
            'en',
        ]
    ];

    /**
     * @var \Mhor\MediaInfo\Type\Audio $audio
     */
    foreach ($mediaInfoContainer->getAudios() as $index => $audio) {
        $audio->set('language', $locales[$index]);
    }

So, back to the question again, how can i write back the updated information?

P.S. I know about duplicate array elements, however, just to be sure, i would like to leave them as they were read from the 'valid' file which was edited by my media player.

Warning: escapeshellarg() expects parameter 1 to be string, array given (...)

I am running into this error when I am trying to fetch information from a media.

ContextErrorException: Warning: escapeshellarg() expects parameter 1 to be string, array given in /Applications/MAMP/htdocs/playerAV/vendor/symfony/symfony/src/Symfony/Component/Process/ProcessUtils.php line 74

Here is my controller action code :

public function testMediaAction(){

    $mediaInfo = new MediaInfo();
    $repository = $this->getDoctrine()
                       ->getManager()
                       ->getRepository('PlayerBundle:Player\Media');

    $media = $repository->findOneBy(array('id' => '5'));
    $fichier = $media->getWebPath();

    $general = $mediaInfo->getInfo($fichier)->getGeneral();
    return $this->render('PlayerBundle:Player:Media/test.html.twig', array('general' => $general));
}

I can't find the part where I am doing something wrong. Any idea where the issue comes from ?
I am using Symfony 2.3, MediaInfo v0.7.77 (installed on Mac OS X via homebrew) and running my server locally with MAMP.

Encoding

Problem

Filenames with characters like 'ç,^' works nice when using php cli, but fails when loading via webserver.

Example:

$mkv_file = 'Êxodo: Deuses e Reis (2014)/Êxodo: Deuses e Reis.mkv';
$mediaInfo = new MediaInfo();
$mediaInfoContainer = $mediaInfo->getInfo($mkv_file);
var_dump($mediaInfoContainer);

Testing

Add 'ç' to a filename and test code above via cli and using php embed webserver

ErrorException: Undefined index: track in /var/www/vendor/mhor/php-mediainfo/src/Parser/MediaInfoOutputParser.php:46

I am getting this error while running $mediaInfo->getInfo($presignedUrl)
Below is error trace:
ErrorException: Undefined index: track in /var/www/vendor/mhor/php-mediainfo/src/Parser/MediaInfoOutputParser.php:46
Stack trace:
#0 /var/www/vendor/mhor/php-mediainfo/src/Parser/MediaInfoOutputParser.php(46): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined index...', '/var/www/vendor...', 46, Array)
#1 /var/www/vendor/mhor/php-mediainfo/src/MediaInfo.php(44): Mhor\MediaInfo\Parser\MediaInfoOutputParser->getMediaInfoContainer(false)
#2 /var/www/app/Services/MediaInfoService.php(35): Mhor\MediaInfo\MediaInfo->getInfo('https://s3-us-w...')
#3 /var/www/app/Traits/CableLabHelperTrait.php(143): App\Services\MediaInfoService->getMediaInfo('https://s3-us-w...')

The $presignedUrl value is :
https://s3-us-west-2.amazonaws.com/bluevo-gusto/mrss/Fresh%20Market%20Dinners/episodes/Fresh%20Market%20Dinners%20-%20S1E4%20-%20Raspberries%20Mint%20Peas%20and%20Apricot/thumbnail/xumo/FMD_1004_Fried%20Rainbow%20Trout%20%26%20Apricot%20Berry%20Chutney_1x1.jpg?X-Amz-Content-Sha256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAZMHPZBKBE7KWOJ5U%2F20210407%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20210407T190608Z&X-Amz-SignedHeaders=Host&X-Amz-Expires=604800&X-Amz-Signature=16cc63430e8e166f2fbced1552b99604d97227aeb47c00e9df09e4054c44a106

Height is expressed as a Rate

The absolute value for a rate is a float, and for a height, I would expect an integer rather than a float. Not sure if this can be fixed though.

Laravel 5.6 support

Hi,
Could be great to have the dependency updated to be compatible with Laravel 5.6
Error:
Conclusion: don't install symfony/process v4.0.2 - mhor/php-mediainfo 3.0.0 requires symfony/process ~2.3|~3.0
Thank you!

Unicode filename fail

I have this filename /path/Tenkû no shiro Rapyuta/file.avi and I try to get the media info but instead I get an empty exception throw on line 76 file /Runner/MediaInfoCommandRunner.php.

Im using this code inside a CentOS 7 docker image over Windows, and this is a shared volumen from local path.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.