remotion-ffmpeg-skill 0.14.2 → 0.14.3
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/package.json +1 -1
- package/scripts/_common.py +54 -0
- package/scripts/analyze.py +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "remotion-ffmpeg-skill",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.3",
|
|
4
4
|
"description": "Agent Skill: ffmpeg-skill measures the footage, Remotion draws the motion graphics from those measurements, ffmpeg-skill checks and delivers the result. Timeline-driven captions, silence jump cuts and audio-peak motion with probe-first / verify-last rendering. Local, no API keys.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"remotion",
|
package/scripts/_common.py
CHANGED
|
@@ -23,6 +23,7 @@ import shutil
|
|
|
23
23
|
import subprocess
|
|
24
24
|
import sys
|
|
25
25
|
import time
|
|
26
|
+
from fractions import Fraction
|
|
26
27
|
from pathlib import Path
|
|
27
28
|
from typing import Any, Dict, List, Optional, Sequence, Tuple
|
|
28
29
|
|
|
@@ -267,6 +268,59 @@ def _finite(v: Any) -> bool:
|
|
|
267
268
|
return isinstance(v, (int, float)) and not isinstance(v, bool) and math.isfinite(v)
|
|
268
269
|
|
|
269
270
|
|
|
271
|
+
# velisa/timebase@1 (Velisa ADR-026; docs/adr/0004): a frame rate is an exact fraction. A decimal that is not an
|
|
272
|
+
# integer and lies within 0.005 of base x 1000/1001 (base 24, 30, 48, 60, 120, 240) is that NTSC rate.
|
|
273
|
+
NTSC_BASES = (24, 30, 48, 60, 120, 240)
|
|
274
|
+
_DECIMAL_RE = re.compile(r"^\+?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$")
|
|
275
|
+
_RATIONAL_RE = re.compile(r"^\s*(\d+)\s*/\s*(\d+)\s*$")
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def exact_rate(value: Any) -> Optional[Fraction]:
|
|
279
|
+
"""A frame rate as an exact fraction, or None when it is not one in (0, 1000] (rule TB-2): 'N/D' as written
|
|
280
|
+
(ffprobe's r_frame_rate; '2997/100' stays), an integer as N/1, an NTSC decimal (29.97, 23.976, 59.94) as N/1001,
|
|
281
|
+
never as 2997/100, any other decimal as its exact value; a float through its shortest text."""
|
|
282
|
+
if isinstance(value, bool) or value is None:
|
|
283
|
+
return None
|
|
284
|
+
if isinstance(value, Fraction):
|
|
285
|
+
r = value
|
|
286
|
+
elif isinstance(value, int):
|
|
287
|
+
r = Fraction(value)
|
|
288
|
+
else:
|
|
289
|
+
if isinstance(value, float):
|
|
290
|
+
if not math.isfinite(value):
|
|
291
|
+
return None
|
|
292
|
+
text = repr(value)
|
|
293
|
+
elif isinstance(value, str):
|
|
294
|
+
text = value.strip()
|
|
295
|
+
else:
|
|
296
|
+
return None
|
|
297
|
+
m = _RATIONAL_RE.match(text)
|
|
298
|
+
if m:
|
|
299
|
+
if int(m.group(2)) == 0:
|
|
300
|
+
return None
|
|
301
|
+
r = Fraction(int(m.group(1)), int(m.group(2)))
|
|
302
|
+
elif _DECIMAL_RE.match(text):
|
|
303
|
+
r = Fraction(text)
|
|
304
|
+
if r.denominator != 1:
|
|
305
|
+
r = next((Fraction(b * 1000, 1001) for b in NTSC_BASES
|
|
306
|
+
if abs(r - Fraction(b * 1000, 1001)) <= Fraction(5, 1000)), r)
|
|
307
|
+
else:
|
|
308
|
+
return None
|
|
309
|
+
return r if 0 < r <= 1000 else None
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def stream_rate(v: Dict[str, Any], default: float = 30.0) -> float:
|
|
313
|
+
"""The rate a timeline is drawn at, as the float of the exact fraction (TB-1, TB-2): ffprobe's r_frame_rate when
|
|
314
|
+
it is the stream's rate (within 0.001 of the probe's fps), else the probe's 3-decimal fps read by TB-2 (29.97 ->
|
|
315
|
+
30000/1001). The compositions and expected_frames() then multiply by 29.97002997..., not by 29.97: the file
|
|
316
|
+
Remotion writes carries 30000/1001, and a long timeline does not drift a frame every ~9 hours."""
|
|
317
|
+
fps = exact_rate(v.get("fps"))
|
|
318
|
+
r = exact_rate(v.get("r_frame_rate"))
|
|
319
|
+
if r is not None and (fps is None or abs(r - fps) < Fraction(1, 1000)):
|
|
320
|
+
return float(r)
|
|
321
|
+
return float(fps) if fps is not None else float(default)
|
|
322
|
+
|
|
323
|
+
|
|
270
324
|
def sec_to_frames(seconds: float, fps: float) -> int:
|
|
271
325
|
# JavaScript's Math.round (round half up), not Python's round() (half to even): the TypeScript
|
|
272
326
|
# compositions compute the same frame numbers and the two must agree to the frame (94.5 -> 95).
|
package/scripts/analyze.py
CHANGED
|
@@ -34,7 +34,7 @@ from typing import Any, Dict, List, Optional, Tuple
|
|
|
34
34
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
35
35
|
from _common import (STATE, TIMELINE_SCHEMA, SKILL_ID, add_common, apply_common, default_output, die,
|
|
36
36
|
emit, ffmpeg_skill_version, ffskill, ffskill_cmd, info, refuse_existing,
|
|
37
|
-
require_ffmpeg_skill, shell_join, version)
|
|
37
|
+
require_ffmpeg_skill, shell_join, stream_rate, version)
|
|
38
38
|
from _captions import (CaptionError, cues_from_words, parse_chapters, read_captions, read_emphasis,
|
|
39
39
|
read_word_timings, resolve_emphasis, youtube_chapter_warnings)
|
|
40
40
|
|
|
@@ -490,7 +490,7 @@ def main() -> None:
|
|
|
490
490
|
pip = {"path": str(cam.resolve()), "name": cam.name,
|
|
491
491
|
"duration": round(float(cv.get("duration") or cp.get("duration") or 0), 3),
|
|
492
492
|
"width": int(cv.get("width") or 0), "height": int(cv.get("height") or 0),
|
|
493
|
-
"fps":
|
|
493
|
+
"fps": stream_rate(cv, 0.0), "offset": 0.0, "confidence": None, "measured": False,
|
|
494
494
|
"conform": cam_conform}
|
|
495
495
|
if a.pip_offset is not None:
|
|
496
496
|
pip["offset"] = round(float(a.pip_offset), 4)
|
|
@@ -514,7 +514,7 @@ def main() -> None:
|
|
|
514
514
|
"path": str(src.resolve()),
|
|
515
515
|
"name": src.name,
|
|
516
516
|
"duration": round(duration, 3),
|
|
517
|
-
"fps":
|
|
517
|
+
"fps": stream_rate(v),
|
|
518
518
|
"width": int(v.get("width") or 1920),
|
|
519
519
|
"height": int(v.get("height") or 1080),
|
|
520
520
|
"has_video": bool(video),
|