{"id":22425231,"url":"https://github.com/fireworkweb/smpte.php","last_synced_at":"2025-08-01T08:32:57.460Z","repository":{"id":33234379,"uuid":"155253578","full_name":"fireworkweb/smpte.php","owner":"fireworkweb","description":"Easily deal with Timecode SMPTE format in PHP","archived":false,"fork":false,"pushed_at":"2024-11-05T14:36:55.000Z","size":58,"stargazers_count":7,"open_issues_count":2,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-30T20:20:01.948Z","etag":null,"topics":["composer","laravel","php","smpte","timecode"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fireworkweb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-29T17:32:57.000Z","updated_at":"2024-11-05T14:36:40.000Z","dependencies_parsed_at":"2022-08-09T09:30:23.846Z","dependency_job_id":null,"html_url":"https://github.com/fireworkweb/smpte.php","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fireworkweb%2Fsmpte.php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fireworkweb%2Fsmpte.php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fireworkweb%2Fsmpte.php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fireworkweb%2Fsmpte.php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fireworkweb","download_url":"https://codeload.github.com/fireworkweb/smpte.php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228356402,"owners_count":17907191,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["composer","laravel","php","smpte","timecode"],"created_at":"2024-12-05T19:13:35.279Z","updated_at":"2024-12-05T19:13:35.969Z","avatar_url":"https://github.com/fireworkweb.png","language":"PHP","readme":"# smpte.php\n\n[![Build Status](https://travis-ci.com/fireworkweb/smpte.php.svg?branch=master)](https://travis-ci.com/fireworkweb/smpte.php)\n[![codecov](https://codecov.io/gh/fireworkweb/smpte.php/branch/master/graph/badge.svg)](https://codecov.io/gh/fireworkweb/smpte.php)\n\nEasily deal with SMPTE Timecode format in PHP. If you need a Javascript lib, check out [fireworkweb/smpte.js](https://github.com/fireworkweb/smpte.js).\n\n## Installation\n\nYou can install the package via composer:\n\n```sh\ncomposer require fireworkweb/smpte\n```\n\n## Usage\n\nInclude the Timecode or Validations classes:\n\n```php\nuse FireworkWeb\\SMPTE\\Timecode;\nuse FireworkWeb\\SMPTE\\Validations;\n```\n\nYou can instantiate it directly using new:\n\n```php\n// passing frame count\n$timecode = new Timecode(360);\n\n// passing a timecode string\n$timecode = new Timecode('00:00:01:10');\n\n// passing a Datetime object\n$timecode = new Timecode(new \\DateTime('01:34:12'));\n```\n\nOr you can use the static helper:\n\n```php\n$timecode = Timecode::fromSeconds(10);\n```\n\n### Properties\n\n| Property              | Type  | Description                  |\n| --------------------- | ----- | ---------------------------- |\n| `getFrameCount()`     | `int` | Total number of frames       |\n| `getHours()`          | `int` | Hours number                 |\n| `getMinutes()`        | `int` | Minutes number               |\n| `getSeconds()`        | `int` | Seconds number               |\n| `getFrames()`         | `int` | Frames number                |\n| `durationInSeconds()` | `int` | Timecode duration in seconds |\n\n### Object Methods\n\n#### `__construct($time = 0, $frameRate = null, $dropFrame = null)`\n\n* `$time`: `int|String|Timecode` time to start with.\n* `$frameRate`: `float` frame rate to calculate the timecode.\n* `$dropFrame`: `bool` indicates if is drop frame. **ONLY WITH 29.97 FPS**\n\n`$time` as int is the frame count to be setted with. To deal with seconds, use `fromSeconds`.\n\n**Note:** if `$frameRate` or `$dropFrame` are null, it will use the default.\n\n#### `toString()` / `__toString()`\n\nReturns a timecode string representation.\n\n```php\n(new Timecode(360))-\u003etoString();\n// \"00:00:15:00\"\n```\n\n#### `add($time, $operation = 1)`\n\nAdds a timecode or a frame count to the current Timecode object.\n\n* `$time`: `int|String|Timecode` indicating the value to be added.\n* `$operation`: `int` used to get the sign of `time`.\n* `return`: `Timecode` Reference to the `Timecode` object.\n\n```php\n$tc = new Timecode('00:01:00:00');\n\n// Adding from string\n$tc-\u003eadd('00:00:30:00')-\u003etoString();\n// 00:01:30:00\n\n// Adding frame count\n$tc-\u003eadd(1)-\u003etoString();\n// 00:01:30:01\n\n// Adding from another object\n$tc2 = new Timecode('00:01:00:00');\n$tc-\u003eadd($tc2)-\u003etoString();\n// 00:02:30:01\n```\n\n#### `subtract($time)`\n\nSubstracts a timecode or a frame count to the current Timecode object.\n\n* `$time`: `int|String|Timecode` indicating the value to be added.\n* `return`: `Timecode` Reference to the `Timecode` object.\n\n```php\n$tc = new Timecode('00:03:00:00');\n\n// Subtracting from string\n$tc-\u003esubtract('00:00:30:00')-\u003etoString();\n// 00:02:30:00\n\n// Subtracting frame count\n$tc-\u003esubtract(1)-\u003etoString();\n// 00:02:29:23\n\n// Subtracting from another object\n$tc2 = new Timecode('00:01:00:00');\n$tc-\u003esubtract($tc2)-\u003etoString();\n// 00:01:29:23\n```\n\n#### `setHours($hours)`\n\nDirectly set object hours.\n\n* `$hours`: `int` indicating the value to be setted.\n\n```php\n$tc = new Timecode('00:03:00:00');\n$tc-\u003esetHours(1)-\u003etoString();\n// 01:03:00:00\n```\n\n#### `setMinutes($minutes)`\n\nDirectly set object minutes.\n\n* `$minutes`: `int` indicating the value to be setted.\n\n```php\n$tc = new Timecode('00:03:00:00');\n$tc-\u003esetMinutes(1)-\u003etoString();\n// 00:01:00:00\n```\n\n#### `setSeconds($seconds)`\n\nDirectly set object seconds.\n\n* `$seconds`: `int` indicating the value to be setted.\n\n```php\n$tc = new Timecode('00:03:00:00');\n$tc-\u003esetSeconds(1)-\u003etoString();\n// 00:03:01:00\n```\n\n#### `setFrames($frames)`\n\nDirectly set object frames.\n\n* `$frames`: `int` indicating the value to be setted.\n\n```php\n$tc = new Timecode('00:03:00:00');\n$tc-\u003esetFrames(1)-\u003etoString();\n// 00:03:00:01\n```\n\n#### `setFrameCount($frameCount)`\n\nDirectly set object frame count. This will recalculate all other attributes, so use it with care.\n\n* `$frameCount`: `int` indicating the value to be setted.\n\n```php\n$tc = new Timecode('00:03:00:00');\n$tc-\u003esetFrameCount(360)-\u003etoString();\n// 00:00:15:00\n```\n\n### Static Methods\n\n#### `frameCountFromTimecode($time, $frameRate = null, $dropFrame = null)`\n\nReturns the frame count from a time.\n\n* `$time`: `String` time as string to calculate.\n* `$frameRate`: `float` frame rate to calculate the timecode.\n* `$dropFrame`: `bool` indicates if is drop frame.\n* `return`: `int` returns the frame count\n\n#### `fromSeconds($seconds, $frameRate = null, $dropFrame = null)`\n\nInstantiate a new object from seconds instead of timecode/framecount.\n\n* `$seconds`: `int` seconds to convert\n* `$frameRate`: `float` frame rate to calculate the timecode.\n* `$dropFrame`: `bool` indicates if is drop frame.\n* `return`: `Timecode` Returns the newly created object\n\n```php\n$tc = Timecode::fromSeconds(15);\n$tc-\u003etoString();\n// 00:00:15:00\n```\n\n#### `setDefaultFrameRate($frameRate)`\n\nChange default frame rate to instantiate objects with.\n\n* `$frameRate`: `float` New default frame rate.\n\n```php\n$tc = new Timecode();\n$tc-\u003egetFrameRate();\n// 24\n\nTimecode::setDefaultFrameRate(25);\n\n$tc2 = new Timecode();\n$tc2-\u003egetFrameRate();\n// 25\n```\n\n#### `setDefaultDropFrame($dropFrame)`\n\nChange default drop frame to instantiate objects with.\n\n* `$dropFrame`: `float` New default drop frame.\n\n```php\n$tc = new Timecode();\n$tc-\u003egetDropFrame();\n// false\n\nTimecode::setDefaultDropFrame(true);\n\n$tc2 = new Timecode();\n$tc2-\u003egetDropFrame();\n// true\n```\n\n## Contributing\nAll contribution is welcome, please feel free to open tickets and pull requests.\n\n## License\n\n[MIT.](LICENSE)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffireworkweb%2Fsmpte.php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffireworkweb%2Fsmpte.php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffireworkweb%2Fsmpte.php/lists"}