PHP Classes
elePHPant
Icontem

PHP Media File Info: Extract metadata from audio and video files

Recommend this page to a friend!
  Info   View files Example   View files View files (24)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-02-14 (15 days ago) RSS 2.0 feedNot enough user ratingsTotal: 49 This week: 49All time: 8,751 This week: 14Up
Version License PHP version Categories
mediafile 0.1.0MIT/X Consortium ...5.3.6Utilities and Tools, Files and Folders
Description Author

This package can extract metadata from audio and video files.

It can parse different formats of audio and video and extract metadata.

The package can detect the file types if they are audio or video, and what is the format, WAV, FLAC, AAC, OGG, MP3, AMR, WMA for audio, and AVI, WMV and MP4 for video.

It can also return stream length, bit bate, sample rate, channels, width, height, frame rate, number of streams and type of streams.

Innovation Award
PHP Programming Innovation award nominee
February 2017
Nominee
Vote
PHP provides good file type detection methods using the fileinfo extension. However, that extension only detect the type of file and does not give much more information.

This package provides means to not only detect the file types of audio and video files, but also extract several types of metadata like audio and video length, resolution, etc.. It supports many types of well known video and audio formats.

Manuel Lemos
  Performance   Level  
Name: Sergey Vanyushin <contact>
Classes: 20 packages by
Country: Russian Federation Russian Federation
Innovation award
Innovation award
Nominee: 10x

Winner: 1x

Details

MediaFile

Allows you easily get meta information about any media file with unified interface.

Composer package Latest Stable Version License Latest Unstable Version

It can retrieve following information:

  • For any audio: length, bitRate, sampleRate, channels
  • For any video: length, width, height, frameRate
  • For any container: number of streams, type of streams, formats of streams

Table of contents:

  1. Usage
  2. Supported formats
  3. API
  4. Technical details

Usage

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

Supported formats

  • Audio - wav - flac - aac - ogg - mp3 - amr - wma
  • Video - avi (also as container) - wmv (also as container) - mp4 (also as container)

Other formats support coming soon.

API

MediaFile

wapmorgan\wapmorgan\MediaFile

| Method | Description | Notes | |------------------------------------------|-----------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------| | static open($filename) | Detects file type and format and calls constructor with these parameters. | Throws an \Exception if file is not a media or is not accessible. | | __construct($filename, $type, $format) | Opens file and reads metadata. | Available $type values: MediaFile::AUDIO, MediaFile::VIDEO. Available $format values see below. | | isAudio() | Returns true if media is just audio. | | | isVideo() | Returns true if media is a video with audio. | | | isContainer() | Returns true if media is also a container (can store multiple audios and videos). | | | getType() | Returns media file type. | | | getFormat() | Returns media file format. | | | getAudio() | Returns an AudioAdapter interface for audio. | | | getVideo() | Returns an VideoAdapter interface for video. | |

Available formats:

  1. For MediaFile::AUDIO:

    | MediaFile::WAV | MediaFile::FLAC | MediaFile::AAC | MediaFile::OGG | |----------------------|----------------------|----------------------|------------------| | MediaFile::MP3 | MediaFile::AMR | MediaFile::WMA | |

  2. For MediaFile::VIDEO:

    | MediaFile::AVI | MediaFile::WMV | MediaFile::MP4 | |------------------|------------------|------------------|

AudioAdapter

wapmorgan\MediaFile\AudioAdapter

| Method | Description | |-----------------------|-------------------------------------------------------------------| | getLength() | Returns audio length in seconds and microseconds as _float_. | | getBitRate() | Returns audio bit rate as _int_. | | getSampleRate() | Returns audio sampling rate as _int_. | | getChannels() | Returns number of channels used in audio as _int_. | | isVariableBitRate() | Returns whether format support VBR and file has VBR as _boolean_. | | isLossless() | Returns whether format has compression lossless as _boolean_. |

VideoAdapter

wapmorgan\MediaFile\VideoAdapter

| Method | Description | |------------------|--------------------------------------------------------------| | getLength() | Returns video length in seconds and microseconds as _float_. | | getWidth() | Returns width of video as _int_. | | getHeight() | Returns height of video as _int_. | | getFramerate() | Returns video frame rate of video as _int_. |

ContainerAdapter

wapmorgan\MediaFile\ContainerAdapter

| Method | Description | |-----------------------|--------------------------------------------------| | countStreams() | Returns number of streams in container as _int_. | | countVideoStreams() | Returns number of video streams as _int_. | | countAudioStreams() | Returns number of audio streams as _int_. | | getStreams() | Returns streams information as _array_. |

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 | | 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 | |

  Files folder image Files  
File Role Description
Files folder imagebin (1 file)
Files folder imagesrc (19 files)
Plain text file composer.json Data Auxiliary data
Plain text file LICENSE Lic. License text
Plain text file README.md Doc. Documentation
Plain text file _config.yml Data Auxiliary data

  Files folder image Files  /  bin  
File Role Description
  Plain text file mediafile Example Example script

  Files folder image Files  /  src  
File Role Description
  Plain text file AacAdapter.php Class Class source
  Plain text file AmrAdapter.php Class Class source
  Plain text file AsfAdapter.php Class Class source
  Plain text file AudioAdapter.php Class Class source
  Plain text file AviAdapter.php Class Class source
  Plain text file ContainerAdapter.php Class Class source
  Plain text file Exception.php Class Class source
  Plain text file FileAccessException.php Class Class source
  Plain text file FlacAdapter.php Class Class source
  Plain text file MediaFile.php Class Class source
  Plain text file Mp3Adapter.php Class Class source
  Plain text file Mp4Adapter.php Class Class source
  Plain text file Mpeg4Part12Adapter.php Class Class source
  Plain text file OggAdapter.php Class Class source
  Plain text file ParsingException.php Class Class source
  Plain text file VideoAdapter.php Class Class source
  Plain text file WavAdapter.php Class Class source
  Plain text file WmaAdapter.php Class Class source
  Plain text file WmvAdapter.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:49
This week:49
All time:8,751
This week:14Up