wapmorgan/media-file

A unified reader of metadata from audio & video files

0.1.4 2018-03-10 00:56 UTC

This package is auto-updated.

Last update: 2024-12-17 04:46:17 UTC


README

Allows you easily get meta information about any media file with unified interface. The library has no requirements of external libs or system unitilies.

Latest Stable Version License Latest Unstable Version Tests

Supported formats

Table of contents:

  1. Usage
  2. API
  3. Why not using getID3?
  4. Technical details

Usage

use wapmorgan\MediaFile\MediaFile;

try {
  $media = MediaFile::open('123.mp3');
  // for audio
  if ($media->isAudio()) {
    $audio = $media->getAudio();
    echo 'Duration: '.$audio->getLength().PHP_EOL;
    echo 'Bit rate: '.$audio->getBitRate().PHP_EOL;
    echo 'Sample rate: '.$audio->getSampleRate().PHP_EOL;
    echo 'Channels: '.$audio->getChannels().PHP_EOL;
  }
  // for video
  else {
    $video = $media->getVideo();
    // calls to VideoAdapter interface
    echo 'Duration: '.$video->getLength().PHP_EOL;
    echo 'Dimensions: '.$video->getWidth().'x'.$video->getHeight().PHP_EOL;
    echo 'Framerate: '.$video->getFramerate().PHP_EOL;
  }
} catch (wapmorgan\MediaFile\Exceptions\FileAccessException $e) {
  // FileAccessException throws when file is not a detected media
} catch (wapmorgan\MediaFile\Exceptions\ParsingException $e) {
   echo 'File is propably corrupted: '.$e->getMessage().PHP_EOL;
}

API

MediaFile

wapmorgan\wapmorgan\MediaFile

AudioAdapter

wapmorgan\MediaFile\AudioAdapter

VideoAdapter

wapmorgan\MediaFile\VideoAdapter

ContainerAdapter

wapmorgan\MediaFile\ContainerAdapter

Why not using getID3?

getID3 library is very popular and has a lot of features, but it's old and too slow.

Following table shows comparation of analyzing speed of fixtures, distributed with first release of MediaFile:

Technical information