feat(cli,core): #7 動画入力対応 — 色トラック (位置固定、色だけ時間変化)#144
Merged
Conversation
- 新規 `crates/core/src/color_track.rs`: `interpolate_color_track(track, t)` を提供。 端点 clamp / 単一サンプル / 空 / NaN 安全網を持つ純粋関数。Issue #7 の完了条件 「補間関数を単独でカバー」用にユニットテスト 8 件を併設。 - `AnimateOptions` に `color_tracks: Option<Vec<Vec<[u8; 3]>>>` を追加。 Some のとき `render_frame_with_params` の各 orb の `cluster.color` を `interpolate_color_track(tracks[cluster_idx], t)` で動的に上書きする。 Aquarelle 経路 (`render_frame_aquarelle`) でも同じ置換を行う。 - 既存 AnimateOptions / VideoOptions リテラル全箇所に `color_tracks: None` を追加。 WebGL / wasm 経路 (Web GUI) は静止画オンリーなので `color_tracks=None` 固定で 従来挙動とバイト一致。
入力が動画拡張子 (mp4 / webm / mov / mkv / m4v / avi) のとき動画経路へ分岐。
位置は固定 (先頭フレームの k=6 k-means)、色だけが時間で変わる orb を生成する。
出力長は --duration-ms で独立に決まり、入力動画の長さは色サンプル列の
サイズだけに効く (3 分動画 → 30 秒 orb なら入力色変化が 6 倍速で乗る)。
実装:
- 新規 `crates/cli/src/video_input.rs`:
- `is_video_path(path)`: 拡張子で動画を判定。
- `sample_video_frames(path, n)`: ffprobe で動画長取得 → ffmpeg を per-sample
で 1 回ずつ起動 (-ss T -frames:v 1) して N=20 枚を均等区間サンプリング。
一時ディレクトリは tempfile::TempDir で RAII クリーンアップ。
- `build_color_tracks(samples, k)`: 先頭フレームを「テンプレート」とし、
各サンプルを LAB ΔE76 距離で greedy マッチング → cluster あたり N 個の
色サンプル列を構築。LAB 変換は CLI 側で自前実装 (palette 依存追加なし)。
- `VideoInputError`: ffmpeg / ffprobe 不在、破損ファイル、0 フレーム等を
明示的なエラー variant で表現。
- `main.rs::run_video_input`: 動画入力経路を実装。template_clusters に
drop_dominant 相当のフィルタを cluster と tracks の両方に同時に適用して
index 整合を保つ。出力モードは PNG (t=0 1 枚) / mp4 / webm に対応、
それ以外は明示エラー。
- `VideoOptions.color_tracks` を pipe through し、render_video から
AnimateOptions.color_tracks に流し込む。
- 静止画入力経路 (`render_png` / `render_video_path` / `render_style_path` /
`render_variations`) は完全に従来挙動のまま (regression なし)。
ドキュメント:
- docs/overview.md に「Video input — color track」章を追加。
- docs/roadmap.md の項目 7 を完了マーク。
- CHANGELOG.md unreleased に feat(cli,core): #7 の記述を追加。
新規依存なし (tempfile / image は既存)。
…ctionFailed variant / VIDEO_FRAME_TAIL_EPSILON_S 命名 / 欠損サンプル警告
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
関連 Issue
closes #7
変更内容
core (
crates/core/src/color_track.rs新規 +animate.rs)interpolate_color_track(track, t)を新設。t∈[0,1] で sample 列の線形補間(端点 clamp)。NaN 防御込みAnimateOptions.color_tracks: Option<Vec<Vec<[u8;3]>>>を追加。Someのとき render 経路でcluster.colorの代わりに track 補間値を使用pack_render_data_for_webgl経路は影響なし(wasm 側はcolor_tracks: Noneで従来挙動)cli (
crates/cli/src/video_input.rs新規 +main.rs)is_video_path()で拡張子検出 (mp4/webm/mov/mkv/m4v/avi)、video なら新経路、image はそのままsample_video_frames(path, n): ffprobe で動画長取得 →ffmpeg -ss T -frames:v 1を per-sample N=20 回起動して均等区間で PNG 抽出build_color_tracks(samples, k=6): 先頭フレームから template_clusters 抽出 → 各 sample で k-means → LAB ΔE76 greedy マッチングで cluster ごとの色トラック構築tempfile::TempDirで RAII クリーンアップ受け入れ条件
orber --input video.mp4 --output orb.mp4 --duration-ms 30000で 30 秒 orb 動画 (入力長と独立) — スモークテスト 4s 入力 → 3s 出力で確認build_color_tracks_two_samples_color_changes)検証
cargo test --workspace: 179 件 PASS (新規 16 件)cargo clippy --workspace -- -D warnings: cleancargo build --release: OK新規依存
なし。tempfile/image は既存ワークスペース依存を流用。