codememory / media-file-fork
A unified reader of metadata from audio & video files
v1.0
2022-06-17 21:10 UTC
Requires
- php: >=5.5
- bluemoehre/flac-php: 1.0.2
- codememory/wave-fork: 1.0
- wapmorgan/binary-stream: ~0.4.0
- wapmorgan/file-type-detector: ^1.0.2
- wapmorgan/mp3info: ~0.0
Requires (Dev)
- james-heinrich/getid3: ^1.9
- phpunit/phpunit: ~4.8
Suggests
- boyhagemann/wave: Wav support
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.
Supported formats
Table of contents:
- Usage
- API
- Why not using getID3?
- 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: