• Stars
    star
    156
  • Rank 238,900 (Top 5 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A unified reader of metadata from audio & video files.

MediaFile

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

Audio Video
aac, amr, flac, mp3, ogg, wav, wma avi, mkv, mp4, wmv
- length - length
- bitRate - width
- sampleRate - height
- channels - frameRate

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

Method Description Notes
static open($filename): MediaFile Detects file type and format and calls constructor with these parameters. Throws an \Exception if file is not a media or is not accessible.
isAudio(): boolean Returns true if media is just audio.
isVideo(): boolean Returns true if media is a video with audio.
isContainer(): boolean Returns true if media is also a container (can store multiple audios and videos).
getFormat(): string Returns media file format.
getAudio(): AudioAdapter Returns an AudioAdapter interface for audio.
getVideo(): VideoAdapter Returns an VideoAdapter interface for video.

AudioAdapter

wapmorgan\MediaFile\AudioAdapter

Method Description
getLength(): float Returns audio length in seconds and microseconds as float.
getBitRate(): int Returns audio bit rate as int.
getSampleRate(): int Returns audio sampling rate as int.
getChannels(): int Returns number of channels used in audio as int.
isVariableBitRate(): boolean Returns whether format support VBR and file has VBR as boolean.
isLossless(): boolean Returns whether format has compression lossless as boolean.

VideoAdapter

wapmorgan\MediaFile\VideoAdapter

Method Description
getLength(): int Returns video length in seconds and microseconds as float.
getWidth(): int Returns width of video as int.
getHeight(): int Returns height of video as int.
getFramerate(): int Returns video frame rate of video as int.

ContainerAdapter

wapmorgan\MediaFile\ContainerAdapter

Method Description
countStreams(): int Returns number of streams in container as int.
countVideoStreams(): int Returns number of video streams as int.
countAudioStreams(): int Returns number of audio streams as int.
getStreams(): array Returns streams information as array.

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:

File getID3 MediaFile Speed gain
video.avi 0.215 0.126 1.71x
video.mp4 3.055 0.429 7.12x
video.wmv 0.354 0.372 0.95x
audio.aac 0.560 0.262 2.13x
audio.amr 8.241 12.248 0.67x
audio.flac 1.880 0.071 26.41x
audio.m4a 13.372 0.169 79.14x
audio.mp3 10.931 0.077 141.54x
audio.ogg 0.170 0.096 1.78x
audio.wav 0.114 0.070 1.64x
audio.wma 0.195 0.158 1.23x

Technical information

Format Full format name Specifications Notes
aac MPEG 4 Part 12 container with audio only http://l.web.umkc.edu/lizhu/teaching/2016sp.video-communication/ref/mp4.pdf Does not provide support of MPEG2-AAC
amr AMR-NB http://hackipedia.org/File%20formats/Containers/AMR,%20Adaptive%20MultiRate/AMR%20format.pdf Does not provide support of AMR-WB
avi - http://www.alexander-noe.com/video/documentation/avi.pdf
flac - - Support based on third-party library
mkv Matroska container https://www.matroska.org/technical/specs/index.html
mp3 MPEG 1/2 Layer 1/2/3 https://github.com/wapmorgan/mp3info#technical-information
mp4 MPEG 4 Part 12/14 container with few audio and video streams Part 12 specification: http://l.web.umkc.edu/lizhu/teaching/2016sp.video-communication/ref/mp4.pdf Part 14 extension: https://www.cmlab.csie.ntu.edu.tw/~cathyp/eBooks/14496_MPEG4/ISO_IEC_14496-14_2003-11-15.pdf
ogg Ogg container with Vorbis audio https://xiph.org/vorbis/doc/Vorbis_I_spec.html
wav - - Support based on third-party library
wma ASF container with only one audio stream http://go.microsoft.com/fwlink/p/?linkid=31334
wmv ASF container with few audio and video streams http://go.microsoft.com/fwlink/p/?linkid=31334

More Repositories

1

Morphos

A morphological solution for Russian and English language written completely in PHP. Provides classes to inflect personal names, geographical names, decline and pluralize nouns, generate cardinal and ordinal numerals, spell out money amounts and time intervals. / Морфологическая библиотека для английского и русского языков. Склоняет имена собственные, названия географических объектов, склонение и плюрализация имен собственных и другое.
PHP
783
star
2

PhpDeprecationDetector

Analyzer of PHP code to search issues with deprecated functionality in newer interpreter versions.
PHP
365
star
3

UnifiedArchive

UnifiedArchive - an archive manager with unified interface for different formats (bundled with cli utility). Supports all formats with basic operations (reading, extracting and creation) and popular formats specific features (compression level, password-protection, comment)
PHP
274
star
4

Mp3Info

The fastest PHP library to extract mp3 meta information (duration, bitrate, samplerate and so on) and tags (id3v1, id3v2).
PHP
138
star
5

PhpCodeAnalyzer

PhpCodeAnalyzer scans codebase and analyzes which non-built-in php extensions used
PHP
96
star
6

TimeParser

A parser for date and time written in natural language for PHP.
PHP
95
star
7

Threadable

Easy-to-use threading library providing all basic features to perform work in background mode (with simulation mode).
PHP
77
star
8

java_for_beginners_book

71
star
9

SystemDaemon

Simple base for system daemons
PHP
60
star
10

BinaryStream

BinaryStream - a writer and reader for binary data. Best replacement for pack()/unpack().
PHP
52
star
11

csharp_for_beginners

49
star
12

Morphos-Blade

Morphos adapter for Blade
PHP
34
star
13

NcursesObjects

This is a php library that provides ncurses functionality in OOP way
PHP
34
star
14

FileTypeDetector

Detects file type by filename or content and generates correct mimetype.
PHP
33
star
15

yii2-inflection

Inflection extension for Yii2. Support for English / Russian languages to inflect words / names / numbers / money / date&time.
PHP
31
star
16

Imagery

Imagery simplifies image manipulations.
PHP
25
star
17

awesome-webservice

A curated list of awesome web services.
25
star
18

OpenApiGenerator

OpenApi configuration generator directly from PHP code (PhpDoc and php type hints). Can be used with a large monolithic backend
PHP
19
star
19

php-rpm-packager

A simple rpm packager for PHP applications.
PHP
10
star
20

Morphos-Twig

Morphos adapter for Twig
PHP
9
star
21

OneCloudApi.php

API client for 1cloud.ru
PHP
6
star
22

CabArchive

CabArchive - reader of cab-archives
PHP
3
star
23

ImageEditor

Moved to
PHP
3
star
24

posvt_ipz

CSS
1
star
25

cpp_for_beginners_book

1
star