shortform-qc 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +86 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +93 -0
- package/dist/evaluate.d.ts +8 -0
- package/dist/evaluate.js +113 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +14 -0
- package/dist/licenses.d.ts +6 -0
- package/dist/licenses.js +14 -0
- package/dist/measure.d.ts +32 -0
- package/dist/measure.js +94 -0
- package/dist/safe-zones.d.ts +23 -0
- package/dist/safe-zones.js +41 -0
- package/dist/subtitles.d.ts +22 -0
- package/dist/subtitles.js +51 -0
- package/dist/targets.d.ts +7 -0
- package/dist/targets.js +19 -0
- package/dist/types.d.ts +111 -0
- package/dist/types.js +1 -0
- package/package.json +56 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,87 @@
|
|
|
1
|
-
#
|
|
1
|
+
# shortform-qc
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Pre-publish quality checks for short-form video (Shorts, Reels, TikTok). Point it at a rendered file
|
|
4
|
+
and it tells you, rule by rule, whether it's ready to publish and what to fix if it isn't.
|
|
5
|
+
|
|
6
|
+
```
|
|
7
|
+
$ npx shortform-qc final.mp4 --format 9:16 --duration 57 --srt final.srt --platform tiktok,youtube
|
|
8
|
+
PASS Integrated loudness: -14.1 (target -14 ± 1 LUFS)
|
|
9
|
+
FAIL True peak: -0.6 (target ≤ -1 dBTP)
|
|
10
|
+
PASS Rec.709, limited range: {...}
|
|
11
|
+
PASS Resolution: 1080x1920 (target 1080x1920)
|
|
12
|
+
PASS Frame rate: 30/1 (target 30 fps)
|
|
13
|
+
PASS Duration (video and audio): {"video":57,"audio":57.01} (target 57.000 s; ...)
|
|
14
|
+
PASS Frame count (dropped or extra): 1710 (target 1710 ± 2)
|
|
15
|
+
PASS Duplicated frames and freezes: {"ratio":0.03,"freezes":[]} (...)
|
|
16
|
+
FAIL Readable subtitles: {"worstCharsPerLine":48,...}
|
|
17
|
+
"this line is much too long for a phone screen" at 12.40 s: 1 lines, 48 chars/line, 15.2 chars/s
|
|
18
|
+
|
|
19
|
+
Not ready: fix the FAIL lines above.
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
It is the QC gate of [Geeper](https://github.com/saihdez/geeper), a local video studio, extracted so
|
|
23
|
+
any pipeline (ffmpeg scripts, Remotion, HyperFrames, MoneyPrinterTurbo, an editor export) can use it.
|
|
24
|
+
|
|
25
|
+
## What it checks
|
|
26
|
+
|
|
27
|
+
| Rule | Default target | Why |
|
|
28
|
+
|---|---|---|
|
|
29
|
+
| Integrated loudness | −14 ± 1 LUFS | What YouTube, TikTok and Instagram normalize to; quieter videos sound weak next to others |
|
|
30
|
+
| True peak | ≤ −1 dBTP | AAC encoding overshoots; above −1 dBTP it clips on phones |
|
|
31
|
+
| Color | Rec.709, limited (`tv`) range, yuv420p | Untagged files get guessed and look washed out or crushed |
|
|
32
|
+
| Resolution / frame rate | from `--format` / `--fps` | Catches a wrong export preset |
|
|
33
|
+
| Duration and A/V sync | expected ± 2 frames; audio within 0.15 s | Truncated renders and drifting audio |
|
|
34
|
+
| Frame count | expected ± 2 | Dropped or duplicated frames from a broken render |
|
|
35
|
+
| Duplicates and freezes | ≤ 10 % duplicated, no still ≥ 1 s | Stalled renders (stops at `--outro-start` so a static end card is fine) |
|
|
36
|
+
| Subtitles | ≤ 42 chars/line, ≤ 2 lines, ≤ 17 chars/s | Common broadcast caption limits; unreadable captions lose viewers |
|
|
37
|
+
| Safe zone | inside the platform UI-free area | Text under TikTok's buttons or the Shorts caption is invisible |
|
|
38
|
+
| Licenses | every asset allows commercial use | Warns by default; fails when the project is commercial |
|
|
39
|
+
|
|
40
|
+
Rules whose inputs you don't give are skipped, not guessed. Measurements use ffmpeg's `loudnorm`
|
|
41
|
+
(EBU R128), `ffprobe`, `freezedetect` and `mpdecimate`, on the CPU.
|
|
42
|
+
|
|
43
|
+
## Install
|
|
44
|
+
|
|
45
|
+
Needs Node 20+ and ffmpeg/ffprobe on `PATH` (or set `FFMPEG` / `FFPROBE`).
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm install shortform-qc # library
|
|
49
|
+
npx shortform-qc --help # CLI
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Exit codes: `0` ready (warnings allowed), `1` a rule failed, `2` usage error. Use `--json` in CI.
|
|
53
|
+
|
|
54
|
+
## Library
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { checkVideo, evaluate, measure, parseSrt } from "shortform-qc";
|
|
58
|
+
import { readFile } from "node:fs/promises";
|
|
59
|
+
|
|
60
|
+
const report = await checkVideo("final.mp4", {
|
|
61
|
+
format: "9:16",
|
|
62
|
+
duration: 57,
|
|
63
|
+
platforms: ["tiktok", "youtube"],
|
|
64
|
+
subtitles: parseSrt(await readFile("final.srt", "utf8")),
|
|
65
|
+
boxes: [{ name: "title", x: 130, y: 300, w: 700, h: 200 }],
|
|
66
|
+
assets: [{ name: "music.mp3", license: "CC-BY-4.0" }],
|
|
67
|
+
commercial: true,
|
|
68
|
+
outroStart: 54,
|
|
69
|
+
});
|
|
70
|
+
if (!report.passed) console.table(report.rules.filter((r) => !r.ok));
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
`measure()` and `evaluate()` are separate, so you can measure once and evaluate against several
|
|
74
|
+
targets, or evaluate numbers you got elsewhere without running ffmpeg. Override any default with
|
|
75
|
+
`targets`, e.g. `{ targets: { lufs: -16, maxCps: 20 } }`.
|
|
76
|
+
|
|
77
|
+
Helpers: `safeZone(format, platforms)`, `platformZone()`, `parseSrt()`, `reviewCues()`,
|
|
78
|
+
`commercialUse(licenseText)`.
|
|
79
|
+
|
|
80
|
+
## Credits
|
|
81
|
+
|
|
82
|
+
Platform UI margins for 9:16 adapted from [vincentsch/explainroo](https://github.com/vincentsch/explainroo)
|
|
83
|
+
(MIT).
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
Apache-2.0
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { parseArgs } from "node:util";
|
|
4
|
+
import { checkVideo } from "./index.js";
|
|
5
|
+
import { parseSrt } from "./subtitles.js";
|
|
6
|
+
const HELP = `Usage: shortform-qc <video> [options]
|
|
7
|
+
|
|
8
|
+
Checks a rendered short-form video before you publish it: loudness (-14 LUFS, true peak <= -1 dBTP),
|
|
9
|
+
Rec.709 color tags, resolution, frame rate, duration, dropped/duplicated/frozen frames and,
|
|
10
|
+
if you pass an .srt, subtitle line length and reading speed.
|
|
11
|
+
|
|
12
|
+
Options:
|
|
13
|
+
--format <9:16|16:9|1:1> expected canvas (sets the resolution check)
|
|
14
|
+
--fps <n> expected frame rate (default 30)
|
|
15
|
+
--duration <seconds> expected duration (enables duration and frame-count checks)
|
|
16
|
+
--srt <file> subtitles to check (max 42 chars/line, 2 lines, 17 chars/s)
|
|
17
|
+
--platform <list> comma-separated: tiktok,youtube,instagram,facebook
|
|
18
|
+
--outro-start <seconds> stop freeze/duplicate checks here (static end card)
|
|
19
|
+
--no-rec709 skip the color check
|
|
20
|
+
--json print the full report as JSON
|
|
21
|
+
-h, --help show this help
|
|
22
|
+
|
|
23
|
+
Exit code: 0 when every rule passes (warnings allowed), 1 when one fails, 2 on usage errors.
|
|
24
|
+
Uses ffmpeg/ffprobe from PATH, or the FFMPEG / FFPROBE environment variables.`;
|
|
25
|
+
const FORMATS = new Set(["9:16", "16:9", "1:1"]);
|
|
26
|
+
const PLATFORMS = new Set(["tiktok", "youtube", "instagram", "facebook"]);
|
|
27
|
+
function fail(msg) {
|
|
28
|
+
process.stderr.write(`shortform-qc: ${msg}\n`);
|
|
29
|
+
process.exit(2);
|
|
30
|
+
}
|
|
31
|
+
function num(v, name) {
|
|
32
|
+
if (v === undefined)
|
|
33
|
+
return undefined;
|
|
34
|
+
const n = Number(v);
|
|
35
|
+
if (!Number.isFinite(n) || n <= 0)
|
|
36
|
+
fail(`--${name} must be a positive number`);
|
|
37
|
+
return n;
|
|
38
|
+
}
|
|
39
|
+
function print(r) {
|
|
40
|
+
for (const rule of r.rules) {
|
|
41
|
+
const mark = rule.ok ? "PASS" : rule.warning ? "WARN" : "FAIL";
|
|
42
|
+
const measured = typeof rule.measured === "object" ? JSON.stringify(rule.measured) : String(rule.measured);
|
|
43
|
+
process.stdout.write(`${mark} ${rule.name}: ${measured} (target ${rule.target})\n`);
|
|
44
|
+
if (!rule.ok && rule.detail)
|
|
45
|
+
process.stdout.write(rule.detail.replace(/^/gm, " ") + "\n");
|
|
46
|
+
}
|
|
47
|
+
process.stdout.write(r.passed ? "\nReady to publish.\n" : "\nNot ready: fix the FAIL lines above.\n");
|
|
48
|
+
}
|
|
49
|
+
async function main() {
|
|
50
|
+
const { values, positionals } = parseArgs({
|
|
51
|
+
allowPositionals: true,
|
|
52
|
+
options: {
|
|
53
|
+
format: { type: "string" },
|
|
54
|
+
fps: { type: "string" },
|
|
55
|
+
duration: { type: "string" },
|
|
56
|
+
srt: { type: "string" },
|
|
57
|
+
platform: { type: "string" },
|
|
58
|
+
"outro-start": { type: "string" },
|
|
59
|
+
"no-rec709": { type: "boolean" },
|
|
60
|
+
json: { type: "boolean" },
|
|
61
|
+
help: { type: "boolean", short: "h" },
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
if (values.help) {
|
|
65
|
+
process.stdout.write(HELP + "\n");
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const file = positionals[0];
|
|
69
|
+
if (!file || positionals.length > 1)
|
|
70
|
+
fail("expected exactly one video file (see --help)");
|
|
71
|
+
if (values.format && !FORMATS.has(values.format))
|
|
72
|
+
fail(`unknown --format ${values.format}`);
|
|
73
|
+
const platforms = values.platform?.split(",").map((p) => p.trim()).filter(Boolean) ?? [];
|
|
74
|
+
for (const p of platforms)
|
|
75
|
+
if (!PLATFORMS.has(p))
|
|
76
|
+
fail(`unknown platform ${p}`);
|
|
77
|
+
const exp = {
|
|
78
|
+
format: values.format,
|
|
79
|
+
fps: num(values.fps, "fps"),
|
|
80
|
+
duration: num(values.duration, "duration"),
|
|
81
|
+
platforms: platforms,
|
|
82
|
+
outroStart: num(values["outro-start"], "outro-start"),
|
|
83
|
+
requireRec709: !values["no-rec709"],
|
|
84
|
+
subtitles: values.srt ? parseSrt(await readFile(values.srt, "utf8")) : undefined,
|
|
85
|
+
};
|
|
86
|
+
const report = await checkVideo(file, exp);
|
|
87
|
+
if (values.json)
|
|
88
|
+
process.stdout.write(JSON.stringify(report, null, 2) + "\n");
|
|
89
|
+
else
|
|
90
|
+
print(report);
|
|
91
|
+
process.exitCode = report.passed ? 0 : 1;
|
|
92
|
+
}
|
|
93
|
+
main().catch((e) => fail(e instanceof Error ? e.message : String(e)));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Expectations, Measurements, Report } from "./types.js";
|
|
2
|
+
/** "30/1" or "30000/1001" → frames per second. */
|
|
3
|
+
export declare function parseRate(rate: string): number;
|
|
4
|
+
/**
|
|
5
|
+
* Turns measurements into pass/fail rules. Pure: no ffmpeg, no file system. A rule whose inputs are
|
|
6
|
+
* missing (no expected duration, no subtitles, ...) is left out rather than guessed.
|
|
7
|
+
*/
|
|
8
|
+
export declare function evaluate(m: Measurements, exp?: Expectations, file?: string): Report;
|
package/dist/evaluate.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { commercialUse } from "./licenses.js";
|
|
2
|
+
import { CANVAS, inside, safeZone } from "./safe-zones.js";
|
|
3
|
+
import { describeProblem, reviewCues } from "./subtitles.js";
|
|
4
|
+
import { resolveTargets } from "./targets.js";
|
|
5
|
+
/** "30/1" or "30000/1001" → frames per second. */
|
|
6
|
+
export function parseRate(rate) {
|
|
7
|
+
const [n, d] = rate.split("/").map(Number);
|
|
8
|
+
return d ? n / d : Number(n);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Turns measurements into pass/fail rules. Pure: no ffmpeg, no file system. A rule whose inputs are
|
|
12
|
+
* missing (no expected duration, no subtitles, ...) is left out rather than guessed.
|
|
13
|
+
*/
|
|
14
|
+
export function evaluate(m, exp = {}, file = "") {
|
|
15
|
+
const t = resolveTargets(exp.targets);
|
|
16
|
+
const fps = exp.fps ?? 30;
|
|
17
|
+
const rules = [];
|
|
18
|
+
if (m.loudness) {
|
|
19
|
+
const { integrated, truePeak } = m.loudness;
|
|
20
|
+
rules.push({
|
|
21
|
+
id: "loudness", name: "Integrated loudness", ok: Math.abs(integrated - t.lufs) <= t.lufsTolerance,
|
|
22
|
+
measured: integrated, target: `${t.lufs} ± ${t.lufsTolerance} LUFS`,
|
|
23
|
+
});
|
|
24
|
+
rules.push({ id: "true-peak", name: "True peak", ok: truePeak <= t.maxTruePeak, measured: truePeak, target: `≤ ${t.maxTruePeak} dBTP` });
|
|
25
|
+
}
|
|
26
|
+
const v = m.video;
|
|
27
|
+
if (v) {
|
|
28
|
+
if (exp.requireRec709 !== false) {
|
|
29
|
+
const color = { colorSpace: v.colorSpace, colorTransfer: v.colorTransfer, colorPrimaries: v.colorPrimaries, colorRange: v.colorRange, pixFmt: v.pixFmt };
|
|
30
|
+
rules.push({
|
|
31
|
+
id: "color", name: "Rec.709, limited range",
|
|
32
|
+
ok: v.colorSpace === "bt709" && v.colorTransfer === "bt709" && v.colorPrimaries === "bt709" && v.colorRange === "tv" && v.pixFmt === "yuv420p",
|
|
33
|
+
measured: color, target: "bt709 / bt709 / bt709, tv, yuv420p",
|
|
34
|
+
detail: v.colorSpace ? undefined : "No color tags: players will guess. Encode with -colorspace bt709 -color_trc bt709 -color_primaries bt709 -color_range tv.",
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const w = exp.width ?? (exp.format && CANVAS[exp.format].width);
|
|
38
|
+
const h = exp.height ?? (exp.format && CANVAS[exp.format].height);
|
|
39
|
+
if (w && h) {
|
|
40
|
+
rules.push({ id: "resolution", name: "Resolution", ok: v.width === w && v.height === h, measured: `${v.width}x${v.height}`, target: `${w}x${h}` });
|
|
41
|
+
}
|
|
42
|
+
const rate = parseRate(v.frameRate);
|
|
43
|
+
rules.push({ id: "fps", name: "Frame rate", ok: Math.abs(rate - fps) < 0.01, measured: v.frameRate, target: `${fps} fps` });
|
|
44
|
+
if (exp.duration !== undefined) {
|
|
45
|
+
const audio = m.audioDuration ?? v.duration;
|
|
46
|
+
rules.push({
|
|
47
|
+
id: "duration", name: "Duration (video and audio)",
|
|
48
|
+
ok: Math.abs(v.duration - exp.duration) <= 2 / fps + 0.05 && Math.abs(audio - v.duration) <= t.avSyncTolerance,
|
|
49
|
+
measured: { video: Number(v.duration.toFixed(3)), audio: Number(audio.toFixed(3)) },
|
|
50
|
+
target: `${exp.duration.toFixed(3)} s; audio within ${t.avSyncTolerance} s of video`,
|
|
51
|
+
});
|
|
52
|
+
if (m.frameCount !== undefined) {
|
|
53
|
+
const expected = Math.round(exp.duration * fps);
|
|
54
|
+
rules.push({
|
|
55
|
+
id: "frames", name: "Frame count (dropped or extra)", ok: Math.abs(m.frameCount - expected) <= t.frameTolerance,
|
|
56
|
+
measured: m.frameCount, target: `${expected} ± ${t.frameTolerance}`,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (m.duplicateRatio !== undefined || m.freezes) {
|
|
62
|
+
const fromSource = exp.expectedDuplicates ?? 0;
|
|
63
|
+
const cap = Math.min(1, t.maxDuplicates + fromSource);
|
|
64
|
+
const ratio = m.duplicateRatio ?? 0;
|
|
65
|
+
const freezes = (m.freezes ?? []).filter((f) => f.duration >= t.maxFreeze);
|
|
66
|
+
rules.push({
|
|
67
|
+
id: "duplicates", name: "Duplicated frames and freezes", ok: ratio <= cap && freezes.length === 0,
|
|
68
|
+
measured: { ratio: Number(ratio.toFixed(3)), freezes, ...(fromSource ? { fromSource } : {}) },
|
|
69
|
+
target: `≤ ${Math.round(cap * 100)} % duplicated, no freeze ≥ ${t.maxFreeze} s`,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (exp.subtitles?.length) {
|
|
73
|
+
const r = reviewCues(exp.subtitles, t);
|
|
74
|
+
const warnOnly = exp.subtitleSpeedWarnOnly === true;
|
|
75
|
+
const failing = r.problems.filter((p) => p.shape || (p.speed && !warnOnly));
|
|
76
|
+
rules.push({
|
|
77
|
+
id: "subtitles", name: warnOnly ? "Readable subtitles (shape)" : "Readable subtitles",
|
|
78
|
+
ok: failing.length === 0,
|
|
79
|
+
measured: { worstCharsPerLine: r.worstLine, worstLines: r.worstLines, worstCps: r.worstCps, cues: r.cues },
|
|
80
|
+
target: `≤ ${t.maxCharsPerLine} chars/line, ≤ ${t.maxLines} lines${warnOnly ? "" : `, ≤ ${t.maxCps} chars/s`}`,
|
|
81
|
+
detail: failing.slice(0, 12).map(describeProblem).join("\n") || undefined,
|
|
82
|
+
});
|
|
83
|
+
if (warnOnly) {
|
|
84
|
+
const fast = r.problems.filter((p) => p.speed && !p.shape);
|
|
85
|
+
rules.push({
|
|
86
|
+
id: "subtitle-speed", name: "Subtitle reading speed", ok: fast.length === 0, warning: true,
|
|
87
|
+
measured: { worstCps: r.worstCps }, target: `≤ ${t.maxCps} chars/s`,
|
|
88
|
+
detail: fast.slice(0, 12).map(describeProblem).join("\n") || undefined,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (exp.boxes?.length && exp.format) {
|
|
93
|
+
const zone = safeZone(exp.format, exp.platforms);
|
|
94
|
+
const out = exp.boxes.filter((b) => !inside(b, zone));
|
|
95
|
+
rules.push({
|
|
96
|
+
id: "safe-zone", name: "Text and logos inside the safe zone", ok: out.length === 0,
|
|
97
|
+
measured: exp.boxes.map((b) => ({ name: b.name, inside: inside(b, zone) })),
|
|
98
|
+
target: `x ${zone.x}–${zone.x + zone.w}, y ${zone.y}–${zone.y + zone.h} px`,
|
|
99
|
+
detail: out.map((b) => b.name).join(", ") || undefined,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (exp.assets?.length) {
|
|
103
|
+
const classified = exp.assets.map((a) => ({ ...a, commercial: commercialUse(a.license) }));
|
|
104
|
+
const bad = classified.filter((a) => a.commercial !== "yes");
|
|
105
|
+
rules.push({
|
|
106
|
+
id: "licenses", name: exp.commercial ? "Asset licenses (commercial use)" : "Asset licenses",
|
|
107
|
+
ok: bad.length === 0, warning: !exp.commercial, measured: classified,
|
|
108
|
+
target: "every asset allows commercial use",
|
|
109
|
+
detail: bad.map((a) => `${a.name}: ${a.license} (${a.commercial === "no" ? "non-commercial" : "unconfirmed"})`).join("\n") || undefined,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return { passed: rules.every((r) => r.ok || r.warning), file, measuredAt: new Date().toISOString(), rules };
|
|
113
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Tools } from "./measure.js";
|
|
2
|
+
import type { Expectations, Report } from "./types.js";
|
|
3
|
+
export * from "./types.js";
|
|
4
|
+
export { DEFAULT_TARGETS, resolveTargets } from "./targets.js";
|
|
5
|
+
export { CANVAS, PLATFORM_UI_9X16, inside, intersect, platformZone, safeZone } from "./safe-zones.js";
|
|
6
|
+
export { charCount, parseSrt, reviewCues } from "./subtitles.js";
|
|
7
|
+
export { commercialUse, type CommercialUse } from "./licenses.js";
|
|
8
|
+
export { evaluate, parseRate } from "./evaluate.js";
|
|
9
|
+
export { countFrames, detectFreezes, duplicateRatio, measure, measureLoudness, parseFreezes, probe, type MeasureOptions, type Tools } from "./measure.js";
|
|
10
|
+
/** Measures a rendered video with ffmpeg and checks it against the expectations. */
|
|
11
|
+
export declare function checkVideo(file: string, expectations?: Expectations, tools?: Tools): Promise<Report>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { evaluate } from "./evaluate.js";
|
|
2
|
+
import { measure } from "./measure.js";
|
|
3
|
+
export * from "./types.js";
|
|
4
|
+
export { DEFAULT_TARGETS, resolveTargets } from "./targets.js";
|
|
5
|
+
export { CANVAS, PLATFORM_UI_9X16, inside, intersect, platformZone, safeZone } from "./safe-zones.js";
|
|
6
|
+
export { charCount, parseSrt, reviewCues } from "./subtitles.js";
|
|
7
|
+
export { commercialUse } from "./licenses.js";
|
|
8
|
+
export { evaluate, parseRate } from "./evaluate.js";
|
|
9
|
+
export { countFrames, detectFreezes, duplicateRatio, measure, measureLoudness, parseFreezes, probe } from "./measure.js";
|
|
10
|
+
/** Measures a rendered video with ffmpeg and checks it against the expectations. */
|
|
11
|
+
export async function checkVideo(file, expectations = {}, tools = {}) {
|
|
12
|
+
const m = await measure(file, { ...tools, fps: expectations.fps, outroStart: expectations.outroStart });
|
|
13
|
+
return evaluate(m, expectations, file);
|
|
14
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type CommercialUse = "yes" | "no" | "unknown";
|
|
2
|
+
/**
|
|
3
|
+
* Whether a free-text license string allows commercial use. Anything it doesn't recognize is
|
|
4
|
+
* "unknown". OpenRAIL counts as commercial (with use restrictions). Understands English and Spanish.
|
|
5
|
+
*/
|
|
6
|
+
export declare function commercialUse(license: string): CommercialUse;
|
package/dist/licenses.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a free-text license string allows commercial use. Anything it doesn't recognize is
|
|
3
|
+
* "unknown". OpenRAIL counts as commercial (with use restrictions). Understands English and Spanish.
|
|
4
|
+
*/
|
|
5
|
+
export function commercialUse(license) {
|
|
6
|
+
const l = license.toLowerCase();
|
|
7
|
+
if (/desconocid|revisar|unknown|\?/.test(l))
|
|
8
|
+
return "unknown";
|
|
9
|
+
if (/\bnc\b|-nc\b|non-?commercial|no comercial|no-comercial|sólo editorial|solo editorial|editorial only|research only|sólo investigación|cpml/.test(l))
|
|
10
|
+
return "no";
|
|
11
|
+
if (/apache|\bmit\b|cc0|public domain|dominio público|\bbsd\b|openrail|\bcc-by\b|cc by|propia|own work|permiso del creador|creator permission|youtube audio library|biblioteca de audio de youtube|pixabay|pexels/.test(l))
|
|
12
|
+
return "yes";
|
|
13
|
+
return "unknown";
|
|
14
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Measurements } from "./types.js";
|
|
2
|
+
export interface Tools {
|
|
3
|
+
/** Defaults to `ffmpeg` / `ffprobe` on PATH, or the FFMPEG / FFPROBE environment variables. */
|
|
4
|
+
ffmpeg?: string;
|
|
5
|
+
ffprobe?: string;
|
|
6
|
+
}
|
|
7
|
+
/** First pass of ffmpeg's loudnorm (EBU R128): integrated loudness, true peak and loudness range. */
|
|
8
|
+
export declare function measureLoudness(file: string, t?: Tools): Promise<NonNullable<Measurements["loudness"]>>;
|
|
9
|
+
export declare function probe(file: string, t?: Tools): Promise<Pick<Measurements, "video" | "audioDuration">>;
|
|
10
|
+
export declare function countFrames(file: string, t?: Tools): Promise<number>;
|
|
11
|
+
/** Stills of at least 0.5 s (ffmpeg freezedetect), up to `until` seconds. */
|
|
12
|
+
export declare function detectFreezes(file: string, until?: number, t?: Tools): Promise<{
|
|
13
|
+
start: number;
|
|
14
|
+
duration: number;
|
|
15
|
+
}[]>;
|
|
16
|
+
/**
|
|
17
|
+
* Pairs freezedetect's `freeze_start` / `freeze_duration` lines. A freeze that lasts until the end
|
|
18
|
+
* has no duration line: it runs to `end` (or is reported with duration 0 when `end` is unknown).
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseFreezes(stderr: string, end?: number): {
|
|
21
|
+
start: number;
|
|
22
|
+
duration: number;
|
|
23
|
+
}[];
|
|
24
|
+
/** Share of frames ffmpeg's mpdecimate drops as near-duplicates, up to `until` seconds. */
|
|
25
|
+
export declare function duplicateRatio(file: string, fps: number, until: number, t?: Tools): Promise<number>;
|
|
26
|
+
export interface MeasureOptions extends Tools {
|
|
27
|
+
fps?: number;
|
|
28
|
+
/** Freeze and duplicate analysis stop here. Default: the whole video. */
|
|
29
|
+
outroStart?: number;
|
|
30
|
+
}
|
|
31
|
+
/** Runs every measurement. Needs ffmpeg and ffprobe; CPU only. */
|
|
32
|
+
export declare function measure(file: string, o?: MeasureOptions): Promise<Measurements>;
|
package/dist/measure.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
const run = promisify(execFile);
|
|
4
|
+
function tools(t = {}) {
|
|
5
|
+
return { ffmpeg: t.ffmpeg ?? process.env.FFMPEG ?? "ffmpeg", ffprobe: t.ffprobe ?? process.env.FFPROBE ?? "ffprobe" };
|
|
6
|
+
}
|
|
7
|
+
async function stderrOf(bin, args) {
|
|
8
|
+
const r = await run(bin, args, { maxBuffer: 64 * 1024 * 1024 });
|
|
9
|
+
return r.stderr;
|
|
10
|
+
}
|
|
11
|
+
/** First pass of ffmpeg's loudnorm (EBU R128): integrated loudness, true peak and loudness range. */
|
|
12
|
+
export async function measureLoudness(file, t) {
|
|
13
|
+
const err = await stderrOf(tools(t).ffmpeg, [
|
|
14
|
+
"-hide_banner", "-nostdin", "-i", file, "-vn", "-af", "loudnorm=I=-14:TP=-1:LRA=11:print_format=json", "-f", "null", "-",
|
|
15
|
+
]);
|
|
16
|
+
const json = /\{[\s\S]*?"target_offset"[\s\S]*?\}/.exec(err)?.[0];
|
|
17
|
+
if (!json)
|
|
18
|
+
throw new Error("loudnorm returned no measurements (does the file have audio?)");
|
|
19
|
+
const j = JSON.parse(json);
|
|
20
|
+
return { integrated: Number(j.input_i), truePeak: Number(j.input_tp), lra: Number(j.input_lra) };
|
|
21
|
+
}
|
|
22
|
+
export async function probe(file, t) {
|
|
23
|
+
const r = await run(tools(t).ffprobe, ["-v", "error", "-show_streams", "-show_format", "-of", "json", file], { maxBuffer: 16 * 1024 * 1024 });
|
|
24
|
+
const j = JSON.parse(r.stdout);
|
|
25
|
+
const v = j.streams?.find((s) => s.codec_type === "video");
|
|
26
|
+
const a = j.streams?.find((s) => s.codec_type === "audio");
|
|
27
|
+
const fallback = Number(j.format?.duration ?? 0);
|
|
28
|
+
return {
|
|
29
|
+
video: v && {
|
|
30
|
+
width: v.width ?? 0,
|
|
31
|
+
height: v.height ?? 0,
|
|
32
|
+
frameRate: v.r_frame_rate ?? "0/1",
|
|
33
|
+
duration: Number(v.duration ?? fallback),
|
|
34
|
+
colorSpace: v.color_space,
|
|
35
|
+
colorTransfer: v.color_transfer,
|
|
36
|
+
colorPrimaries: v.color_primaries,
|
|
37
|
+
colorRange: v.color_range,
|
|
38
|
+
pixFmt: v.pix_fmt,
|
|
39
|
+
},
|
|
40
|
+
audioDuration: a ? Number(a.duration ?? fallback) : undefined,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export async function countFrames(file, t) {
|
|
44
|
+
const r = await run(tools(t).ffprobe, ["-v", "error", "-count_packets", "-select_streams", "v:0", "-show_entries", "stream=nb_read_packets", "-of", "csv=p=0", file]);
|
|
45
|
+
return Number(r.stdout.trim());
|
|
46
|
+
}
|
|
47
|
+
/** Stills of at least 0.5 s (ffmpeg freezedetect), up to `until` seconds. */
|
|
48
|
+
export async function detectFreezes(file, until, t) {
|
|
49
|
+
const err = await stderrOf(tools(t).ffmpeg, [
|
|
50
|
+
"-hide_banner", "-nostdin", ...(until ? ["-t", until.toFixed(3)] : []), "-i", file, "-an",
|
|
51
|
+
"-vf", "freezedetect=n=-60dB:d=0.5", "-f", "null", "-",
|
|
52
|
+
]);
|
|
53
|
+
return parseFreezes(err, until);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Pairs freezedetect's `freeze_start` / `freeze_duration` lines. A freeze that lasts until the end
|
|
57
|
+
* has no duration line: it runs to `end` (or is reported with duration 0 when `end` is unknown).
|
|
58
|
+
*/
|
|
59
|
+
export function parseFreezes(stderr, end) {
|
|
60
|
+
const out = [];
|
|
61
|
+
let open = null;
|
|
62
|
+
for (const m of stderr.matchAll(/freeze_(start|duration): ([\d.]+)/g)) {
|
|
63
|
+
if (m[1] === "start")
|
|
64
|
+
open = Number(m[2]);
|
|
65
|
+
else if (open !== null) {
|
|
66
|
+
out.push({ start: open, duration: Number(m[2]) });
|
|
67
|
+
open = null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (open !== null)
|
|
71
|
+
out.push({ start: open, duration: end !== undefined ? Math.max(0, end - open) : 0 });
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
/** Share of frames ffmpeg's mpdecimate drops as near-duplicates, up to `until` seconds. */
|
|
75
|
+
export async function duplicateRatio(file, fps, until, t) {
|
|
76
|
+
const err = await stderrOf(tools(t).ffmpeg, [
|
|
77
|
+
"-hide_banner", "-nostdin", "-t", until.toFixed(3), "-i", file, "-an", "-vf", "mpdecimate", "-fps_mode", "vfr", "-f", "null", "-",
|
|
78
|
+
]);
|
|
79
|
+
const kept = Number([...err.matchAll(/frame=\s*(\d+)/g)].pop()?.[1] ?? 0);
|
|
80
|
+
const total = Math.round(until * fps);
|
|
81
|
+
return total ? Math.max(0, 1 - kept / total) : 0;
|
|
82
|
+
}
|
|
83
|
+
/** Runs every measurement. Needs ffmpeg and ffprobe; CPU only. */
|
|
84
|
+
export async function measure(file, o = {}) {
|
|
85
|
+
const [p, loudness, frameCount] = await Promise.all([probe(file, o), measureLoudness(file, o).catch(() => undefined), countFrames(file, o)]);
|
|
86
|
+
const until = Math.min(o.outroStart ?? Infinity, p.video?.duration ?? 0);
|
|
87
|
+
// Duplicates are counted against the file's own rate; a wrong rate is the fps rule's job.
|
|
88
|
+
const [n, d] = (p.video?.frameRate ?? "").split("/").map(Number);
|
|
89
|
+
const rate = n && d ? n / d : (o.fps ?? 30);
|
|
90
|
+
const [freezes, dup] = until > 0
|
|
91
|
+
? await Promise.all([detectFreezes(file, until, o), duplicateRatio(file, rate, until, o)])
|
|
92
|
+
: [[], 0];
|
|
93
|
+
return { ...p, loudness, frameCount, freezes, duplicateRatio: dup };
|
|
94
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Box, Format, Platform } from "./types.js";
|
|
2
|
+
export declare const CANVAS: Record<Format, {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
safe: Box;
|
|
6
|
+
}>;
|
|
7
|
+
/**
|
|
8
|
+
* Share of a 9:16 frame each platform's UI covers (top, right, bottom, left). Adapted from
|
|
9
|
+
* vincentsch/explainroo `src/project.js` (MIT). Facebook Reels uses the Instagram Reels layout.
|
|
10
|
+
*/
|
|
11
|
+
export declare const PLATFORM_UI_9X16: Record<Platform, {
|
|
12
|
+
top: number;
|
|
13
|
+
right: number;
|
|
14
|
+
bottom: number;
|
|
15
|
+
left: number;
|
|
16
|
+
}>;
|
|
17
|
+
export declare function intersect(a: Box, b: Box): Box;
|
|
18
|
+
/** Area a platform's UI leaves visible in a 9:16 frame, in pixels. */
|
|
19
|
+
export declare function platformZone(platform: Platform, width?: number, height?: number): Box;
|
|
20
|
+
/** Safe zone for a format; in 9:16 it is the intersection with what every target platform leaves visible. */
|
|
21
|
+
export declare function safeZone(format: Format, platforms?: readonly Platform[]): Box;
|
|
22
|
+
/** Half-pixel tolerance for layouts computed with fractional coordinates. */
|
|
23
|
+
export declare function inside(box: Box, zone: Box): boolean;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export const CANVAS = {
|
|
2
|
+
// Shorts/Reels/TikTok: keep text between the top bar and the caption/buttons area.
|
|
3
|
+
"9:16": { width: 1080, height: 1920, safe: { x: 60, y: 168, w: 960, h: 1162 } },
|
|
4
|
+
// 16:9: the classic 90 % title-safe area.
|
|
5
|
+
"16:9": { width: 1920, height: 1080, safe: { x: 96, y: 54, w: 1728, h: 972 } },
|
|
6
|
+
"1:1": { width: 1080, height: 1080, safe: { x: 54, y: 54, w: 972, h: 972 } },
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Share of a 9:16 frame each platform's UI covers (top, right, bottom, left). Adapted from
|
|
10
|
+
* vincentsch/explainroo `src/project.js` (MIT). Facebook Reels uses the Instagram Reels layout.
|
|
11
|
+
*/
|
|
12
|
+
export const PLATFORM_UI_9X16 = {
|
|
13
|
+
tiktok: { top: 0.125, right: 0.2, bottom: 0.34, left: 0.11 },
|
|
14
|
+
youtube: { top: 0.15, right: 0.12, bottom: 0.35, left: 0.06 },
|
|
15
|
+
instagram: { top: 0.14, right: 0.11, bottom: 0.35, left: 0.06 },
|
|
16
|
+
facebook: { top: 0.14, right: 0.11, bottom: 0.35, left: 0.06 },
|
|
17
|
+
};
|
|
18
|
+
export function intersect(a, b) {
|
|
19
|
+
const x = Math.max(a.x, b.x);
|
|
20
|
+
const y = Math.max(a.y, b.y);
|
|
21
|
+
return { x, y, w: Math.max(0, Math.min(a.x + a.w, b.x + b.w) - x), h: Math.max(0, Math.min(a.y + a.h, b.y + b.h) - y) };
|
|
22
|
+
}
|
|
23
|
+
/** Area a platform's UI leaves visible in a 9:16 frame, in pixels. */
|
|
24
|
+
export function platformZone(platform, width = 1080, height = 1920) {
|
|
25
|
+
const z = PLATFORM_UI_9X16[platform];
|
|
26
|
+
return { x: z.left * width, y: z.top * height, w: width * (1 - z.left - z.right), h: height * (1 - z.top - z.bottom) };
|
|
27
|
+
}
|
|
28
|
+
/** Safe zone for a format; in 9:16 it is the intersection with what every target platform leaves visible. */
|
|
29
|
+
export function safeZone(format, platforms = []) {
|
|
30
|
+
const c = CANVAS[format];
|
|
31
|
+
if (format !== "9:16" || platforms.length === 0)
|
|
32
|
+
return c.safe;
|
|
33
|
+
let s = c.safe;
|
|
34
|
+
for (const p of platforms)
|
|
35
|
+
s = intersect(s, platformZone(p, c.width, c.height));
|
|
36
|
+
return { x: Math.round(s.x), y: Math.round(s.y), w: Math.floor(s.w), h: Math.floor(s.h) };
|
|
37
|
+
}
|
|
38
|
+
/** Half-pixel tolerance for layouts computed with fractional coordinates. */
|
|
39
|
+
export function inside(box, zone) {
|
|
40
|
+
return box.x >= zone.x - 0.5 && box.y >= zone.y - 0.5 && box.x + box.w <= zone.x + zone.w + 0.5 && box.y + box.h <= zone.y + zone.h + 0.5;
|
|
41
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Cue, Targets } from "./types.js";
|
|
2
|
+
/** Parses SRT (or WebVTT cue blocks). Cues keep their line breaks. */
|
|
3
|
+
export declare function parseSrt(text: string): Cue[];
|
|
4
|
+
/** Counts code points, so accented letters and emoji count as one character. */
|
|
5
|
+
export declare function charCount(s: string): number;
|
|
6
|
+
export interface CueProblem {
|
|
7
|
+
cue: Cue;
|
|
8
|
+
lines: number;
|
|
9
|
+
longestLine: number;
|
|
10
|
+
cps: number;
|
|
11
|
+
/** Too many lines or a line too long (as opposed to only too fast). */
|
|
12
|
+
shape: boolean;
|
|
13
|
+
speed: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function reviewCues(cues: readonly Cue[], t: Targets): {
|
|
16
|
+
worstLine: number;
|
|
17
|
+
worstLines: number;
|
|
18
|
+
worstCps: number;
|
|
19
|
+
problems: CueProblem[];
|
|
20
|
+
cues: number;
|
|
21
|
+
};
|
|
22
|
+
export declare function describeProblem(p: CueProblem): string;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const TIME = /(\d+):(\d{2}):(\d{2})[,.](\d{1,3})/;
|
|
2
|
+
function seconds(t) {
|
|
3
|
+
const m = TIME.exec(t);
|
|
4
|
+
if (!m)
|
|
5
|
+
throw new Error(`invalid SRT timestamp: ${t}`);
|
|
6
|
+
return Number(m[1]) * 3600 + Number(m[2]) * 60 + Number(m[3]) + Number(m[4].padEnd(3, "0")) / 1000;
|
|
7
|
+
}
|
|
8
|
+
/** Parses SRT (or WebVTT cue blocks). Cues keep their line breaks. */
|
|
9
|
+
export function parseSrt(text) {
|
|
10
|
+
const cues = [];
|
|
11
|
+
for (const block of text.replace(/^/, "").replace(/\r\n?/g, "\n").split(/\n{2,}/)) {
|
|
12
|
+
const lines = block.split("\n");
|
|
13
|
+
const i = lines.findIndex((l) => l.includes("-->"));
|
|
14
|
+
if (i < 0)
|
|
15
|
+
continue;
|
|
16
|
+
const [a, b] = lines[i].split("-->");
|
|
17
|
+
const body = lines.slice(i + 1).join("\n").trim();
|
|
18
|
+
if (!body)
|
|
19
|
+
continue;
|
|
20
|
+
cues.push({ start: seconds(a.trim()), end: seconds(b.trim().split(/\s+/)[0]), text: body });
|
|
21
|
+
}
|
|
22
|
+
return cues;
|
|
23
|
+
}
|
|
24
|
+
/** Counts code points, so accented letters and emoji count as one character. */
|
|
25
|
+
export function charCount(s) {
|
|
26
|
+
return [...s].length;
|
|
27
|
+
}
|
|
28
|
+
export function reviewCues(cues, t) {
|
|
29
|
+
let worstLine = 0;
|
|
30
|
+
let worstLines = 0;
|
|
31
|
+
let worstCps = 0;
|
|
32
|
+
const problems = [];
|
|
33
|
+
for (const cue of cues) {
|
|
34
|
+
const lines = cue.text.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
35
|
+
const longestLine = Math.max(0, ...lines.map(charCount));
|
|
36
|
+
const dur = cue.end - cue.start;
|
|
37
|
+
const cps = dur > 0 ? charCount(lines.join(" ")) / dur : Infinity;
|
|
38
|
+
worstLine = Math.max(worstLine, longestLine);
|
|
39
|
+
worstLines = Math.max(worstLines, lines.length);
|
|
40
|
+
worstCps = Math.max(worstCps, cps);
|
|
41
|
+
const shape = longestLine > t.maxCharsPerLine || lines.length > t.maxLines;
|
|
42
|
+
const speed = cps > t.maxCps;
|
|
43
|
+
if (shape || speed)
|
|
44
|
+
problems.push({ cue, lines: lines.length, longestLine, cps, shape, speed });
|
|
45
|
+
}
|
|
46
|
+
return { worstLine, worstLines, worstCps: Number(worstCps.toFixed(2)), problems, cues: cues.length };
|
|
47
|
+
}
|
|
48
|
+
export function describeProblem(p) {
|
|
49
|
+
const text = p.cue.text.replace(/\n/g, " / ");
|
|
50
|
+
return `"${text}" at ${p.cue.start.toFixed(2)} s: ${p.lines} lines, ${p.longestLine} chars/line, ${p.cps.toFixed(1)} chars/s`;
|
|
51
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Targets } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Defaults for short-form delivery: −14 LUFS / −1 dBTP (what YouTube, TikTok and Instagram normalize
|
|
4
|
+
* to), and the common broadcast caption limits of 42 characters per line, 2 lines, 17 characters/s.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_TARGETS: Targets;
|
|
7
|
+
export declare function resolveTargets(t?: Partial<Targets>): Targets;
|
package/dist/targets.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defaults for short-form delivery: −14 LUFS / −1 dBTP (what YouTube, TikTok and Instagram normalize
|
|
3
|
+
* to), and the common broadcast caption limits of 42 characters per line, 2 lines, 17 characters/s.
|
|
4
|
+
*/
|
|
5
|
+
export const DEFAULT_TARGETS = {
|
|
6
|
+
lufs: -14,
|
|
7
|
+
lufsTolerance: 1,
|
|
8
|
+
maxTruePeak: -1,
|
|
9
|
+
maxCharsPerLine: 42,
|
|
10
|
+
maxLines: 2,
|
|
11
|
+
maxCps: 17,
|
|
12
|
+
maxFreeze: 1,
|
|
13
|
+
maxDuplicates: 0.1,
|
|
14
|
+
frameTolerance: 2,
|
|
15
|
+
avSyncTolerance: 0.15,
|
|
16
|
+
};
|
|
17
|
+
export function resolveTargets(t) {
|
|
18
|
+
return { ...DEFAULT_TARGETS, ...t };
|
|
19
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
export type Format = "9:16" | "16:9" | "1:1";
|
|
2
|
+
export type Platform = "tiktok" | "youtube" | "instagram" | "facebook";
|
|
3
|
+
export interface Box {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
w: number;
|
|
7
|
+
h: number;
|
|
8
|
+
}
|
|
9
|
+
/** A named element drawn on screen (title, logo, caption block) to check against the safe zone. */
|
|
10
|
+
export interface NamedBox extends Box {
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
export interface Cue {
|
|
14
|
+
start: number;
|
|
15
|
+
end: number;
|
|
16
|
+
/** Text as displayed; `\n` separates lines. */
|
|
17
|
+
text: string;
|
|
18
|
+
}
|
|
19
|
+
export interface Asset {
|
|
20
|
+
name: string;
|
|
21
|
+
license: string;
|
|
22
|
+
}
|
|
23
|
+
export interface Rule {
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
ok: boolean;
|
|
27
|
+
/** Warnings never fail the report. */
|
|
28
|
+
warning?: boolean;
|
|
29
|
+
measured: unknown;
|
|
30
|
+
target: string;
|
|
31
|
+
detail?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface Report {
|
|
34
|
+
passed: boolean;
|
|
35
|
+
file: string;
|
|
36
|
+
measuredAt: string;
|
|
37
|
+
rules: Rule[];
|
|
38
|
+
}
|
|
39
|
+
export interface Targets {
|
|
40
|
+
/** Integrated loudness (LUFS). */
|
|
41
|
+
lufs: number;
|
|
42
|
+
lufsTolerance: number;
|
|
43
|
+
/** Maximum true peak (dBTP). */
|
|
44
|
+
maxTruePeak: number;
|
|
45
|
+
maxCharsPerLine: number;
|
|
46
|
+
maxLines: number;
|
|
47
|
+
/** Maximum reading speed (characters per second). */
|
|
48
|
+
maxCps: number;
|
|
49
|
+
/** Longest freeze allowed before the outro (seconds). */
|
|
50
|
+
maxFreeze: number;
|
|
51
|
+
/** Share of duplicated frames allowed before the outro (0–1). */
|
|
52
|
+
maxDuplicates: number;
|
|
53
|
+
/** Frames the file may be off by. */
|
|
54
|
+
frameTolerance: number;
|
|
55
|
+
/** Seconds the audio track may differ from the video track. */
|
|
56
|
+
avSyncTolerance: number;
|
|
57
|
+
}
|
|
58
|
+
export interface Expectations {
|
|
59
|
+
/** Sets the canvas size and the base safe zone. */
|
|
60
|
+
format?: Format;
|
|
61
|
+
/** Overrides the canvas size from `format`. */
|
|
62
|
+
width?: number;
|
|
63
|
+
height?: number;
|
|
64
|
+
/** Expected frame rate (default 30). */
|
|
65
|
+
fps?: number;
|
|
66
|
+
/** Expected duration (s). Duration and frame-count rules are skipped without it. */
|
|
67
|
+
duration?: number;
|
|
68
|
+
/** In 9:16, the safe zone is narrowed to what each platform's UI leaves visible. */
|
|
69
|
+
platforms?: readonly Platform[];
|
|
70
|
+
subtitles?: readonly Cue[];
|
|
71
|
+
/** When the creator's voice can't be slowed down: reading speed only warns. */
|
|
72
|
+
subtitleSpeedWarnOnly?: boolean;
|
|
73
|
+
boxes?: readonly NamedBox[];
|
|
74
|
+
assets?: readonly Asset[];
|
|
75
|
+
/** Commercial use: unknown or non-commercial licenses fail instead of warn. */
|
|
76
|
+
commercial?: boolean;
|
|
77
|
+
/** Freeze and duplicate checks stop here (an end card is static on purpose). Default: whole file. */
|
|
78
|
+
outroStart?: number;
|
|
79
|
+
/** Duplicate share the source already has (low-fps clips, stills); added to `maxDuplicates`. */
|
|
80
|
+
expectedDuplicates?: number;
|
|
81
|
+
/** Rec.709 limited range, yuv420p (default true). */
|
|
82
|
+
requireRec709?: boolean;
|
|
83
|
+
targets?: Partial<Targets>;
|
|
84
|
+
}
|
|
85
|
+
export interface Measurements {
|
|
86
|
+
loudness?: {
|
|
87
|
+
integrated: number;
|
|
88
|
+
truePeak: number;
|
|
89
|
+
lra: number;
|
|
90
|
+
};
|
|
91
|
+
video?: {
|
|
92
|
+
width: number;
|
|
93
|
+
height: number;
|
|
94
|
+
/** As reported by ffprobe, e.g. "30/1" or "30000/1001". */
|
|
95
|
+
frameRate: string;
|
|
96
|
+
duration: number;
|
|
97
|
+
colorSpace?: string;
|
|
98
|
+
colorTransfer?: string;
|
|
99
|
+
colorPrimaries?: string;
|
|
100
|
+
colorRange?: string;
|
|
101
|
+
pixFmt?: string;
|
|
102
|
+
};
|
|
103
|
+
audioDuration?: number;
|
|
104
|
+
frameCount?: number;
|
|
105
|
+
freezes?: {
|
|
106
|
+
start: number;
|
|
107
|
+
duration: number;
|
|
108
|
+
}[];
|
|
109
|
+
/** Share of frames `mpdecimate` drops as duplicates (0–1). */
|
|
110
|
+
duplicateRatio?: number;
|
|
111
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shortform-qc",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Pre-publish quality checks for short-form video: loudness (-14 LUFS / -1 dBTP), Rec.709, frame integrity, subtitle readability, platform safe zones and asset licenses.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"shortform-qc": "./dist/cli.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=20"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc -p tsconfig.build.json",
|
|
28
|
+
"test": "vitest run --root .",
|
|
29
|
+
"prepublishOnly": "npm run build && npm test"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"video",
|
|
33
|
+
"qc",
|
|
34
|
+
"quality-control",
|
|
35
|
+
"ffmpeg",
|
|
36
|
+
"loudness",
|
|
37
|
+
"lufs",
|
|
38
|
+
"ebu-r128",
|
|
39
|
+
"subtitles",
|
|
40
|
+
"srt",
|
|
41
|
+
"safe-zone",
|
|
42
|
+
"shorts",
|
|
43
|
+
"tiktok",
|
|
44
|
+
"reels"
|
|
45
|
+
],
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "git+https://github.com/saihdez/geeper.git",
|
|
49
|
+
"directory": "packages/shortform-qc"
|
|
50
|
+
},
|
|
51
|
+
"bugs": "https://github.com/saihdez/geeper/issues",
|
|
52
|
+
"homepage": "https://github.com/saihdez/geeper/tree/main/packages/shortform-qc#readme",
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@types/node": "^24.0.0",
|
|
55
|
+
"typescript": "^5.9.0",
|
|
56
|
+
"vitest": "^4.0.0"
|
|
57
|
+
}
|
|
58
|
+
}
|