fireworkweb/smpte
Composer 安装命令:
composer create-project fireworkweb/smpte
包简介
Easily deal with Timecode SMPTE format in PHP
README 文档
README
Easily deal with SMPTE Timecode format in PHP. If you need a Javascript lib, check out fireworkweb/smpte.js.
Installation
You can install the package via composer:
composer require fireworkweb/smpte
Usage
Include the Timecode or Validations classes:
use FireworkWeb\SMPTE\Timecode; use FireworkWeb\SMPTE\Validations;
You can instantiate it directly using new:
// passing frame count $timecode = new Timecode(360); // passing a timecode string $timecode = new Timecode('00:00:01:10'); // passing a Datetime object $timecode = new Timecode(new \DateTime('01:34:12'));
Or you can use the static helper:
$timecode = Timecode::fromSeconds(10);
Properties
| Property | Type | Description |
|---|---|---|
getFrameCount() |
int |
Total number of frames |
getHours() |
int |
Hours number |
getMinutes() |
int |
Minutes number |
getSeconds() |
int |
Seconds number |
getFrames() |
int |
Frames number |
durationInSeconds() |
int |
Timecode duration in seconds |
Object Methods
__construct($time = 0, $frameRate = null, $dropFrame = null)
$time:int|String|Timecodetime to start with.$frameRate:floatframe rate to calculate the timecode.$dropFrame:boolindicates if is drop frame. ONLY WITH 29.97 FPS
$time as int is the frame count to be setted with. To deal with seconds, use fromSeconds.
Note: if $frameRate or $dropFrame are null, it will use the default.
toString() / __toString()
Returns a timecode string representation.
(new Timecode(360))->toString(); // "00:00:15:00"
add($time, $operation = 1)
Adds a timecode or a frame count to the current Timecode object.
$time:int|String|Timecodeindicating the value to be added.$operation:intused to get the sign oftime.return:TimecodeReference to theTimecodeobject.
$tc = new Timecode('00:01:00:00'); // Adding from string $tc->add('00:00:30:00')->toString(); // 00:01:30:00 // Adding frame count $tc->add(1)->toString(); // 00:01:30:01 // Adding from another object $tc2 = new Timecode('00:01:00:00'); $tc->add($tc2)->toString(); // 00:02:30:01
subtract($time)
Substracts a timecode or a frame count to the current Timecode object.
$time:int|String|Timecodeindicating the value to be added.return:TimecodeReference to theTimecodeobject.
$tc = new Timecode('00:03:00:00'); // Subtracting from string $tc->subtract('00:00:30:00')->toString(); // 00:02:30:00 // Subtracting frame count $tc->subtract(1)->toString(); // 00:02:29:23 // Subtracting from another object $tc2 = new Timecode('00:01:00:00'); $tc->subtract($tc2)->toString(); // 00:01:29:23
setHours($hours)
Directly set object hours.
$hours:intindicating the value to be setted.
$tc = new Timecode('00:03:00:00'); $tc->setHours(1)->toString(); // 01:03:00:00
setMinutes($minutes)
Directly set object minutes.
$minutes:intindicating the value to be setted.
$tc = new Timecode('00:03:00:00'); $tc->setMinutes(1)->toString(); // 00:01:00:00
setSeconds($seconds)
Directly set object seconds.
$seconds:intindicating the value to be setted.
$tc = new Timecode('00:03:00:00'); $tc->setSeconds(1)->toString(); // 00:03:01:00
setFrames($frames)
Directly set object frames.
$frames:intindicating the value to be setted.
$tc = new Timecode('00:03:00:00'); $tc->setFrames(1)->toString(); // 00:03:00:01
setFrameCount($frameCount)
Directly set object frame count. This will recalculate all other attributes, so use it with care.
$frameCount:intindicating the value to be setted.
$tc = new Timecode('00:03:00:00'); $tc->setFrameCount(360)->toString(); // 00:00:15:00
Static Methods
frameCountFromTimecode($time, $frameRate = null, $dropFrame = null)
Returns the frame count from a time.
$time:Stringtime as string to calculate.$frameRate:floatframe rate to calculate the timecode.$dropFrame:boolindicates if is drop frame.return:intreturns the frame count
fromSeconds($seconds, $frameRate = null, $dropFrame = null)
Instantiate a new object from seconds instead of timecode/framecount.
$seconds:intseconds to convert$frameRate:floatframe rate to calculate the timecode.$dropFrame:boolindicates if is drop frame.return:TimecodeReturns the newly created object
$tc = Timecode::fromSeconds(15); $tc->toString(); // 00:00:15:00
setDefaultFrameRate($frameRate)
Change default frame rate to instantiate objects with.
$frameRate:floatNew default frame rate.
$tc = new Timecode(); $tc->getFrameRate(); // 24 Timecode::setDefaultFrameRate(25); $tc2 = new Timecode(); $tc2->getFrameRate(); // 25
setDefaultDropFrame($dropFrame)
Change default drop frame to instantiate objects with.
$dropFrame:floatNew default drop frame.
$tc = new Timecode(); $tc->getDropFrame(); // false Timecode::setDefaultDropFrame(true); $tc2 = new Timecode(); $tc2->getDropFrame(); // true
Contributing
All contribution is welcome, please feel free to open tickets and pull requests.
License
fireworkweb/smpte 适用场景与选型建议
fireworkweb/smpte 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34.68k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2018 年 11 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「subtitle」 「timecode」 「smpte」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fireworkweb/smpte 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fireworkweb/smpte 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fireworkweb/smpte 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Lib allowing to deal with timecode manipulation
Implementation of subtitles converter with following supported formats: srt, webvtt, ttaf1, txt, tabtxt
FFMpeg video/audio/subs conversions, thumbnails, audio extraction, query...
Simple, lightweight PHP-SDK for accessing subtitles from OpenSubtitles.org
Simple, lightweight PHP-SDK for searching and downloading subtitles from Subscene.com
Download subtitles from www.addic7ed.com
统计信息
- 总下载量: 34.68k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-11-05