wapmorgan/media-file
Composer 安装命令:
composer require wapmorgan/media-file
包简介
A unified reader of metadata from audio & video files
README 文档
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
| Audio | Video |
|---|---|
| aac, amr, flac, mp3, ogg, wav, wma | avi, mkv, mp4, wmv |
| - length | - length |
| - bitRate | - width |
| - sampleRate | - height |
| - channels | - frameRate |
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
| 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
wapmorgan/media-file 适用场景与选型建议
wapmorgan/media-file 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 237.74k 次下载、GitHub Stars 达 158, 最近一次更新时间为 2017 年 02 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mp3」 「wav」 「mp4」 「ogg」 「flac」 「aac」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wapmorgan/media-file 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wapmorgan/media-file 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wapmorgan/media-file 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP-Client which enables you to seamlessly integrate the Bitmovin API into your existing projects
PHP library for handling audio/video files metadata
PHP package to parse and update audio files metadata, with `JamesHeinrich/getID3`.
Library for manipulating audio files (validating, transcoding, and tagging)
A light weight Laravel package for simple operations with mp3 files
A wrapper around james-heinrich/getid3 to extract various information from media files.
统计信息
- 总下载量: 237.74k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 162
- 点击次数: 36
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-02-06