{"id":13828494,"url":"https://github.com/mhor/php-mediainfo","last_synced_at":"2025-12-30T06:40:59.467Z","repository":{"id":24278832,"uuid":"27673427","full_name":"mhor/php-mediainfo","owner":"mhor","description":"PHP wrapper around the mediainfo command","archived":false,"fork":false,"pushed_at":"2024-02-14T22:41:13.000Z","size":771,"stargazers_count":118,"open_issues_count":8,"forks_count":27,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-09-08T13:43:59.327Z","etag":null,"topics":["id3","id3v2","mediainfo","metadata","php","wrapper"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"spatie/guidelines.spatie.be","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mhor.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-12-07T14:52:03.000Z","updated_at":"2024-07-23T09:47:47.000Z","dependencies_parsed_at":"2024-02-14T22:29:52.259Z","dependency_job_id":"6cb6d96e-8eda-4a59-8bb2-6fe8105599e9","html_url":"https://github.com/mhor/php-mediainfo","commit_stats":{"total_commits":181,"total_committers":18,"mean_commits":"10.055555555555555","dds":0.3812154696132597,"last_synced_commit":"103b767270817f178c76eeda04a445387268c2a5"},"previous_names":[],"tags_count":40,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhor%2Fphp-mediainfo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhor%2Fphp-mediainfo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhor%2Fphp-mediainfo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mhor%2Fphp-mediainfo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mhor","download_url":"https://codeload.github.com/mhor/php-mediainfo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225492420,"owners_count":17482869,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["id3","id3v2","mediainfo","metadata","php","wrapper"],"created_at":"2024-08-04T09:02:49.370Z","updated_at":"2025-12-30T06:40:59.428Z","avatar_url":"https://github.com/mhor.png","language":"PHP","readme":"# Php-MediaInfo [![Coverage Status](https://coveralls.io/repos/github/mhor/php-mediainfo/badge.svg?branch=master)](https://coveralls.io/github/mhor/php-mediainfo?branch=master) [![Packagist](https://img.shields.io/packagist/v/mhor/php-mediainfo.svg)](https://packagist.org/packages/mhor/php-mediainfo) [![Packagist](https://img.shields.io/packagist/dt/mhor/php-mediainfo.svg)](https://packagist.org/packages/mhor/php-mediainfo) [![Code Checks](https://github.com/mhor/php-mediainfo/actions/workflows/code_checks.yml/badge.svg)](https://github.com/mhor/php-mediainfo/actions/workflows/code_checks.yml)\n\n## Introduction\n\nPHP wrapper around the `mediainfo` command\n\n## Table of contents:\n- [Installation](#installation)\n- [How to use](#how-to-use)\n- [Specials types](#specials-types)\n- [Extra](#extra)\n- [License](#license)\n\n## Installation\n\n### 1 - Install mediainfo\nYou should install [mediainfo](http://manpages.ubuntu.com/manpages/gutsy/man1/mediainfo.1.html):\n\n#### On linux:\n\n```bash\n$ sudo apt-get install mediainfo\n```\n\n#### On Mac:\n\n```bash\n$ brew install mediainfo\n```\n\n### 2 - Integration in your php project\n\nTo use this library install it through [Composer](https://getcomposer.org/), run:\n\n```bash\n$ composer require mhor/php-mediainfo\n```\n\n## How to use\n\n### Retrieve media information container\n\n```php\n\u003c?php\n//...\nuse Mhor\\MediaInfo\\MediaInfo;\n//...\n$mediaInfo = new MediaInfo();\n$mediaInfoContainer = $mediaInfo-\u003egetInfo('music.mp3');\n//...\n```\n\n### Get general information from media information container\n\n```php\n$general = $mediaInfoContainer-\u003egetGeneral();\n```\n\n### Get videos information from media information container\n\n```php\n$videos = $mediaInfoContainer-\u003egetVideos();\n\nforeach ($videos as $video) {\n    // ... do something\n}\n```\n\n### Get audios information from media information container\n\n```php\n$audios = $mediaInfoContainer-\u003egetAudios();\n\nforeach ($audios as $audio) {\n    // ... do something\n}\n```\n\n### Get subtitles information from media information container\n\n```php\n$subtitles = $mediaInfoContainer-\u003egetSubtitles();\n\nforeach ($subtitles as $subtitle) {\n    // ... do something\n}\n```\n\n### Get images information from media information container\n\n```php\n$images = $mediaInfoContainer-\u003egetImages();\n\nforeach ($images as $image) {\n    // ... do something\n}\n```\n\n### Get menus information from media information container\n\n```php\n$menus = $mediaInfoContainer-\u003egetMenus();\n\nforeach ($menus as $menu) {\n    // ... do something\n}\n```\n\n### Example\n\n```php\n\u003c?php\n\nrequire './vendor/autoload.php';\n\nuse Mhor\\MediaInfo\\MediaInfo;\n\n$mediaInfo = new MediaInfo();\n$mediaInfoContainer = $mediaInfo-\u003egetInfo('./SampleVideo_1280x720_5mb.mkv');\n\necho \"Videos channel: \\n\";\necho \"=======================\\n\";\nforeach ($mediaInfoContainer-\u003egetVideos() as $video) {\n    if ($video-\u003ehas('format')) {\n        echo 'format: '.(string)$video-\u003eget('format').\"\\n\";\n    }\n\n    if ($video-\u003ehas('height')) {\n        echo 'height: '.$video-\u003eget('height')-\u003egetAbsoluteValue().\"\\n\";\n    }\n\n    echo \"\\n---------------------\\n\";\n}\n\necho \"Audios channel: \\n\";\necho \"=======================\\n\";\nforeach ($mediaInfoContainer-\u003egetAudios() as $audio) {\n    $availableInfo = $audio-\u003elist();\n    foreach ($availableInfo as $key) {\n        echo $audio-\u003eget($key);\n    }\n    echo \"\\n---------------------\\n\";\n}\n```\n\n### Ignore unknown types\n\nBy default, unknown type throw an error this, to avoid this behavior, you can do:\n\n```php\n$mediaInfo = new MediaInfo();\n$mediaInfo-\u003esetConfig('ignore_unknown_track_types', true);\n\n$mediaInfoContainer = $mediaInfo-\u003egetInfo('music.mp3');\n\n$others = $mediaInfoContainer-\u003egetOthers();\nforeach ($others as $other) {\n    // ... do something\n}\n```\n\n### Access to information\n\n#### Get all information into an array\n\n```php\n$informationArray = $general-\u003eget();\n```\n\n#### Get one information by field name\n\nField Name are in lower case separated by \"_\"\n\n```php\n$oneInformation = $general-\u003eget('count_of_audio_streams');\n```\n\n#### Check if information exists\n\nField Name are in lower case separated by \"_\"\n\n```php\nif ($general-\u003ehas('count_of_audio_streams')) {\n    echo $general-\u003eget('count_of_audio_streams');\n}\n```\n\n#### List available information\n\n```php\n$availableInfo = $general-\u003elist();\nforeach ($availableInfo as $key) {\n    echo $general-\u003eget($key);\n}\n```\n\n### Specials types\n\n#### Cover\n\nFor field:\n\n- cover_data\n\n[Cover](src/Attribute/Cover.php) type will be applied\n\n#### Duration\n\nFor fields:\n\n- duration\n- delay_relative_to_video\n- video0_delay\n- delay\n\n[Duration](src/Attribute/Duration.php) type will be applied\n\n#### Mode\n\nFor fields:\n\n- overall_bit_rate_mode\n- overall_bit_rate\n- bit_rate_mode\n- compression_mode\n- codec\n- format\n- kind_of_stream\n- writing_library\n- id\n- format_settings_sbr\n- channel_positions\n- default\n- forced\n- delay_origin\n- scan_type\n- interlacement\n- scan_type\n- frame_rate_mode\n- format_settings_cabac\n- unique_id\n\n[Mode](src/Attribute/Mode.php) type will be applied\n\n#### Rate\n\nFor fields:\n\n- channel_s\n- bit_rate\n- sampling_rate\n- bit_depth\n- width\n- nominal_bit_rate\n- format_settings_reframes\n- height\n- resolution\n- maximum_bit_rate\n\n[Rate](src/Attribute/Rate.php) type will be applied\n\n#### FloatRate\n\nFor fields:\n\n- frame_rate\n\n[FloatRate](src/Attribute/FloatRate.php) type will be applied\n\n\n#### Ratio\n\nFor fields:\n\n- display_aspect_ratio\n- original_display_aspect_ratio\n\n[Ratio](src/Attribute/Ratio.php) type will be applied\n\n#### Size\n\nFor fields:\n\n- file_size\n- stream_size\n\n[Size](src/Attribute/Size.php) type will be applied\n\n#### Others\n- All date fields will be transformed into `Datetime` php object\n\n## Extra\n\n### Use custom mediainfo path\n\n```php\n$mediaInfo = new MediaInfo();\n$mediaInfo-\u003esetConfig('command', '/usr/local/bin/mediainfo');\n$mediaInfoContainer = $mediaInfo-\u003egetInfo('music.mp3');\n```\n\n### Support old mediainfo version (\u003c17.10)\n\n```php\n$mediaInfo = new MediaInfo();\n$mediaInfo-\u003esetConfig('use_oldxml_mediainfo_output_format', false);\n$mediaInfoContainer = $mediaInfo-\u003egetInfo('music.mp3');\n```\n\n### Use url as filepath\n\n```php\n$mediaInfo = new MediaInfo();\n$mediaInfoContainer = $mediaInfo-\u003egetInfo('http://example.org/music/test.mp3');\n```\n\n### MediaInfoContainer to JSON, Array or XML\n\n```php\n$mediaInfo = new MediaInfo();\n$mediaInfoContainer = $mediaInfo-\u003egetInfo('music.mp3');\n\n$json = json_encode($mediaInfoContainer);\n$array = $mediaInfoContainer-\u003e__toArray();\n$xml = $mediaInfoContainer-\u003e__toXML();\n```\n\n### Usage for WindowsOS\n\nDownload MediaInfo CLI from [here](https://mediaarea.net/de/MediaInfo/Download/Windows). Extract zip-archive and place MediaInfo.exe somewhere. Use it:\n\n```php\n$mediaInfo = new MediaInfo();\n$mediaInfo-\u003esetConfig('command', 'C:\\path\\to\\directory\\MediaInfo.exe');\n$mediaInfoContainer = $mediaInfo-\u003egetInfo('music.mp3');\n```\n\n### Urlencode Config\n\nBy default, MediaInfo tries to detect if a URL is already percent-encode and encodes the URL when it's not.\nSetting the `'urlencode'` config setting to `true` forces MediaInfo to encode the URL despite the presence of percentage signs in the URL.\nThis is for example required when using pre-signed URLs for AWS S3 objects.\n\n```php\n$mediaInfo = new MediaInfo();\n$mediaInfo-\u003esetConfig('urlencode', true);\n$mediaInfoContainer = $mediaInfo-\u003egetInfo('https://demo.us-west-1.amazonaws.com/video.mp4?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD\u0026X-Amz-Algorithm=AWS4-HMAC-SHA256\u0026X-Amz-Credential=ABC%2F123%2Fus-west-1%2Fs3%2Faws4_request\u0026X-Amz-Date=20200721T114451Z\u0026X-Amz-SignedHeaders=host\u0026X-Amz-Expires=600\u0026X-Amz-Signature=123');\n```\n\nThis setting requires MediaInfo `20.03` minimum\n\n### Cover data\n\nRecent 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](#cover) for details on retrieving the base64 encoded image from `cover_data`.\n\nOriginally this cover data was always included in the MediaInfo output, so this option is unnecessary for older versions. But [around version 18](https://sourceforge.net/p/mediainfo/discussion/297610/thread/aeb4222d/?limit=25) cover data was removed from the output by default, unless you also pass the `--Cover_Data=base64` flag.\n\n```php\n$mediaInfo = new MediaInfo();\n$mediaInfo-\u003esetConfig('include_cover_data', true);\n$mediaInfoContainer = $mediaInfo-\u003egetInfo('music.mp3');\n\n$general = $mediaInfoContainer-\u003egetGeneral();\nif ($general-\u003ehas('cover_data')) {\n    $attributeCover = $general-\u003eget('cover_data');\n    $base64EncodedImage = $attributeCover-\u003egetBinaryCover();\n}\n```\n\n**Note:** Older versions of MediaInfo will print the following error if passed this flag:\n\n```bash\n$ mediainfo ./music.mp3 -f --OUTPUT=OLDXML --Cover_Data=base64\nOption not known\n```\n\n### Override attribute checkers/types\n\nThis 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.\n\n1. Create a new class that implements the ``AttributeCheckerInterface``\n\n```php\nclass CustomDurationChecker extends \\Mhor\\MediaInfo\\Checker\\DurationChecker\n{\n    public function create($durations): \\Mhor\\MediaInfo\\Attribute\\Duration\n    {\n        return new CustomDuration($durations[0]);\n    }\n\n    public function getMembersFields(): array\n    {\n        return [\n            'duration',\n        ];\n    }\n}\n```\n\n2. Create a new class that implements the ``AttributeInterface``\n\n```php\nclass CustomDuration extends \\Mhor\\MediaInfo\\Attribute\\Duration\n{\n    public function getSeconds()\n    {\n        return $this-\u003egetMilliseconds() / 1000;\n    }\n}\n```\n\n3. Set the new list of attribute checkers into the config\n\n```php\n$mediaInfo = new MediaInfo();\n$mediaInfo-\u003esetConfig('attribute_checkers', [new CustomDurationChecker()]);\n$mediaInfoContainer = $mediaInfo-\u003egetInfo(\n    './SampleVideo_1280x720_5mb.mkv'\n);\n\nforeach ($mediaInfoContainer-\u003egetAudios() as $audio) {\n    echo $audio-\u003eget('duration')-\u003egetSeconds();\n}\n```\n\n### Symfony integration\n\nLook at this bundle: [MhorMediaInfoBunde](https://github.com/mhor/MhorMediaInfoBundle)\n\n### Codeigniter integration\n\nLook at [this](https://philsturgeon.uk/blog/2012/05/composer-with-codeigniter/) to use composer with Codeigniter\n\n## License\nSee `LICENSE` for more information\n","funding_links":[],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmhor%2Fphp-mediainfo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmhor%2Fphp-mediainfo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmhor%2Fphp-mediainfo/lists"}