ffmpeg-skill 3.8.10 → 3.8.12
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/README.md +1 -1
- package/docs/contract.md +13 -7
- package/package.json +1 -1
- package/references/scripts.md +13 -6
- package/scripts/_common/decision.py +108 -2
- package/scripts/_common/emit.py +8 -5
- package/scripts/_common/probe.py +5 -0
- package/scripts/_common/runner.py +42 -1
- package/scripts/_contract.py +3 -3
- package/scripts/background.py +30 -10
- package/scripts/broll.py +82 -18
- package/scripts/caption.py +2 -2
- package/scripts/color.py +8 -5
- package/scripts/crop.py +3 -1
- package/scripts/export.py +16 -7
- package/scripts/fit.py +35 -4
- package/scripts/freeze.py +10 -5
- package/scripts/graphics.py +20 -9
- package/scripts/grid.py +4 -2
- package/scripts/loop.py +24 -6
- package/scripts/metadata.py +4 -0
- package/scripts/overlay.py +12 -13
- package/scripts/pad.py +12 -4
- package/scripts/redact.py +14 -2
- package/scripts/render.py +64 -2
- package/scripts/reverse.py +20 -7
- package/scripts/straighten.py +14 -3
- package/scripts/sync.py +6 -2
package/scripts/overlay.py
CHANGED
|
@@ -38,7 +38,7 @@ from _common import still_input_args # noqa: E402
|
|
|
38
38
|
from _common import STATE, script_font_for_text, drawtext_clean, drawtext_line_metrics, drawtext_text_opts, drawtext_draws_newline_glyph, is_multiline, needs_shaping, LANGUAGE_NAMES, has_emoji, detect_script, emoji_clusters, load_brand, drawn_chain, label_chain, layer_base_chain, matrix_chain, overlay_format, range_chain, rgb_chain_to_bt709, video_args, add_common, apply_common, emit, aac_args, cfr_args, default_output, die, escape_drawtext, ffmpeg_base, info, parse_time, probe, run, run_keeping_subtitles, validate_color, x264_args, X264_PRESETS, time_arg, fmt_secs
|
|
39
39
|
from _common.emit import note, warn
|
|
40
40
|
from _common.color import is_rgb
|
|
41
|
-
from _common.decision import length_output_t
|
|
41
|
+
from _common.decision import length_output_t, window_expr, windowed_overlay_x
|
|
42
42
|
from _common.alpha import (add_alpha_args, audio_line, check_alpha_args, decoder_args_for, default_ext, finish_chain,
|
|
43
43
|
has_alpha_plane, report as alpha_report, source_alpha, source_format, tag_args, video_line)
|
|
44
44
|
from _common.probe import display_size, refuse_not_a_still, square_pixels, square_pixels_note
|
|
@@ -128,13 +128,12 @@ def _wrap_to_frame(args, frame_w: int, margins: Optional[dict], frame_h: int = 0
|
|
|
128
128
|
return wrapped
|
|
129
129
|
|
|
130
130
|
|
|
131
|
-
def enable_expr(start: Optional[float], end: Optional[float]) -> str:
|
|
131
|
+
def enable_expr(start: Optional[float], end: Optional[float], meta: Optional[dict] = None) -> str:
|
|
132
|
+
"""True on the main picture's frames from --start to --end, both inclusive (window_expr):
|
|
133
|
+
the bounds sit half a frame from the frames they select, not on a frame's own time."""
|
|
132
134
|
if start is None and end is None:
|
|
133
135
|
return ""
|
|
134
|
-
|
|
135
|
-
if end is None:
|
|
136
|
-
return f"gte(t,{s})"
|
|
137
|
-
return f"between(t,{s},{end:.3f})"
|
|
136
|
+
return window_expr(start, end, meta)
|
|
138
137
|
|
|
139
138
|
|
|
140
139
|
def alpha_expr(opacity: float, start: Optional[float], end: Optional[float], fade: float) -> str:
|
|
@@ -440,7 +439,7 @@ def main() -> int:
|
|
|
440
439
|
"from --start to --end without a fade", hint="drop --fade for the video layer")
|
|
441
440
|
|
|
442
441
|
output = args.output or default_output(args.input, "overlay", default_ext(alpha_codec) if alpha_codec else None)
|
|
443
|
-
enable = enable_expr(start, end)
|
|
442
|
+
enable = enable_expr(start, end, meta)
|
|
444
443
|
cmd = ffmpeg_base() + ["-i", args.input]
|
|
445
444
|
|
|
446
445
|
if args.image:
|
|
@@ -464,9 +463,9 @@ def main() -> int:
|
|
|
464
463
|
x, y = position_exprs(args.position, args.margin, text_mode=False, margins=safe_margins)
|
|
465
464
|
# a 10-bit main on a 10-bit line is composited at 10 bits in YUV: format=auto with an RGBA
|
|
466
465
|
# still took the whole picture through 8-bit RGB (overlay_format)
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
466
|
+
# a --start/--end window is in the layer's position, which is evaluated on the main
|
|
467
|
+
# picture's frames; overlay's enable is evaluated on the layer's frames too
|
|
468
|
+
ov = f"overlay={windowed_overlay_x(x, enable) if enable else x}:{y}" + (overlay_format(meta) or ":format=auto")
|
|
470
469
|
# -loop 1 turns the still into a timed stream so fade/enable expressions see real timestamps
|
|
471
470
|
cmd = ffmpeg_base() + ["-i", args.input, "-loop", "1", *still_input_args(args.image), "-i", args.image]
|
|
472
471
|
# the RGBA still is converted to the BT.709 the output is tagged with (overlay's own
|
|
@@ -545,9 +544,9 @@ def main() -> int:
|
|
|
545
544
|
# which came back BT.601 under the BT.709 tag (#333's defect, on this path)
|
|
546
545
|
chain.append(f"lut=y=val:u=val:v=val:a=val*{args.opacity:g}")
|
|
547
546
|
x, y = position_exprs(args.position, args.margin, text_mode=False, margins=safe_margins)
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
547
|
+
# a --start/--end window is in the layer's position, which is evaluated on the main
|
|
548
|
+
# picture's frames; overlay's enable is evaluated on the layer's frames too
|
|
549
|
+
ov = f"overlay={windowed_overlay_x(x, enable) if enable else x}:{y}" + (overlay_format(meta) or ":format=auto")
|
|
551
550
|
# a VP9 layer stored with an alpha layer is decoded with libvpx-vp9: FFmpeg's own decoder
|
|
552
551
|
# drops the alpha, and the layer covered the picture as an opaque rectangle
|
|
553
552
|
cmd = ffmpeg_base() + ["-i", args.input] + decoder_args_for(pip_meta, args.video) + ["-i", args.video]
|
package/scripts/pad.py
CHANGED
|
@@ -16,8 +16,8 @@ Examples:
|
|
|
16
16
|
import argparse
|
|
17
17
|
import sys
|
|
18
18
|
|
|
19
|
-
from _common.emit import record_fallback
|
|
20
|
-
from _common.decision import silence_filter
|
|
19
|
+
from _common.emit import note, record_fallback
|
|
20
|
+
from _common.decision import silence_filter, tpad_length
|
|
21
21
|
from _common import add_common, apply_common, aac_args, cfr_args, default_output, die, drawn_chain, emit, EVEN_SCALE, ffmpeg_base, info, probe, run_keeping_subtitles, validate_color, video_args, X264_PRESETS, time_arg, fmt_secs, run
|
|
22
22
|
|
|
23
23
|
|
|
@@ -65,8 +65,16 @@ def main() -> int:
|
|
|
65
65
|
# front (one -filter_complex), so the record is made here, as broll and stabilize do
|
|
66
66
|
record_fallback(f"{args.input} is {v.get('width')}x{v.get('height')}: scaled to even dimensions first",
|
|
67
67
|
"odd_dimensions_scaled_even", output=output, scale=EVEN_SCALE)
|
|
68
|
-
#
|
|
69
|
-
|
|
68
|
+
# The sound is delayed by what the picture is: tpad puts whole frames ahead of the clip
|
|
69
|
+
# (--start 0.23425 at 25 fps: 6 frames, 0.240 s), and a delay of --start itself moved the
|
|
70
|
+
# sound 5.75 ms ahead of its picture (tpad_length). The silence after the clip moves
|
|
71
|
+
# nothing and is --end as asked. Either is counted in samples when it is not a whole
|
|
72
|
+
# millisecond (silence_filter).
|
|
73
|
+
lead = tpad_length(args.start, meta)
|
|
74
|
+
if abs(lead - args.start) > 1e-9:
|
|
75
|
+
note(f"--start {args.start:g}: the picture can only be padded by whole frames, {lead:.6f} s here; "
|
|
76
|
+
f"the sound is delayed by the same {lead:.6f} s so the clip keeps its sync")
|
|
77
|
+
af = silence_filter(meta["audio"].get("sample_rate"), lead, args.end)
|
|
70
78
|
cmd += ["-filter_complex", f"[0:v:0]{even}{vf}[v];[0:a:0]{af}[a]", "-map", "[v]", "-map", "[a]"]
|
|
71
79
|
else:
|
|
72
80
|
cmd += ["-vf", vf, "-map", "0:v:0"]
|
package/scripts/redact.py
CHANGED
|
@@ -101,7 +101,14 @@ def main() -> int:
|
|
|
101
101
|
(square + "," if square else "") + f"delogo=x={args.x}:y={args.y}:w={args.width}:h={args.height}",
|
|
102
102
|
"-map", "0:v:0"]
|
|
103
103
|
else:
|
|
104
|
-
|
|
104
|
+
# exact=1: crop rounds an odd x/y down to the chroma grid of a 4:2:0 frame otherwise, and
|
|
105
|
+
# overlay always does, so an odd rectangle was taken from and put back one pixel up and
|
|
106
|
+
# left (its last column and row left as they were, one outside it changed: A170). The
|
|
107
|
+
# patch is taken exactly, given a transparent first column/row where x/y is odd, and put
|
|
108
|
+
# at the even position before it: the luma inside the rectangle is replaced, the luma
|
|
109
|
+
# outside is not (the chroma pair on an odd edge is shared, so it is half mixed)
|
|
110
|
+
crop = f"crop={args.width}:{args.height}:{args.x}:{args.y}:exact=1"
|
|
111
|
+
ox, oy = args.x % 2, args.y % 2
|
|
105
112
|
if args.mode == "blur":
|
|
106
113
|
# boxblur refuses a radius above half the plane: the chroma planes of 4:2:0 are half-size,
|
|
107
114
|
# so they get their own (halved) radius; a 30 px region with the default 20 used to fail
|
|
@@ -110,7 +117,12 @@ def main() -> int:
|
|
|
110
117
|
region = f"{crop},boxblur={radius}:{radius}:{chroma}:{radius}"
|
|
111
118
|
else:
|
|
112
119
|
region = f"{crop},scale={max(1, args.width // args.block_size)}:{max(1, args.height // args.block_size)}:flags=neighbor,scale={args.width}:{args.height}:flags=neighbor"
|
|
113
|
-
|
|
120
|
+
if ox or oy:
|
|
121
|
+
deep = overlay_format(meta)
|
|
122
|
+
region += (f",format=yuva444p{'10le' if deep else ''},"
|
|
123
|
+
f"pad={args.width + 2 * ox}:{args.height + 2 * oy}:{ox}:{oy}:color=black@0")
|
|
124
|
+
fc = (f"[0:v]{square + ',' if square else ''}split=2[base][region];[region]{region}[patched];"
|
|
125
|
+
f"[base][patched]overlay={args.x - ox}:{args.y - oy}{overlay_format(meta)}[out]")
|
|
114
126
|
cmd = ffmpeg_base() + ["-i", args.input, "-filter_complex", fc, "-map", "[out]"]
|
|
115
127
|
if has_audio:
|
|
116
128
|
cmd += ["-map", f"0:a:{args.audio_stream}?"]
|
package/scripts/render.py
CHANGED
|
@@ -74,7 +74,7 @@ from typing import Any, Dict, List, Optional, Sequence
|
|
|
74
74
|
|
|
75
75
|
from export import PRESETS, PLATFORM_OF
|
|
76
76
|
from _platforms import PLATFORMS, caption_defaults, resolve as resolve_platform
|
|
77
|
-
from _common import guard_sidecar, STATE, add_common, aspect_ratio, brand_caption_style, load_brand, apply_common, child_args, die, emit, info, option_args, probe, require_tool, run, run_tool, place_output, refuse_output_is_input, _check_existing_output, _check_output_path, fingerprint, PLAN_VERSION, ffmpeg_version, X264_PRESETS
|
|
77
|
+
from _common import guard_sidecar, STATE, add_common, aspect_ratio, brand_caption_style, load_brand, apply_common, child_args, die, emit as _emit, info, option_args, probe, require_tool, run, run_tool, place_output, refuse_output_is_input, _check_existing_output, _check_output_path, fingerprint, PLAN_VERSION, ffmpeg_version, X264_PRESETS
|
|
78
78
|
from _common.runner import HW_ENV, HW_FORCED_ENV, add_hw_orchestrator_args, child_exit_code, found_exe, kept_clause, kept_deliverables, mark_delivered, owned_identity, read_json, remember_written
|
|
79
79
|
from _common.emit import absorb_stage, audit, record_fallback, record_skip, refuse, warn
|
|
80
80
|
from _common.decision import rebase_project_paths
|
|
@@ -691,6 +691,59 @@ def check_snap_to(snap: Any, label: str) -> None:
|
|
|
691
691
|
|
|
692
692
|
_LAST_DOC: Dict[str, Any] = {} # the JSON document the most recent sh() child printed
|
|
693
693
|
|
|
694
|
+
# source_carry for a render (A255): the one picture/sound source of a project with one, and what
|
|
695
|
+
# each stage that ran said about the start timecode ("kept", "dropped", None: a stage that compared
|
|
696
|
+
# nothing, "unknown": a cache hit whose entry did not keep it). main() resets both.
|
|
697
|
+
PROJECT_SOURCE: Dict[str, Any] = {"src": None, "timecode": []}
|
|
698
|
+
|
|
699
|
+
|
|
700
|
+
def _timecode_verdict(doc: Any) -> Optional[str]:
|
|
701
|
+
"""What a stage's document says about the start timecode: "kept", "dropped", or None when its
|
|
702
|
+
source_carry compared none."""
|
|
703
|
+
carry = doc.get("source_carry") if isinstance(doc, dict) else None
|
|
704
|
+
if not isinstance(carry, dict):
|
|
705
|
+
return None
|
|
706
|
+
return "dropped" if "timecode" in (carry.get("dropped") or []) else "kept" if "timecode" in (carry.get("kept") or []) else None
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
def project_source(proj: Dict[str, Any], rel) -> Optional[str]:
|
|
710
|
+
"""The project's single picture/sound source -- its clips all one file, and no music,
|
|
711
|
+
replacement or effects track, no video layer and no audiogram picture beside it -- or None,
|
|
712
|
+
when the output mixes several (source_carry is then not compared, as for any tool with two
|
|
713
|
+
sources)."""
|
|
714
|
+
srcs = {os.path.realpath(rel(c["src"])) for c in proj.get("clips") or [] if isinstance(c, dict) and isinstance(c.get("src"), str)}
|
|
715
|
+
audio = proj.get("audio") if isinstance(proj.get("audio"), dict) else {}
|
|
716
|
+
others = [audio.get(k) for k in ("music", "replace", "effects") if audio.get(k)]
|
|
717
|
+
overlays = proj.get("overlays") if isinstance(proj.get("overlays"), list) else []
|
|
718
|
+
others += [ov.get("video") for ov in overlays if isinstance(ov, dict) and ov.get("video")]
|
|
719
|
+
if proj.get("audiogram"):
|
|
720
|
+
others.append("audiogram") # the picture is the waveform over an image, not the clip's
|
|
721
|
+
return next(iter(srcs)) if len(srcs) == 1 and not others else None
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
def emit(output: Optional[str], **extra: Any) -> None:
|
|
725
|
+
"""emit(), with render.py's source_carry: the stages run as children, so this process never
|
|
726
|
+
probed the project's source as an input and its result carried no source_carry at all, even
|
|
727
|
+
for a one-clip render that lost the source's subtitle track (A255). The source is probed here
|
|
728
|
+
(after the stages' intermediates, which are not sources), so emit() compares it with the
|
|
729
|
+
delivered file. A stage that moves the picture's start writes the label of the frame it starts
|
|
730
|
+
on, which is not the source's: the timecode counts as kept when every stage that compared it
|
|
731
|
+
kept it, as dropped when one dropped it, and is compared with the source's own label when no
|
|
732
|
+
stage said (nothing ran, or a cache entry written before stages' source_carry was kept)."""
|
|
733
|
+
src = PROJECT_SOURCE.get("src")
|
|
734
|
+
if src and output and not STATE.dry_run and os.path.isfile(src) and os.path.isfile(output) \
|
|
735
|
+
and os.path.realpath(src) != os.path.realpath(output) and "source_carry" not in extra:
|
|
736
|
+
STATE.first_input, STATE.video_inputs, STATE.audio_inputs = None, set(), set()
|
|
737
|
+
probe(src)
|
|
738
|
+
said = PROJECT_SOURCE["timecode"]
|
|
739
|
+
if "dropped" in said:
|
|
740
|
+
STATE.expected_timecode = ""
|
|
741
|
+
elif "kept" in said and "unknown" not in said:
|
|
742
|
+
STATE.expected_timecode = (probe(output, role="output").get("timecode") or {}).get("value") or ""
|
|
743
|
+
else:
|
|
744
|
+
STATE.expected_timecode = None
|
|
745
|
+
_emit(output, **extra)
|
|
746
|
+
|
|
694
747
|
|
|
695
748
|
def _refuse_uncached_earlier_stage(stage: str) -> None:
|
|
696
749
|
"""--from STAGE promises the earlier stages come from the cache. When one does not, say so
|
|
@@ -783,6 +836,7 @@ def sh(script: str, *argv: Any, extra: List[str] = None, stage: str = None) -> s
|
|
|
783
836
|
code=int(doc.get("exit_code") or 1), kind=err.get("kind") or "input", stage=script, error_extra=error_extra, **extra_fields)
|
|
784
837
|
_LAST_DOC.clear()
|
|
785
838
|
_LAST_DOC.update(doc if isinstance(doc, dict) else {})
|
|
839
|
+
PROJECT_SOURCE["timecode"].append(_timecode_verdict(doc))
|
|
786
840
|
absorb_stage(Path(script).stem, doc) # a stage's GPU facts (ran on VideoToolbox, fell back and why) and its diagnostics reach this result
|
|
787
841
|
out_path = str(doc.get("output") or "")
|
|
788
842
|
if not STATE.dry_run:
|
|
@@ -981,6 +1035,10 @@ def cache_lookup(stage: str, key: str, dest: str, tool: Optional[str] = None) ->
|
|
|
981
1035
|
shutil.copy2(art, dest) # ... and a copy where it does not. Never a move: the cache
|
|
982
1036
|
CACHE["saved_seconds"] += float(meta.get("seconds") or 0.0)
|
|
983
1037
|
result = meta.get("result")
|
|
1038
|
+
# what the stage said about the start timecode, for render's source_carry; an entry written
|
|
1039
|
+
# before its source_carry was kept does not say
|
|
1040
|
+
PROJECT_SOURCE["timecode"].append(_timecode_verdict(result) if isinstance(result, dict) and "source_carry" in result
|
|
1041
|
+
else "unknown")
|
|
984
1042
|
if isinstance(result, dict):
|
|
985
1043
|
absorb_stage(tool or stage, dict(result, status="completed", dry_run=False)) # tagged as the stage's tool, as a live run is
|
|
986
1044
|
else:
|
|
@@ -994,7 +1052,9 @@ def _stage_result(doc: Any) -> Dict[str, Any]:
|
|
|
994
1052
|
"""What a cache entry keeps of the stage's own --json document, replayed on a hit."""
|
|
995
1053
|
if not isinstance(doc, dict):
|
|
996
1054
|
return {}
|
|
997
|
-
|
|
1055
|
+
kept = {k: doc[k] for k in ("verified", "verification", "notes", "diagnostics") if k in doc}
|
|
1056
|
+
kept["source_carry"] = doc.get("source_carry") # None too: the stage compared nothing (render's source_carry)
|
|
1057
|
+
return kept
|
|
998
1058
|
|
|
999
1059
|
|
|
1000
1060
|
def cache_store(stage: str, key: str, produced: str, seconds: float, doc: Any = None) -> None:
|
|
@@ -1472,6 +1532,7 @@ def main() -> int:
|
|
|
1472
1532
|
add_hw_orchestrator_args(ap)
|
|
1473
1533
|
args = ap.parse_args()
|
|
1474
1534
|
apply_common(args)
|
|
1535
|
+
PROJECT_SOURCE.update(src=None, timecode=[])
|
|
1475
1536
|
STATE.audit_log = os.path.abspath(args.audit_log) if args.audit_log else None
|
|
1476
1537
|
|
|
1477
1538
|
if args.list_templates:
|
|
@@ -1650,6 +1711,7 @@ def main() -> int:
|
|
|
1650
1711
|
CACHE.clear()
|
|
1651
1712
|
CACHE.update(_fresh_cache())
|
|
1652
1713
|
CONTENT_KEYED.clear()
|
|
1714
|
+
PROJECT_SOURCE.update(src=project_source(proj, rel), timecode=[])
|
|
1653
1715
|
if args.cache:
|
|
1654
1716
|
cdir = Path(args.cache)
|
|
1655
1717
|
try:
|
package/scripts/reverse.py
CHANGED
|
@@ -17,7 +17,8 @@ import sys
|
|
|
17
17
|
|
|
18
18
|
from _common import add_common, apply_common, aac_args, cfr_args, default_output, die, emit, ffmpeg_base, info, probe, run, video_args, X264_PRESETS, fmt_secs
|
|
19
19
|
from _common.emit import warn
|
|
20
|
-
from _common.decision import av_clip_length, av_trim, frame_durations, frame_rate,
|
|
20
|
+
from _common.decision import (HELD_FRAMES_WARN_BYTES, av_clip_length, av_trim, delivered_rate, frame_durations, frame_rate,
|
|
21
|
+
held_frames_bytes, stream_starts)
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
def main() -> int:
|
|
@@ -37,10 +38,16 @@ def main() -> int:
|
|
|
37
38
|
has_audio = bool(meta.get("audio")) and not args.no_audio
|
|
38
39
|
|
|
39
40
|
output = args.output or default_output(args.input, "reverse")
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
# keyed on what is held (every decoded frame), not on the length alone (A174): the estimate
|
|
42
|
+
# loop.py --boomerang warns from, over the frames of the picture's length at its rate
|
|
43
|
+
v = meta["video"]
|
|
44
|
+
vdur = v.get("duration") or meta.get("duration") or 0.0
|
|
45
|
+
frames = v.get("nb_frames") or vdur * (frame_rate(meta) or v.get("fps") or 30.0)
|
|
46
|
+
held = held_frames_bytes(v, frames)
|
|
47
|
+
if held > HELD_FRAMES_WARN_BYTES:
|
|
48
|
+
warn(f"reverse holds about {held / 1024 ** 3:.1f} GiB of decoded frames in memory "
|
|
49
|
+
f"({vdur:.0f}s of {v['width']}x{v['height']}) -- cut the part to reverse first (cut.py) if RAM is tight",
|
|
50
|
+
"memory_heavy", duration=meta.get("duration"), bytes=held)
|
|
44
51
|
cmd = ffmpeg_base() + ["-i", args.input]
|
|
45
52
|
if has_audio:
|
|
46
53
|
# Both streams are reversed about one end (#409); each reversed about its own end put a sound
|
|
@@ -55,14 +62,20 @@ def main() -> int:
|
|
|
55
62
|
# setpts: from FFmpeg 7.0 setpts leaves its output's frame rate unknown and its frames'
|
|
56
63
|
# durations 0, so a tpad after it clones nothing (the picture stayed 0.6 s short on 7.1);
|
|
57
64
|
# the closing fps gives the frames their durations back (frame_durations).
|
|
58
|
-
rate
|
|
65
|
+
# the rate the encoder line delivers (cfr_args: a VFR source is conformed to its average
|
|
66
|
+
# rate), so the graph's closing fps and the output's -r are one grid: the graph closed on
|
|
67
|
+
# r_frame_rate and -r then resampled it, 51 frames for 49 that ran 81 ms past the sound (A234)
|
|
68
|
+
# The trim that drops the hold's spare clones stays on the source's own grid (half a frame
|
|
69
|
+
# of r_frame_rate before the end): half a delivered frame cut a real last frame that sits
|
|
70
|
+
# nearer the end than that, and reverse then opened on the one before it.
|
|
71
|
+
rate = delivered_rate(meta) or frame_rate(meta) or meta["video"].get("fps") or 30.0
|
|
59
72
|
length = av_clip_length(meta, rate)
|
|
60
73
|
vlen = meta["video"].get("duration") or length
|
|
61
74
|
end = math.ceil(length * rate - 1e-6) / rate
|
|
62
75
|
vtrim, atrim = av_trim(stream_starts(meta)[0], None)
|
|
63
76
|
cmd += ["-filter_complex",
|
|
64
77
|
f"[0:v:0]tpad=stop_mode=clone:stop_duration={max(0.0, end - vlen) + 2 / rate:.6f},{vtrim},"
|
|
65
|
-
f"trim=end={end - 0.5 / rate:.6f},reverse,{frame_durations(meta, rate)}[v];"
|
|
78
|
+
f"trim=end={end - 0.5 / max(rate, frame_rate(meta) or rate):.6f},reverse,{frame_durations(meta, rate)}[v];"
|
|
66
79
|
f"[0:a:0]{atrim},apad=whole_dur={end:.6f},atrim=end={end:.6f},areverse,asetpts=N/SR/TB[a]",
|
|
67
80
|
"-map", "[v]", "-map", "[a]"]
|
|
68
81
|
else:
|
package/scripts/straighten.py
CHANGED
|
@@ -80,9 +80,20 @@ def main() -> int:
|
|
|
80
80
|
dw, dh = display_size(meta["video"])
|
|
81
81
|
aspect = max(dw / dh, dh / dw) if dw and dh else 1.0
|
|
82
82
|
s = abs(math.cos(radians)) + aspect * abs(math.sin(radians))
|
|
83
|
-
#
|
|
84
|
-
#
|
|
85
|
-
|
|
83
|
+
# The window is the displayed frame's own size, to even (4:2:0 chroma), and the scaled frame
|
|
84
|
+
# is rounded UP to even so it still covers it. Scaling to iw*s and cropping back to
|
|
85
|
+
# trunc(iw/s/2)*2 lost to two roundings: 1920x1080 came out 1918x1078, and the scale's
|
|
86
|
+
# rounding left a non-square SAR such as 6112:6111 (A235).
|
|
87
|
+
cw, ch = (dw // 2 * 2, dh // 2 * 2) if dw and dh else (0, 0)
|
|
88
|
+
if cw and ch:
|
|
89
|
+
# the margin on each axis is a multiple of 4, so the centred crop's offset is even:
|
|
90
|
+
# crop floors an odd one to the chroma grid, which moved the window a pixel up and
|
|
91
|
+
# left and could bring the fill into the top-left corner
|
|
92
|
+
sw, sh = (c + math.ceil(max(0.0, c * s - c) / 4) * 4 for c in (cw, ch))
|
|
93
|
+
rotate = (f"scale={sw}:{sh},setsar=1,"
|
|
94
|
+
f"rotate={radians:.8f},crop={cw}:{ch},setsar=1")
|
|
95
|
+
else: # a dry run's pending input has no size yet: the old expression, planned only
|
|
96
|
+
rotate = f"scale=iw*{s:.8f}:ih*{s:.8f},rotate={radians:.8f},crop=trunc(iw/{s:.8f}/2)*2:trunc(ih/{s:.8f}/2)*2"
|
|
86
97
|
|
|
87
98
|
# a rotation of non-square pixels is a shear on screen: the picture is squared at its
|
|
88
99
|
# display aspect first (#411)
|
package/scripts/sync.py
CHANGED
|
@@ -441,8 +441,12 @@ def main() -> int:
|
|
|
441
441
|
# same command, and the seek stays next to the -i it drops the margin from
|
|
442
442
|
cmd += ["-i", args.second] + out_seek + default_selection_maps(second_meta, output)
|
|
443
443
|
af_parts = on_clock + drift_af
|
|
444
|
-
|
|
445
|
-
|
|
444
|
+
# one sound is written here (the default selection, or the probed track of a file
|
|
445
|
+
# with several: default_selection_maps), the one sec_sr is the rate of, so the delay
|
|
446
|
+
# is counted in its samples as --replace-audio's is. A whole millisecond (the
|
|
447
|
+
# default --fine-ms 1 without --fix-drift) keeps `adelay=<ms>:all=1`
|
|
448
|
+
if offset > 0 and round(offset * sec_sr):
|
|
449
|
+
af_parts.append(silence_filter(sec_sr, lead=offset))
|
|
446
450
|
if has_video:
|
|
447
451
|
vf = []
|
|
448
452
|
if delay_ms > 0:
|