Coder Social home page Coder Social logo

php-mediainfo's Introduction

Php-MediaInfo Build Status Scrutinizer Code Quality Scrutinizer Coverage Packagist Packagist StyleCI

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) {
    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";
}

Ignore unknown types

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
}

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

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
  • frame_rate
  • format_settings_reframes
  • height
  • resolution
  • maximum_bit_rate

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

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

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

cklm avatar danog avatar grahamcampbell avatar javiertrejo avatar mhor avatar nek- avatar nicholi avatar

Watchers

 avatar

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.