@auscera/cleoedits 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/README.md +62 -2
- package/cli.mjs +149 -0
- package/lib/dependencies.mjs +384 -0
- package/lib/run.mjs +114 -0
- package/lib/workspace.mjs +167 -0
- package/package.json +240 -3
- package/workspace/.agents/skills/cleoedits/SKILL.md +29 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/audiogram.json +41 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/facebook.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/linkedin.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/podcast.json +23 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/reels.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/shorts.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/tiktok.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/x.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/youtube-shorts.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/ffmpeg_templates/youtube.json +48 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/assets/LICENSE-SimpleIcons +30 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/assets/logos.json +1 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Anton-Regular.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/ArchivoBlack-Regular.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/InstrumentSerif-Italic.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Inter.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/LICENSE-PermanentMarker.txt +202 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Montserrat.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-Anton.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-ArchivoBlack.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-InstrumentSerif.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-Inter.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-Montserrat.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-PlayfairDisplay.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-Poppins.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/OFL-SpaceMono.txt +93 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/PermanentMarker-Regular.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/PlayfairDisplay-Italic.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/PlayfairDisplay.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Poppins-Black.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Poppins-Bold.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/Poppins-ExtraBold.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/fonts/SpaceMono-Bold.ttf +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/LICENSE-MediaPipe +218 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/LICENSE-YuNet +21 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/NOTICE.md +4 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/selfie_segmenter.tflite +0 -0
- package/workspace/.agents/skills/cleoedits/assets/reel_effects/models/yunet.onnx +0 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/LICENSE +21 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/audio-app-ui/STYLE.md +65 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/blueprint/STYLE.md +53 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/blueprint/index.html +328 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/blueprint/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/data-story/STYLE.md +65 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/data-story/index.html +575 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/design-app-ui/STYLE.md +68 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/editor-ui/STYLE.md +73 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/editorial-paper/STYLE.md +54 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/editorial-paper/index.html +189 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/editorial-paper/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/explainer-diagram/STYLE.md +64 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/explainer-diagram/index.html +620 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/graphite-ui/STYLE.md +55 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/graphite-ui/index.html +238 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/graphite-ui/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/growing-city/STYLE.md +66 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/growing-city/index.html +602 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/ink-line/STYLE.md +66 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/ink-line/index.html +777 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/midnight-grid/STYLE.md +56 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/midnight-grid/index.html +186 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/midnight-grid/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/motion-app-ui/STYLE.md +68 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-cut/STYLE.md +56 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-cut/index.html +244 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-cut/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-world/STYLE.md +67 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/paper-world/index.html +663 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/particle-field/STYLE.md +59 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/particle-field/index.html +395 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/poster-pop/STYLE.md +52 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/poster-pop/index.html +194 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/poster-pop/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/risograph/STYLE.md +58 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/risograph/index.html +242 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/risograph/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-grid/STYLE.md +53 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-grid/index.html +138 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-grid/studio.js +57 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-kinetic/STYLE.md +63 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/swiss-kinetic/index.html +599 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/time-travel/STYLE.md +65 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/time-travel/index.html +1297 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/weather-widget/STYLE.md +69 -0
- package/workspace/.agents/skills/cleoedits/assets/video_styles/weather-widget/index.html +674 -0
- package/workspace/.agents/skills/cleoedits/references/audio-clearervoice-elevenlabs.md +11 -0
- package/workspace/.agents/skills/cleoedits/references/ffmpeg-and-reels.md +15 -0
- package/workspace/.agents/skills/cleoedits/references/hyperframes-workflows.md +13 -0
- package/workspace/.agents/skills/cleoedits/references/kdenlive-cli-and-mcp.md +12 -0
- package/workspace/.agents/skills/cleoedits/references/motion-design-pipeline.md +7 -0
- package/workspace/.agents/skills/cleoedits/references/motion-taste-emil.md +5 -0
- package/workspace/.agents/skills/cleoedits/references/playwright-demo-capture.md +9 -0
- package/workspace/.agents/skills/cleoedits/references/remotion-workflows.md +13 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/LICENSE +21 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_ass_overlay.py +399 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/__init__.py +235 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/alpha.py +560 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/asr.py +1237 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/color.py +540 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/decision.py +2452 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/drawtext.py +290 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/emit.py +1309 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/emoji.py +518 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/fonts.py +875 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/pacing.py +263 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/pacing_edit.py +432 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/probe.py +1613 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/runner.py +3994 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/text.py +73 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/timeline.py +721 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_common/wrap.py +981 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_contract.py +2454 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_platforms.py +258 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_review.html +754 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_review.py +258 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/_smartcut.py +450 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/audio.py +867 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/background.py +136 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/batch.py +1409 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/broll.py +282 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/caption.py +2207 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/check.py +815 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/color.py +695 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/crop.py +91 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/cropdetect.py +214 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/cut.py +2076 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/deinterlace.py +90 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/denoise.py +94 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/export.py +1033 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/fit.py +729 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/freeze.py +197 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/graphics.py +920 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/grid.py +235 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/insert.py +142 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/join.py +1083 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/look.py +475 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/loop.py +395 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/loudness.py +397 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/metadata.py +416 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/multicam.py +414 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/overlay.py +766 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/pad.py +121 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/probe.py +145 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/proxy.py +93 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/redact.py +162 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/render.py +2424 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/report.py +354 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/reverse.py +114 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/scenes.py +439 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/sequence.py +285 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/silence.py +945 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/speedramp.py +193 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/sphere.py +137 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/stabilize.py +141 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/straighten.py +120 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/sync.py +500 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/verify.py +411 -0
- package/workspace/.agents/skills/cleoedits/scripts/ffmpeg/waveform.py +502 -0
- package/workspace/.agents/skills/cleoedits/scripts/kdenlive_builder.py +284 -0
- package/workspace/.agents/skills/cleoedits/scripts/motion/LICENSE-claude-motion +21 -0
- package/workspace/.agents/skills/cleoedits/scripts/motion/LICENSE-motion-design +21 -0
- package/workspace/.agents/skills/cleoedits/scripts/motion/_media.py +43 -0
- package/workspace/.agents/skills/cleoedits/scripts/motion/pacing_check.py +90 -0
- package/workspace/.agents/skills/cleoedits/scripts/motion/storyboard.py +77 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/LICENSE +26 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/fx.py +2717 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/logos.py +194 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/sfx.py +105 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/trim.py +99 -0
- package/workspace/.agents/skills/cleoedits/scripts/reel_effects/words.py +60 -0
- package/workspace/.claude/commands/blender-3d.md +12 -0
- package/workspace/.claude/commands/business-short-form-reels.md +12 -0
- package/workspace/.claude/commands/color-grade.md +12 -0
- package/workspace/.claude/commands/cutout-grid-reel.md +12 -0
- package/workspace/.claude/commands/depth-ui-reel.md +12 -0
- package/workspace/.claude/commands/explainer-panel-reel.md +12 -0
- package/workspace/.claude/commands/freeze-frame.md +12 -0
- package/workspace/.claude/commands/glass-graph.md +12 -0
- package/workspace/.claude/commands/over-the-shoulder.md +12 -0
- package/workspace/.claude/commands/personal-short-form-reels.md +12 -0
- package/workspace/.claude/commands/ranking-format.md +12 -0
- package/workspace/.claude/commands/relight.md +12 -0
- package/workspace/.claude/commands/reverse-engineer.md +12 -0
- package/workspace/.claude/commands/text-behind.md +12 -0
- package/workspace/.claude/commands/tier-list.md +12 -0
- package/workspace/.claude-plugin/plugin.json +8 -0
- package/workspace/.npmignore +15 -0
- package/workspace/AGENTS.md +30 -0
- package/workspace/README.md +63 -0
- package/workspace/assets/fonts/TikTokSans-OFL.txt +93 -0
- package/workspace/assets/fonts/TikTokSans-Variable.ttf +0 -0
- package/workspace/assets/luts/clean_warm.cube +4917 -0
- package/workspace/assets/luts/golden_hour.cube +4917 -0
- package/workspace/assets/luts/moody_dark.cube +4917 -0
- package/workspace/assets/luts/teal_orange.cube +4917 -0
- package/workspace/assets/sfx/NOTICE.txt +1 -0
- package/workspace/assets/sfx/click.wav +0 -0
- package/workspace/assets/sfx/pop.wav +0 -0
- package/workspace/assets/sfx/riser.wav +0 -0
- package/workspace/assets/sfx/whoosh.wav +0 -0
- package/workspace/generators/hyperframes/index.html +39 -0
- package/workspace/generators/hyperframes/package.json +15 -0
- package/workspace/generators/hyperframes/pnpm-lock.yaml +1181 -0
- package/workspace/generators/hyperframes/pnpm-workspace.yaml +10 -0
- package/workspace/generators/remotion/eslint.config.mjs +3 -0
- package/workspace/generators/remotion/package.json +36 -0
- package/workspace/generators/remotion/pnpm-lock.yaml +4179 -0
- package/workspace/generators/remotion/pnpm-workspace.yaml +10 -0
- package/workspace/generators/remotion/remotion.config.ts +13 -0
- package/workspace/generators/remotion/src/Root.tsx +52 -0
- package/workspace/generators/remotion/src/index.css +1 -0
- package/workspace/generators/remotion/src/index.ts +4 -0
- package/workspace/generators/remotion/tsconfig.json +15 -0
- package/workspace/pipeline/scripts/_codec.py +28 -0
- package/workspace/pipeline/scripts/ai_media_api.py +109 -0
- package/workspace/pipeline/scripts/blender_render.py +166 -0
- package/workspace/pipeline/scripts/composite.py +49 -0
- package/workspace/pipeline/scripts/melt.sh +68 -0
- package/workspace/pipeline/scripts/normalize_audio.py +39 -0
- package/workspace/pipeline/scripts/person_matte.py +216 -0
- package/workspace/pipeline/scripts/record_demo.py +69 -0
- package/workspace/pipeline/scripts/whisper_cut.py +98 -0
- package/workspace-manifest.json +908 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Step through different constant speeds across a clip's timeline (a speed ramp).
|
|
3
|
+
|
|
4
|
+
Distinct from fit.py --duration --method speed, which applies one constant
|
|
5
|
+
factor to the whole clip. This tool takes a list of --segment START-END:FACTOR
|
|
6
|
+
pieces covering the clip start to end with no gaps or overlaps, each played
|
|
7
|
+
at its own constant speed (pitch-preserving audio, matching fit.py), then
|
|
8
|
+
concatenates them back together -- the classic "speed up, then slow way
|
|
9
|
+
down for the punch, then speed back up" edit, built from a few constant
|
|
10
|
+
segments rather than a continuous curve (which this tool does not attempt:
|
|
11
|
+
picking exactly where a ramp should ease in or out is a judgement call for
|
|
12
|
+
the calling agent, made concrete here as segment boundaries it supplies).
|
|
13
|
+
|
|
14
|
+
Examples:
|
|
15
|
+
python3 speedramp.py action.mp4 --segment 0-3:1.0 --segment 3-4:0.25 --segment 4-8:2.0
|
|
16
|
+
python3 speedramp.py clip.mp4 --segment 0-2:2.0 --segment 2-6:1.0
|
|
17
|
+
"""
|
|
18
|
+
import argparse
|
|
19
|
+
import math
|
|
20
|
+
import sys
|
|
21
|
+
from fractions import Fraction
|
|
22
|
+
from typing import Any, List, Tuple
|
|
23
|
+
|
|
24
|
+
from _common.decision import atempo_chain_with_lead, av_trim, conform_filter, delivered_rate, frame_durations, frame_rate, grid_at_or_after, on_frame, stream_starts
|
|
25
|
+
from _common.runner import with_mapped_chapters
|
|
26
|
+
from _common import add_common, apply_common, aac_args, default_output, die, emit, ffmpeg_base, info, probe, run, video_args, X264_PRESETS, fmt_secs, time_arg
|
|
27
|
+
from _common.emit import input_length, refuse_still
|
|
28
|
+
|
|
29
|
+
MAX_SPEED = 20.0
|
|
30
|
+
MIN_SPEED = 0.05
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def atempo_chain(factor: float, sample_rate: Any = 0) -> str:
|
|
34
|
+
"""atempo accepts 0.5..100 per instance; chain for factors outside that range. The chain is
|
|
35
|
+
led by the samples atempo leaves out (atempo_chain_with_lead, at the track's `sample_rate`):
|
|
36
|
+
without them every segment's sound came out 21 ms early at 1x and 40 ms at 0.5x (#523)."""
|
|
37
|
+
parts: List[str] = []
|
|
38
|
+
remaining = factor
|
|
39
|
+
while remaining < 0.5:
|
|
40
|
+
parts.append("0.5")
|
|
41
|
+
remaining /= 0.5
|
|
42
|
+
while remaining > 100.0:
|
|
43
|
+
parts.append("100.0")
|
|
44
|
+
remaining /= 100.0
|
|
45
|
+
parts.append(f"{remaining:.6f}")
|
|
46
|
+
return atempo_chain_with_lead(parts, sample_rate)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def parse_segment(raw: str) -> Tuple[float, float, float]:
|
|
50
|
+
try:
|
|
51
|
+
span, factor_s = raw.rsplit(":", 1)
|
|
52
|
+
start_s, end_s = span.rsplit("-", 1)
|
|
53
|
+
factor = float(factor_s)
|
|
54
|
+
except ValueError:
|
|
55
|
+
die(f"--segment must look like START-END:FACTOR, got '{raw}'")
|
|
56
|
+
start, end = time_arg(start_s, f"--segment {raw!r} start"), time_arg(end_s, f"--segment {raw!r} end")
|
|
57
|
+
if end <= start:
|
|
58
|
+
die(f"--segment {raw}: END must be after START")
|
|
59
|
+
if not MIN_SPEED <= factor <= MAX_SPEED:
|
|
60
|
+
die(f"--segment {raw}: FACTOR must be {MIN_SPEED}..{MAX_SPEED}")
|
|
61
|
+
return start, end, factor
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def main() -> int:
|
|
65
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
66
|
+
ap.add_argument("input")
|
|
67
|
+
ap.add_argument("-o", "--output", help="output file (default: <name>_ramp.<ext>)")
|
|
68
|
+
ap.add_argument("--segment", action="append", required=True, dest="segments",
|
|
69
|
+
help=f"one step of the ramp as START-END:FACTOR, repeatable; segments must cover 0..duration with no gaps or overlaps, in order. FACTOR is {MIN_SPEED}..{MAX_SPEED} (2.0 = twice as fast, 0.5 = half speed)")
|
|
70
|
+
ap.set_defaults(crf=18) # --quality's default (the --crf alias was removed in 2.0)
|
|
71
|
+
ap.add_argument("--preset", default="medium", choices=X264_PRESETS, help="x264 preset")
|
|
72
|
+
add_common(ap)
|
|
73
|
+
args = ap.parse_args()
|
|
74
|
+
apply_common(args)
|
|
75
|
+
|
|
76
|
+
segments = [parse_segment(s) for s in args.segments]
|
|
77
|
+
segments.sort(key=lambda s: s[0])
|
|
78
|
+
meta = probe(args.input)
|
|
79
|
+
if not meta.get("video"):
|
|
80
|
+
die("input has no video stream")
|
|
81
|
+
refuse_still(meta, args.input, "--segment ranges are times in a clip, and a still has none") # not "0..0.000" (#531)
|
|
82
|
+
dur = input_length(meta)
|
|
83
|
+
if abs(segments[0][0] - 0.0) > 0.01:
|
|
84
|
+
die(f"segments must start at 0, first segment starts at {segments[0][0]:g}")
|
|
85
|
+
if abs(segments[-1][1] - dur) > 0.5:
|
|
86
|
+
die(f"segments must cover the whole clip (0..{dur:.3f}), last segment ends at {segments[-1][1]:g}")
|
|
87
|
+
for i in range(len(segments) - 1):
|
|
88
|
+
if abs(segments[i][1] - segments[i + 1][0]) > 0.01:
|
|
89
|
+
die(f"segments must be contiguous with no gap/overlap: segment {i} ends at {segments[i][1]:g}, "
|
|
90
|
+
f"segment {i + 1} starts at {segments[i + 1][0]:g}")
|
|
91
|
+
has_audio = bool(meta.get("audio"))
|
|
92
|
+
output = args.output or default_output(args.input, "ramp")
|
|
93
|
+
|
|
94
|
+
vparts, aparts = [], []
|
|
95
|
+
# The coverage check above allows the last end to sit up to 0.5 s off the probed duration.
|
|
96
|
+
# That slack is for a caller who rounded the duration, not a reason to redraw the tail at
|
|
97
|
+
# the last factor. The end bound is omitted only when the stated end is the file's end
|
|
98
|
+
# (within 50 ms): a trim a few milliseconds short of the last packet drops that packet.
|
|
99
|
+
last_runs_to_eof = abs(segments[-1][1] - dur) <= 0.05
|
|
100
|
+
# Every boundary is a frame time and both streams of a segment are cut on it and shifted by the
|
|
101
|
+
# same constant before the speed change (#409), as cut.py's re-cut does. Rebasing each stream
|
|
102
|
+
# of each segment to its own first sample moved a sound that starts 0.3 s late 0.3 s early, and
|
|
103
|
+
# the factor scaled that (+570 ms at 0.5x). The first segment starts at the first frame.
|
|
104
|
+
v0 = stream_starts(meta)[0]
|
|
105
|
+
rate = frame_rate(meta)
|
|
106
|
+
# on a VFR source the picture is delivered at the rate the encoder line forces (its average):
|
|
107
|
+
# closed on r_frame_rate, -r then resampled the joined picture and it drifted 113 ms late (#512)
|
|
108
|
+
out_rate = delivered_rate(meta) or rate
|
|
109
|
+
srate = int((meta.get("audio") or {}).get("sample_rate") or 0)
|
|
110
|
+
bounds = [v0] + [grid_at_or_after(on_frame(end, v0, rate), v0, rate) for _, end, _ in segments[:-1]] # (#653)
|
|
111
|
+
retimed = 0.0 # where the segment starts on the output's clock
|
|
112
|
+
for i, (start, end, factor) in enumerate(segments):
|
|
113
|
+
vlabel, alabel = f"v{i}", f"a{i}"
|
|
114
|
+
to_eof = i == len(segments) - 1 and last_runs_to_eof
|
|
115
|
+
seg_end = None if to_eof else (bounds[i + 1] if i + 1 < len(bounds) else grid_at_or_after(on_frame(end, v0, rate), v0, rate))
|
|
116
|
+
if seg_end is not None and seg_end <= bounds[i] + 1e-6:
|
|
117
|
+
# both ends on the same frame: the trims would be empty and the factor reach no frame
|
|
118
|
+
die(f"--segment {start:g}-{end:g}:{factor:g} holds no frame: both ends fall on the frame at "
|
|
119
|
+
f"{bounds[i]:.3f}s; widen it or merge it into a neighbour")
|
|
120
|
+
vtrim, atrim = av_trim(bounds[i], seg_end, rate)
|
|
121
|
+
# the closing fps puts the sped-up frames back on the delivered grid with its frame
|
|
122
|
+
# duration: concat starts the next segment after the last frame's duration, which setpts
|
|
123
|
+
# leaves at the unscaled 1/rate, so every 2x segment pushed the rest of the picture two
|
|
124
|
+
# frames late against the sound (and added those frames)
|
|
125
|
+
vchain = f"[0:v]{vtrim},setpts=PTS/{factor:.6f},{frame_durations(meta, out_rate)}"
|
|
126
|
+
# a 1x segment is not retimed: atempo would place its sound by windows for nothing (#541)
|
|
127
|
+
achain = f"[0:a]{atrim}" if factor == 1.0 else f"[0:a]{atrim},{atempo_chain(factor, srate)}"
|
|
128
|
+
if out_rate:
|
|
129
|
+
# Each segment holds the frames (and samples) between its retimed ends on the whole
|
|
130
|
+
# output's grid, not its own length rounded: eight 0.5 s segments at 27 fps rounded
|
|
131
|
+
# to 14 frames each, concat advanced 14/27 s per segment and the last flash landed
|
|
132
|
+
# 130 ms late. The picture is sampled on the output's grid (an offset of under half
|
|
133
|
+
# a frame, and fps's start_time) and, but for a last segment that runs to the end,
|
|
134
|
+
# padded by a frame or two and cut to its count; the sound is padded or cut to its
|
|
135
|
+
# own count, so neither stream drifts across segments.
|
|
136
|
+
first = round(retimed * out_rate)
|
|
137
|
+
shift = first / out_rate - retimed
|
|
138
|
+
vchain = (f"[0:v]{vtrim},setpts=PTS/{factor:.6f}{-shift:+.6f}/TB,"
|
|
139
|
+
f"{frame_durations(meta, out_rate)}:start_time=0")
|
|
140
|
+
if seg_end is not None:
|
|
141
|
+
after = retimed + (seg_end - bounds[i]) / factor
|
|
142
|
+
vchain += f",tpad=stop=2:stop_mode=clone,trim=end_frame={round(after * out_rate) - first}"
|
|
143
|
+
if srate:
|
|
144
|
+
achain += f",{conform_filter(round(after * srate) - round(retimed * srate), srate)}"
|
|
145
|
+
retimed = after
|
|
146
|
+
vparts.append(f"{vchain}[{vlabel}]")
|
|
147
|
+
if has_audio:
|
|
148
|
+
aparts.append(f"{achain}[{alabel}]")
|
|
149
|
+
|
|
150
|
+
# the two streams are joined by two concats: one concat over both started each segment after
|
|
151
|
+
# the longer of its two streams, so a picture a frame longer than its sound moved both late
|
|
152
|
+
n = len(segments)
|
|
153
|
+
# Every segment's picture is a whole count of frames on one grid, so the joined picture's
|
|
154
|
+
# timestamps are rebuilt from the running frame count: FFmpeg 6.1.1's video-only concat gave a
|
|
155
|
+
# one-frame segment no length (it takes a segment's end from its last frame's timestamp), so
|
|
156
|
+
# three one-frame segments put the rest of the picture a frame before its sound. The closing
|
|
157
|
+
# fps gives the frames their durations back (from 7.0 setpts leaves them 0, frame_durations)
|
|
158
|
+
regrid = ""
|
|
159
|
+
if out_rate:
|
|
160
|
+
grid = frame_durations(meta, out_rate)
|
|
161
|
+
q = Fraction(grid[len("fps="):]) if "/" in grid else Fraction(out_rate).limit_denominator(1001)
|
|
162
|
+
regrid = f",setpts=N*{q.denominator}/({q.numerator}*TB),{grid}"
|
|
163
|
+
fc = ";".join(vparts) + ";" + "".join(f"[v{i}]" for i in range(n)) + f"concat=n={n}:v=1:a=0{regrid}[outv]"
|
|
164
|
+
maps = ["-map", "[outv]"]
|
|
165
|
+
if has_audio:
|
|
166
|
+
fc += ";" + ";".join(aparts) + ";" + "".join(f"[a{i}]" for i in range(n)) + f"concat=n={n}:v=0:a=1[outa]"
|
|
167
|
+
maps += ["-map", "[outa]"]
|
|
168
|
+
|
|
169
|
+
cmd = ffmpeg_base() + ["-i", args.input, "-filter_complex", fc] + maps
|
|
170
|
+
cmd += video_args(meta, args.crf, args.preset)
|
|
171
|
+
cmd += ["-fps_mode", "cfr", "-r", f"{meta['video'].get('fps') or 30.0:g}"]
|
|
172
|
+
if has_audio:
|
|
173
|
+
cmd += aac_args()
|
|
174
|
+
else:
|
|
175
|
+
cmd += ["-an"]
|
|
176
|
+
edges = bounds + [math.inf]
|
|
177
|
+
|
|
178
|
+
def ramped(t: float) -> float:
|
|
179
|
+
# a source time on the output's clock: each segment's share of it at that segment's factor
|
|
180
|
+
return sum(max(0.0, min(t, edges[i + 1]) - edges[i]) / f for i, (_, _, f) in enumerate(segments)) - v0
|
|
181
|
+
cmd = with_mapped_chapters(cmd, meta, ramped, None) # chapters follow the ramp (#470)
|
|
182
|
+
cmd.append(output)
|
|
183
|
+
run(cmd)
|
|
184
|
+
|
|
185
|
+
result = probe(output, role="output")
|
|
186
|
+
v = result["video"]
|
|
187
|
+
info(f"wrote {output} ({fmt_secs(result['duration'])}, {v['width']}x{v['height']}, {len(segments)} speed segments)")
|
|
188
|
+
emit(output, dropped_non_av_streams=bool(meta.get("subtitle_streams") or meta.get("data_streams")))
|
|
189
|
+
return 0
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
if __name__ == "__main__":
|
|
193
|
+
sys.exit(main())
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Extract a flat (rectilinear) viewport from a 360/spherical video.
|
|
3
|
+
|
|
4
|
+
This wraps FFmpeg's v360 filter for the one job it is most often needed for:
|
|
5
|
+
turning an equirectangular (or other spherical-projection) source into an
|
|
6
|
+
ordinary flat video pointed at a chosen direction -- the same "look this way"
|
|
7
|
+
operation a VR headset or a 360 video player's viewport does, baked into a
|
|
8
|
+
real file. --yaw/--pitch/--roll aim the camera; --h-fov/--v-fov set how wide
|
|
9
|
+
the view is (without --v-fov, the vertical view is the one that keeps the
|
|
10
|
+
output's pixels square).
|
|
11
|
+
|
|
12
|
+
This tool does not decide WHERE to point the camera -- there is no subject
|
|
13
|
+
detection or tracking here, only the typed rotation/FOV you give it (see this
|
|
14
|
+
skill's design principles: it measures and transforms, it does not judge
|
|
15
|
+
"what's interesting" in a frame). For a shot that follows a moving subject,
|
|
16
|
+
call this once per keyframe viewpoint (or render a short segment per angle)
|
|
17
|
+
from outside this tool.
|
|
18
|
+
|
|
19
|
+
Nor does it detect whether an input actually IS a 360/spherical video --
|
|
20
|
+
probe.py's frame dimensions don't distinguish a 2:1 equirectangular capture
|
|
21
|
+
from an ordinary flat clip that happens to be that aspect ratio. Point
|
|
22
|
+
--input-projection at what the source actually is; wrong information here
|
|
23
|
+
produces a distorted or garbled output, not an error (a real limit of what a
|
|
24
|
+
frame's own pixels can prove about how they were projected -- ffmpeg's own
|
|
25
|
+
v360 filter has the same limit).
|
|
26
|
+
|
|
27
|
+
Examples:
|
|
28
|
+
python3 sphere.py insta360.mp4 --yaw 0 --pitch 0 -o front.mp4
|
|
29
|
+
python3 sphere.py insta360.mp4 --yaw 90 --h-fov 100 --v-fov 70 -o right_wide.mp4
|
|
30
|
+
python3 sphere.py gopro_max.mp4 --input-projection fisheye --yaw -45 --pitch 10 -o angle.mp4
|
|
31
|
+
"""
|
|
32
|
+
import argparse
|
|
33
|
+
import math
|
|
34
|
+
import sys
|
|
35
|
+
|
|
36
|
+
from _common import add_common, apply_common, aac_args, cfr_args, with_cfr, default_output, die, emit, ffmpeg_base, info, probe, run_keeping_subtitles, video_args, X264_PRESETS, fmt_secs
|
|
37
|
+
from _common.emit import note
|
|
38
|
+
|
|
39
|
+
# v360's own AVOption names for the input projections real 360 cameras/exports actually
|
|
40
|
+
# produce (ffmpeg -h filter=v360 documents 24 total; this is the subset a caller is likely
|
|
41
|
+
# to have on hand, not the full list -- narrower, typed choices over an open string).
|
|
42
|
+
INPUT_PROJECTIONS = ["equirect", "fisheye", "dfisheye", "c3x2", "c6x1", "barrel", "cylindrical", "hequirect"]
|
|
43
|
+
INTERP_METHODS = ["nearest", "linear", "cubic", "lanczos", "spline16", "gaussian", "mitchell"]
|
|
44
|
+
STEREO_MODES = {"mono": "2d", "sbs": "sbs", "tb": "tb"}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def main() -> int:
|
|
48
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
49
|
+
ap.add_argument("input")
|
|
50
|
+
ap.add_argument("-o", "--output", help="output file (default: <name>_view.<ext>)")
|
|
51
|
+
ap.add_argument("--audio-stream", type=int, default=0,
|
|
52
|
+
help="which audio stream of the input to keep, 0-based in file order (probe.py lists them under "
|
|
53
|
+
"audio_streams) -- matters on a multi-track input (dubbed languages, M&E stems); default 0, "
|
|
54
|
+
"the first track")
|
|
55
|
+
ap.add_argument("--input-projection", choices=INPUT_PROJECTIONS, default="equirect",
|
|
56
|
+
help="the source's own 360 projection (default equirect, the most common capture/export format)")
|
|
57
|
+
ap.add_argument("--stereo", choices=list(STEREO_MODES), default="mono",
|
|
58
|
+
help="input stereo packing: mono (default), sbs (side-by-side), tb (top-bottom) -- always flattened to a mono output")
|
|
59
|
+
aim = ap.add_argument_group("camera aim")
|
|
60
|
+
aim.add_argument("--yaw", type=float, default=0.0, help="left/right rotation in degrees, -180..180 (default 0, straight ahead)")
|
|
61
|
+
aim.add_argument("--pitch", type=float, default=0.0, help="up/down rotation in degrees, -180..180 (default 0, level)")
|
|
62
|
+
aim.add_argument("--roll", type=float, default=0.0, help="tilt/roll rotation in degrees, -180..180 (default 0)")
|
|
63
|
+
fov = ap.add_argument_group("field of view")
|
|
64
|
+
fov.add_argument("--h-fov", "--fov", type=float, default=90.0, help="output horizontal field of view in degrees, 1..170 (default 90)")
|
|
65
|
+
fov.add_argument("--v-fov", type=float, default=None,
|
|
66
|
+
help="output vertical field of view in degrees, 1..170 (default: the one that keeps pixels square at "
|
|
67
|
+
"--h-fov and --width/--height, 58.7 at the defaults)")
|
|
68
|
+
out = ap.add_argument_group("output frame")
|
|
69
|
+
out.add_argument("--width", type=int, default=1920, help="output width in px, must be even (default 1920); a size or resolution WxH is --width W --height H")
|
|
70
|
+
out.add_argument("--height", type=int, default=1080, help="output height in px, must be even (default 1080)")
|
|
71
|
+
out.add_argument("--interp", choices=INTERP_METHODS, default="lanczos", help="resampling method (default lanczos)")
|
|
72
|
+
ap.set_defaults(crf=18) # --quality's default (the --crf alias was removed in 2.0)
|
|
73
|
+
ap.add_argument("--preset", default="medium", choices=X264_PRESETS, help="x264 preset")
|
|
74
|
+
ap.add_argument("--fps", type=float, help="force a constant output frame rate (recommended for VFR sources)")
|
|
75
|
+
add_common(ap)
|
|
76
|
+
args = ap.parse_args()
|
|
77
|
+
apply_common(args)
|
|
78
|
+
if args.fps is not None and args.fps <= 0:
|
|
79
|
+
die(f"--fps must be positive, got {args.fps:g}")
|
|
80
|
+
|
|
81
|
+
# the angles and both fields of view state their range in the help; apply_common refuses outside it
|
|
82
|
+
if args.width <= 0 or args.height <= 0:
|
|
83
|
+
die(f"--width/--height must be > 0, got width={args.width} height={args.height}")
|
|
84
|
+
if args.width % 2 or args.height % 2:
|
|
85
|
+
die(f"--width/--height must be even (4:2:0 chroma), got width={args.width} height={args.height}")
|
|
86
|
+
# A rectilinear view has square pixels when tan(v/2) / tan(h/2) = H / W. Through 3.8.8 the
|
|
87
|
+
# default was a fixed 60 degrees, which at 90 x 1920x1080 squashed the view 2.6 % vertically
|
|
88
|
+
# (audit A163); the vertical FOV now follows from the other three unless it is given.
|
|
89
|
+
square_v = math.degrees(2 * math.atan(math.tan(math.radians(args.h_fov) / 2) * args.height / args.width))
|
|
90
|
+
if args.v_fov is None:
|
|
91
|
+
if not 1 <= square_v <= 170:
|
|
92
|
+
die(f"--h-fov {args.h_fov:g} at {args.width}x{args.height} needs a vertical field of view of {square_v:.1f} "
|
|
93
|
+
"degrees for square pixels, outside 1..170", hint="give --v-fov, or a lower --h-fov")
|
|
94
|
+
args.v_fov = round(square_v, 4)
|
|
95
|
+
else:
|
|
96
|
+
stretch = math.tan(math.radians(args.v_fov) / 2) / math.tan(math.radians(square_v) / 2)
|
|
97
|
+
if abs(stretch - 1) > 0.005:
|
|
98
|
+
note(f"--h-fov {args.h_fov:g} / --v-fov {args.v_fov:g} at {args.width}x{args.height} is not square-pixel: the view is "
|
|
99
|
+
f"{'squashed' if stretch > 1 else 'stretched'} {abs(stretch - 1) * 100:.1f} % vertically "
|
|
100
|
+
f"(--v-fov {square_v:.2f} keeps it square; omit --v-fov to get it)")
|
|
101
|
+
|
|
102
|
+
meta = probe(args.input)
|
|
103
|
+
if not meta.get("video"):
|
|
104
|
+
die("input has no video stream")
|
|
105
|
+
has_audio = bool(meta.get("audio"))
|
|
106
|
+
audio_streams = meta.get("audio_streams") or []
|
|
107
|
+
if audio_streams and not (0 <= args.audio_stream < len(audio_streams)):
|
|
108
|
+
die(f"--audio-stream {args.audio_stream}: input has {len(audio_streams)} audio stream(s), 0..{len(audio_streams) - 1}")
|
|
109
|
+
if args.audio_stream and not audio_streams:
|
|
110
|
+
die("--audio-stream needs an input with audio streams")
|
|
111
|
+
output = args.output or default_output(args.input, "view")
|
|
112
|
+
|
|
113
|
+
v360 = (f"v360=input={args.input_projection}:output=rectilinear:"
|
|
114
|
+
f"in_stereo={STEREO_MODES[args.stereo]}:out_stereo=2d:"
|
|
115
|
+
f"yaw={args.yaw:g}:pitch={args.pitch:g}:roll={args.roll:g}:"
|
|
116
|
+
f"h_fov={args.h_fov:g}:v_fov={args.v_fov:g}:"
|
|
117
|
+
f"w={args.width}:h={args.height}:interp={args.interp}")
|
|
118
|
+
cmd = ffmpeg_base() + ["-i", args.input, "-vf", with_cfr(v360, meta, args.fps), "-map", "0:v:0"]
|
|
119
|
+
if has_audio:
|
|
120
|
+
cmd += ["-map", f"0:a:{args.audio_stream}?"]
|
|
121
|
+
cmd += video_args(meta, args.crf, args.preset)
|
|
122
|
+
cmd += cfr_args(meta, args.fps)
|
|
123
|
+
if has_audio:
|
|
124
|
+
cmd += aac_args()
|
|
125
|
+
else:
|
|
126
|
+
cmd += ["-an"]
|
|
127
|
+
dropped_streams = run_keeping_subtitles(cmd, output)
|
|
128
|
+
|
|
129
|
+
result = probe(output, role="output")
|
|
130
|
+
v = result["video"]
|
|
131
|
+
info(f"wrote {output} ({fmt_secs(result['duration'])}, {v['width']}x{v['height']}, yaw={args.yaw:g} pitch={args.pitch:g})")
|
|
132
|
+
emit(output, dropped_non_av_streams=dropped_streams)
|
|
133
|
+
return 0
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
if __name__ == "__main__":
|
|
137
|
+
sys.exit(main())
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Stabilize shaky video (FFmpeg's vidstab, two-pass).
|
|
3
|
+
|
|
4
|
+
Pass 1 (vidstabdetect) analyses camera motion and writes the transforms to a
|
|
5
|
+
temporary file; pass 2 (vidstabtransform) smooths that motion and re-renders
|
|
6
|
+
the frames. The transforms file lives in a temp directory for the duration of
|
|
7
|
+
this run only -- it is not a caller-facing artifact.
|
|
8
|
+
|
|
9
|
+
--shakiness (1 = barely shaky, fast; 10 = very shaky, slow analysis) and
|
|
10
|
+
--smoothing (how many neighbouring frames to average the camera path over)
|
|
11
|
+
are the two knobs that matter most; --zoom crops in slightly to hide the
|
|
12
|
+
edges stabilizing can introduce (0 = keep the original framing and let edges
|
|
13
|
+
show). --crop chooses what happens to any edge vidstab reveals that --zoom
|
|
14
|
+
doesn't crop away: "keep" (default) stretches the border pixels, "black"
|
|
15
|
+
fills it in solid black instead. --tripod locks the frame fully still
|
|
16
|
+
against a single reference frame (e.g. a camera meant to be static but
|
|
17
|
+
nudged, or a shot you want dead-locked rather than merely smoothed) instead
|
|
18
|
+
of following the camera's intended motion.
|
|
19
|
+
|
|
20
|
+
Examples:
|
|
21
|
+
python3 stabilize.py shaky.mp4
|
|
22
|
+
python3 stabilize.py shaky.mp4 --shakiness 8 --smoothing 20 --zoom 5
|
|
23
|
+
python3 stabilize.py locked-off.mp4 --tripod --crop black
|
|
24
|
+
"""
|
|
25
|
+
import argparse
|
|
26
|
+
import sys
|
|
27
|
+
import tempfile
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
|
|
30
|
+
from _common.probe import PROBED_VIDEO, probed_maps
|
|
31
|
+
from _common.color import is_rgb
|
|
32
|
+
from _common.decision import line_matrix_filter
|
|
33
|
+
from _common.emit import note
|
|
34
|
+
from _common.runner import ffmpeg_failure_extra, require_filter
|
|
35
|
+
from _common import add_common, apply_common, aac_args, cfr_args, with_cfr, default_output, die, emit, escape_filter_path, ffmpeg_base, info, probe, require_tool, run_keeping_subtitles, video_args, X264_PRESETS, run_analysis, dry_run_input_pending, fmt_secs, record_fallback, EVEN_SCALE
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def main() -> int:
|
|
39
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
40
|
+
ap.add_argument("input")
|
|
41
|
+
ap.add_argument("-o", "--output", help="output file (default: <name>_stab.<ext>)")
|
|
42
|
+
ap.add_argument("--strength", "--shakiness", dest="shakiness", type=int, default=5, help="the amount of shake to correct, the strength: 1 (barely shaky) .. 10 (very shaky), default 5")
|
|
43
|
+
ap.add_argument("--smoothing", type=int, default=15, help="frames of camera-path smoothing on each side, default 15")
|
|
44
|
+
ap.add_argument("--zoom", type=float, default=0.0, help="percent to zoom in to hide stabilization edges, 0..100 (default 0)")
|
|
45
|
+
ap.add_argument("--crop", choices=["keep", "black"], default="keep", help="edges --zoom doesn't crop away: keep (stretch border pixels, default) or black (fill solid black)")
|
|
46
|
+
ap.add_argument("--tripod", action="store_true", help="lock the frame fully still against a single reference frame instead of smoothing the camera's motion")
|
|
47
|
+
ap.set_defaults(crf=18) # --quality's default (the --crf alias was removed in 2.0)
|
|
48
|
+
ap.add_argument("--preset", default="medium", choices=X264_PRESETS, help="x264 preset")
|
|
49
|
+
add_common(ap)
|
|
50
|
+
args = ap.parse_args()
|
|
51
|
+
apply_common(args)
|
|
52
|
+
|
|
53
|
+
if not 1 <= args.shakiness <= 10:
|
|
54
|
+
die(f"--shakiness must be 1..10, got {args.shakiness}")
|
|
55
|
+
if not 0 <= args.smoothing <= 1000:
|
|
56
|
+
die(f"--smoothing must be 0..1000, got {args.smoothing}")
|
|
57
|
+
|
|
58
|
+
meta = probe(args.input)
|
|
59
|
+
if not meta.get("video"):
|
|
60
|
+
die("input has no video stream")
|
|
61
|
+
# pass 1 is a measurement that runs under --dry-run too: refused here, with the reason a run
|
|
62
|
+
# that met "No such filter" gets, instead of as an unclassified pass-1 failure (#402)
|
|
63
|
+
for name in ("vidstabdetect", "vidstabtransform"):
|
|
64
|
+
require_filter(name, "stabilizing (vid.stab)")
|
|
65
|
+
has_audio = bool(meta.get("audio"))
|
|
66
|
+
output = args.output or default_output(args.input, "stab")
|
|
67
|
+
|
|
68
|
+
with tempfile.TemporaryDirectory(prefix="ffmpeg-skill-vidstab-") as tmp:
|
|
69
|
+
trf = str(Path(tmp) / "transforms.trf")
|
|
70
|
+
trf_arg = escape_filter_path(trf)
|
|
71
|
+
|
|
72
|
+
ffmpeg = require_tool("ffmpeg")
|
|
73
|
+
# vid.stab asserts on an odd frame (ffmpeg aborts in pass 1, #438), so both passes see an
|
|
74
|
+
# even one. Recorded like the runner's own odd-size retry: the output is a pixel narrower
|
|
75
|
+
# or shorter than the source.
|
|
76
|
+
v = meta["video"]
|
|
77
|
+
w, h = int(v.get("width") or 0), int(v.get("height") or 0)
|
|
78
|
+
if int(v.get("rotation") or 0) % 180 == 90:
|
|
79
|
+
w, h = h, w
|
|
80
|
+
even = f"{EVEN_SCALE}," if (w % 2 or h % 2) else ""
|
|
81
|
+
if even:
|
|
82
|
+
record_fallback("source has odd dimensions; scaling to even before stabilizing (vid.stab needs it)",
|
|
83
|
+
"odd_dimensions_scaled_even", output=output, scale=EVEN_SCALE)
|
|
84
|
+
# vid.stab aborts on an RGB picture (FFmpeg 6.1.1 with libvidstab 1.1: rgb24, bgr24, rgba
|
|
85
|
+
# and gbrp all fail the assertion `fi->planes==1`), so pass 1 failed as kind ffmpeg on a
|
|
86
|
+
# PNG still or an RGB .mov (#531), and yuv444p of the same frames runs. Both passes see YUV
|
|
87
|
+
# 4:4:4: the conversion the encoder line folds into pass 2 for an RGB source
|
|
88
|
+
# (line_matrix_filter: to BT.709 on the SDR line, with the matrix the line tags on a
|
|
89
|
+
# BT.2020 / HDR one, #544), or, for an SDR source on a line that keeps the source's tags
|
|
90
|
+
# and converts no matrix (--codec prores), FFmpeg's own conversion to yuv444p, as that
|
|
91
|
+
# line's encoder has.
|
|
92
|
+
to_yuv, to_yuv_pass2 = "", ""
|
|
93
|
+
if is_rgb(meta):
|
|
94
|
+
conv = line_matrix_filter(meta)
|
|
95
|
+
to_yuv = (conv or "format=yuv444p") + ","
|
|
96
|
+
to_yuv_pass2 = "" if conv else to_yuv # the encoder line's conversion is folded in by run() (fold_bt709_matrix)
|
|
97
|
+
note(f"the source is RGB ({v.get('pix_fmt')}), which vid.stab does not take: both passes stabilize a YUV 4:4:4 "
|
|
98
|
+
"copy of it, and the output's pixel format is the encoder line's (probe.video.pix_fmt)")
|
|
99
|
+
detect_vf = f"{to_yuv}{even}vidstabdetect=shakiness={args.shakiness}:result={trf_arg}"
|
|
100
|
+
if args.tripod:
|
|
101
|
+
# A frame number, not a boolean: frame 1 is the standard reference for "lock to
|
|
102
|
+
# this fixed frame" (mirrors vidstabtransform's own tripod=1 below).
|
|
103
|
+
detect_vf += ":tripod=1"
|
|
104
|
+
# both passes read the picture probe() describes (its size chose the even scale above)
|
|
105
|
+
detect_cmd = [ffmpeg, "-hide_banner", "-loglevel", "error", "-nostdin", "-y", "-i", args.input,
|
|
106
|
+
"-map", f"0:{PROBED_VIDEO}", "-vf", detect_vf, "-f", "null", "-"]
|
|
107
|
+
# Pass 1 is a measurement into a temp file (the transforms), so it runs under --dry-run
|
|
108
|
+
# as well; only pass 2, the write, is skipped there.
|
|
109
|
+
if not dry_run_input_pending(args.input):
|
|
110
|
+
proc = run_analysis(detect_cmd, check=False, record=True)
|
|
111
|
+
if proc.returncode != 0:
|
|
112
|
+
die(f"stabilization analysis (pass 1) failed:\n{proc.stderr.strip()[-1500:]}", kind="ffmpeg", **ffmpeg_failure_extra(proc.stderr))
|
|
113
|
+
|
|
114
|
+
crop_mode = {"keep": 0, "black": 1}[args.crop]
|
|
115
|
+
# optzoom=0: the zoom is --zoom and nothing else. vidstab's default (optzoom=1) adds its own
|
|
116
|
+
# "optimal" zoom on top, so --zoom 0 did not keep the original framing and --crop black
|
|
117
|
+
# rarely had an edge to fill (through 3.8.8, audit A156)
|
|
118
|
+
transform_vf = f"{to_yuv_pass2}{even}vidstabtransform=input={trf_arg}:smoothing={args.smoothing}:crop={crop_mode}:zoom={args.zoom:g}:optzoom=0"
|
|
119
|
+
if args.tripod:
|
|
120
|
+
# Equivalent to relative=0:smoothing=0 -- overrides --smoothing, since averaging a
|
|
121
|
+
# camera path makes no sense once every frame is locked to one fixed reference.
|
|
122
|
+
transform_vf += ":tripod=1"
|
|
123
|
+
cmd = ffmpeg_base() + ["-i", args.input] + probed_maps(meta) + ["-vf", with_cfr(transform_vf, meta)]
|
|
124
|
+
cmd += video_args(meta, args.crf, args.preset)
|
|
125
|
+
cmd += cfr_args(meta)
|
|
126
|
+
if has_audio:
|
|
127
|
+
cmd += aac_args()
|
|
128
|
+
else:
|
|
129
|
+
cmd += ["-an"]
|
|
130
|
+
# the frames keep their times, so the subtitle/data tracks are copied as fit.py and color.py
|
|
131
|
+
# copy them, and dropped (said) only where the container refuses them (#520)
|
|
132
|
+
dropped_streams = run_keeping_subtitles(cmd, output)
|
|
133
|
+
|
|
134
|
+
result = probe(output, role="output")
|
|
135
|
+
info(f"wrote {output} ({fmt_secs(result['duration'])}, {result['video']['width']}x{result['video']['height']})")
|
|
136
|
+
emit(output, dropped_non_av_streams=dropped_streams)
|
|
137
|
+
return 0
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
if __name__ == "__main__":
|
|
141
|
+
sys.exit(main())
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Rotate a video by an arbitrary angle (horizon correction, not a 90/180/270 turn).
|
|
3
|
+
|
|
4
|
+
Distinct from fit.py --rotate, which only turns the picture in exact 90-degree
|
|
5
|
+
steps (swapping width/height, lossless in intent). This tool wraps FFmpeg's
|
|
6
|
+
rotate filter for a small corrective tilt -- "the horizon is 2 degrees off" --
|
|
7
|
+
which necessarily crops or pads the corners: rotating a rectangle by a
|
|
8
|
+
non-90-degree angle leaves triangular gaps at the corners. --fit crop scales
|
|
9
|
+
up just enough to fill the frame with no visible gap (losing a thin border
|
|
10
|
+
of the original picture); --fit pad keeps the full original picture inside
|
|
11
|
+
the rotated frame and fills the gaps with --fill-color.
|
|
12
|
+
|
|
13
|
+
This tool does not measure the tilt itself -- it has no way to find a
|
|
14
|
+
horizon line in a frame; that is a look.py/vision judgement call. Give the
|
|
15
|
+
degrees once you can see how far off it is.
|
|
16
|
+
|
|
17
|
+
Examples:
|
|
18
|
+
python3 straighten.py tilted.mp4 --degrees -2.5
|
|
19
|
+
python3 straighten.py handheld.mp4 --degrees 1.2 --fit pad --fill-color 0x101010
|
|
20
|
+
"""
|
|
21
|
+
import argparse
|
|
22
|
+
import math
|
|
23
|
+
import sys
|
|
24
|
+
|
|
25
|
+
from _common import add_common, apply_common, aac_args, cfr_args, with_cfr, default_output, die, drawn_chain, emit, ffmpeg_base, info, probe, run_keeping_subtitles, validate_color, video_args, X264_PRESETS, fmt_secs
|
|
26
|
+
from _common.emit import note
|
|
27
|
+
from _common.probe import display_size, square_pixels, square_pixels_note
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def main() -> int:
|
|
31
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
32
|
+
ap.add_argument("input")
|
|
33
|
+
ap.add_argument("-o", "--output", help="output file (default: <name>_straighten.<ext>)")
|
|
34
|
+
ap.add_argument("--angle", "--degrees", dest="degrees", type=float, required=True, help="rotation angle in degrees, -45..45, positive = clockwise")
|
|
35
|
+
ap.add_argument("--fit", choices=["crop", "pad"], default="crop",
|
|
36
|
+
help="crop (default): scale up to fill the frame, no visible corner gap; pad: keep the full picture (no crop), fill the corner gaps with --fill-color")
|
|
37
|
+
ap.add_argument("--pad-color", "--fill-color", dest="fill_color", default="black", help="corner fill colour with --fit pad (default black)")
|
|
38
|
+
ap.add_argument("--audio-stream", type=int, default=0,
|
|
39
|
+
help="which audio stream of the input to keep, 0-based in file order (default 0)")
|
|
40
|
+
ap.set_defaults(crf=18) # --quality's default (the --crf alias was removed in 2.0)
|
|
41
|
+
ap.add_argument("--preset", default="medium", choices=X264_PRESETS, help="x264 preset")
|
|
42
|
+
ap.add_argument("--fps", type=float, help="force a constant output frame rate (recommended for VFR sources)")
|
|
43
|
+
add_common(ap)
|
|
44
|
+
args = ap.parse_args()
|
|
45
|
+
apply_common(args)
|
|
46
|
+
if args.fps is not None and args.fps <= 0:
|
|
47
|
+
die(f"--fps must be positive, got {args.fps:g}")
|
|
48
|
+
|
|
49
|
+
if args.degrees == 0:
|
|
50
|
+
die("--degrees must be nonzero (nothing to straighten)")
|
|
51
|
+
validate_color(args.fill_color, "--fill-color")
|
|
52
|
+
|
|
53
|
+
meta = probe(args.input)
|
|
54
|
+
if not meta.get("video"):
|
|
55
|
+
die("input has no video stream")
|
|
56
|
+
has_audio = bool(meta.get("audio"))
|
|
57
|
+
audio_streams = meta.get("audio_streams") or []
|
|
58
|
+
if audio_streams and not (0 <= args.audio_stream < len(audio_streams)):
|
|
59
|
+
die(f"--audio-stream {args.audio_stream}: input has {len(audio_streams)} audio stream(s), 0..{len(audio_streams) - 1}")
|
|
60
|
+
if args.audio_stream and not audio_streams:
|
|
61
|
+
die("--audio-stream needs an input with audio streams")
|
|
62
|
+
output = args.output or default_output(args.input, "straighten")
|
|
63
|
+
|
|
64
|
+
radians = math.radians(args.degrees)
|
|
65
|
+
if args.fit == "pad":
|
|
66
|
+
geometry = f"ow=trunc(rotw({radians:.8f})/2)*2:oh=trunc(roth({radians:.8f})/2)*2"
|
|
67
|
+
# a --fill-color with chroma lands in the BT.709 the output is tagged with (drawn_chain)
|
|
68
|
+
rotate = drawn_chain(f"rotate={radians:.8f}:fillcolor={args.fill_color}:{geometry}", meta, [args.fill_color],
|
|
69
|
+
f"rotate={radians:.8f}:fillcolor=black:{geometry}")
|
|
70
|
+
else:
|
|
71
|
+
# Pre-scale the frame up so the rotated content fully covers the original W:H window with
|
|
72
|
+
# no black corner, then rotate in place (canvas stays at the scaled size) and crop back
|
|
73
|
+
# down to the original W:H, centred. The window turned back by the angle must fit inside
|
|
74
|
+
# the scaled frame: W*cos + H*sin <= s*W and W*sin + H*cos <= s*H, so
|
|
75
|
+
# s = |cos| + max(W/H, H/W) * |sin| for the displayed (squared, upright) frame. Through
|
|
76
|
+
# 3.1.5 it was |cos| + |sin|, a square's factor, which left two corners black on 16:9
|
|
77
|
+
# (#416 review).
|
|
78
|
+
dw, dh = display_size(meta["video"])
|
|
79
|
+
aspect = max(dw / dh, dh / dw) if dw and dh else 1.0
|
|
80
|
+
s = abs(math.cos(radians)) + aspect * abs(math.sin(radians))
|
|
81
|
+
# The window is the displayed frame's own size, to even (4:2:0 chroma), and the scaled frame
|
|
82
|
+
# is rounded UP to even so it still covers it. Scaling to iw*s and cropping back to
|
|
83
|
+
# trunc(iw/s/2)*2 lost to two roundings: 1920x1080 came out 1918x1078, and the scale's
|
|
84
|
+
# rounding left a non-square SAR such as 6112:6111 (A235).
|
|
85
|
+
cw, ch = (dw // 2 * 2, dh // 2 * 2) if dw and dh else (0, 0)
|
|
86
|
+
if cw and ch:
|
|
87
|
+
# the margin on each axis is a multiple of 4, so the centred crop's offset is even:
|
|
88
|
+
# crop floors an odd one to the chroma grid, which moved the window a pixel up and
|
|
89
|
+
# left and could bring the fill into the top-left corner
|
|
90
|
+
sw, sh = (c + math.ceil(max(0.0, c * s - c) / 4) * 4 for c in (cw, ch))
|
|
91
|
+
rotate = (f"scale={sw}:{sh},setsar=1,"
|
|
92
|
+
f"rotate={radians:.8f},crop={cw}:{ch},setsar=1")
|
|
93
|
+
else: # a dry run's pending input has no size yet: the old expression, planned only
|
|
94
|
+
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"
|
|
95
|
+
|
|
96
|
+
# a rotation of non-square pixels is a shear on screen: the picture is squared at its
|
|
97
|
+
# display aspect first (#411)
|
|
98
|
+
if square_pixels(meta["video"]):
|
|
99
|
+
rotate = square_pixels(meta["video"]) + "," + rotate
|
|
100
|
+
note(square_pixels_note(meta["video"]))
|
|
101
|
+
cmd = ffmpeg_base() + ["-i", args.input, "-vf", with_cfr(rotate, meta, args.fps), "-map", "0:v:0"]
|
|
102
|
+
if has_audio:
|
|
103
|
+
cmd += ["-map", f"0:a:{args.audio_stream}?"]
|
|
104
|
+
cmd += video_args(meta, args.crf, args.preset)
|
|
105
|
+
cmd += cfr_args(meta, args.fps)
|
|
106
|
+
if has_audio:
|
|
107
|
+
cmd += aac_args()
|
|
108
|
+
else:
|
|
109
|
+
cmd += ["-an"]
|
|
110
|
+
dropped_streams = run_keeping_subtitles(cmd, output)
|
|
111
|
+
|
|
112
|
+
result = probe(output, role="output")
|
|
113
|
+
v = result["video"]
|
|
114
|
+
info(f"wrote {output} ({fmt_secs(result['duration'])}, {v['width']}x{v['height']}, degrees={args.degrees:g}, fit={args.fit})")
|
|
115
|
+
emit(output, dropped_non_av_streams=dropped_streams)
|
|
116
|
+
return 0
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
if __name__ == "__main__":
|
|
120
|
+
sys.exit(main())
|