Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ venv/
/previews/
/renders/
/history/
/artifacts/

# Editors and operating systems
.idea/
Expand Down
35 changes: 30 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

**facut**(Fast AI Cut)是一款面向 AI Agent、自动化脚本与高级用户的非破坏性命令行视频编辑器。它使用稳定素材 ID、结构化工程、可组合子命令及统一 JSON 返回值,让复杂剪辑既能由人操作,也能可靠地被程序调用。

当前版本 `0.3.0` 已打通代理—精剪—声音—QC—多版本交付链路:原片/代理自动切换、片段级增量缓存、多视频轨合成、画面变换与停帧、完整音频处理、JSONL 渲染进度、自动 QC、素材分析、标记、命名序列、字幕模板及常驻 JSON-RPC 会话。Windows 单文件发行版内置 FFmpeg/FFprobe,不依赖系统 Python。
当前版本 `0.4.0` 在代理—精剪—声音—QC 链路上增加专业旅拍底座:混合设备摄取、相机/GPS/时区/HDR 元数据、内容哈希分析缓存、带证据和置信度的保守分类、单主序列多平台交付,以及从“临港两日”成片提炼的电影感中英双层标题模板。Windows 单文件发行版内置 FFmpeg/FFprobe,不依赖系统 Python。

## 安装

Expand Down Expand Up @@ -40,11 +40,11 @@ facut doctor
当前可执行的公共接口:

```text
facut init/import/inspect/help
facut init/import/ingest/inspect/help
facut timeline/clip/transition/effect/audio
facut proxy/analyze/qc/marker
facut subtitle/text
facut preview/render/sequence
facut preview/render/deliver/delivery-presets/sequence
facut project/history
facut undo/redo/run/serve/doctor
```
Expand Down Expand Up @@ -150,6 +150,18 @@ facut --project demo serve

它通过 stdin/stdout 交换逐行 JSON-RPC,支持 `ping`、`project.snapshot`、`timeline.show`、原子 `run` 和 `shutdown`,同一进程复用已载入工程。

## 专业旅拍摄取与素材理解

```powershell
facut ingest D:\JapanTrip --trip "日本旅行2026" --verify sha256 --proxy auto
facut --project 日本旅行2026 inspect <MEDIA_ID> --json
facut --project 日本旅行2026 analyze travel <MEDIA_ID> --save --json
```

`ingest` 递归导入手机、相机、运动相机、无人机、录音与字幕素材,逐文件流式计算 SHA-256,并可先查找同名/LRF 代理、缺失时生成 540p 代理。默认新建 3840×2160、48kHz 工程;也可配合全局 `--project` 写入已有工程。

FFprobe 元数据会保留旋转、VFR、创建时间、时区、时间码、相机厂商/型号、镜头、GPS、色彩空间和 HDR-PQ/HDR-HLG/Log 线索。`analyze travel` 第一版只根据路径和元数据产生可解释候选,每项含 `confidence` 与 `evidence`;文件夹名并不被当作画面事实。需要人物、动作、地点或镜头语义时会明确返回 `plugin_required`。同一内容哈希和参数的分析结果写入工程缓存,后续调用直接复用。

## 完整可运行示例

裁切并合并:
Expand Down Expand Up @@ -182,11 +194,13 @@ facut --project demo subtitle import captions.srt --track S1
facut --project demo subtitle shift S1 --offset +500ms
facut --project demo subtitle export S1 --format vtt --output captions.vtt
facut --project demo text add --text "临港两日" --at 1s --duration 3s --y 20%
facut --project demo text add --text "抬头,是更大的尺度" --subtitle "LOOK UP · THE SCALE CHANGES" --at 4s --duration 3s --template lingang-cinematic-panel
facut --project demo text add --text "再来" --subtitle "同一条雪道,重新滑下" --at 48s --duration 2s --template lingang-cinematic-mint
facut --project demo subtitle compile-ass --output render-text.ass
facut --project demo render --output subtitled.mp4
```

渲染和预览会自动将工程中的字幕与文字编译为临时 ASS 并烧录。`compile-ass` 仍可生成独立、可检查的 ASS 侧车文件。
渲染和预览会自动将工程中的字幕与文字编译为临时 ASS 并烧录。`compile-ass` 仍可生成独立、可检查的 ASS 侧车文件。临港系列模板不是简单的颜色预设:编译器会生成半透明圆角矢量面板、细描边、强调色竖线和独立主副标题图层,并按 1080p/4K 画布等比例缩放。内置 `lingang-cinematic-panel`、`lingang-cinematic-mint`、`lingang-cinematic-warm`、`lingang-day-card` 和 `lingang-main-title`;可用 `--accent-color` 覆盖强调色。软件不捆绑第三方字体文件,默认使用系统字体以避免授权问题。

背景音乐与原声混合:

Expand Down Expand Up @@ -241,7 +255,16 @@ facut text presets
facut --project demo text import-csv titles.csv --template documentary-lower-third
```

命名 sequence 保存时间线快照并共享素材/代理池,可在一个工程维护主片、精华版等交付版本。文字内置纪录片下三分之一、章节、歌曲标题和字幕底板模板,并支持阴影、半透明底、安全区、对齐和字距。
命名 sequence 保存时间线快照并共享素材/代理池,可在一个工程维护主片、精华版等交付版本。文字模板支持阴影、半透明底、安全区、对齐、字距和模板专属矢量图层。

一个主序列可一次生成横版、竖版与方形派生文件:

```bash
facut delivery-presets --json
facut --project demo deliver --preset youtube-4k-sdr --also bilibili-4k,shorts-9x16,community-1x1 --output-dir renders/delivery --hardware auto
```

YouTube 预设保留工程原帧率,标准帧率 4K SDR 使用 45Mbps、高帧率使用 68Mbps,输出 AAC 384kbps、BT.709、4:2:0 和 MP4 Fast Start。B站预设明确标记为 FACUT 创作者工作流默认值,不伪称平台官方上限。竖版输出当前使用确定性画面适配并发出警告;主体跟踪式自动重构图尚未实现。

### 当前明确限制

Expand All @@ -250,6 +273,8 @@ facut --project demo text import-csv titles.csv --template documentary-lower-thi
- 调整层当前接受单 FFmpeg 节点效果;像素化这种多节点效果暂不接受。
- 画面关键帧当前为线性 x/y/scale/rotation;光流补帧和高级稳定模型尚未实现。
- ASR 需要用户提供本地模型;歌曲识别需要本地指纹数据库插件。
- 旅拍语义分类目前以元数据/路径规则为确定性底座;视觉语义搜索、人物识别、故事生成和 B-roll 覆盖诊断仍需后续本地视觉索引插件。
- GPX/KML 路线动画、主体跟踪自动重构图、OpenTimelineIO/FCPXML 交换尚未实现。
- 增量缓存会对复杂工程安全降级为整片渲染;跨转场区间复用是后续优化。

## 开发与测试
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "facut"
version = "0.3.0"
version = "0.4.0"
description = "Fast AI Cut — a deterministic, agent-friendly command-line video editor"
readme = "README.md"
requires-python = ">=3.11"
Expand Down
2 changes: 1 addition & 1 deletion src/facut/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

__all__ = ["__version__"]

__version__ = "0.3.0"
__version__ = "0.4.0"
2 changes: 2 additions & 0 deletions src/facut/analysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
analyze_song_metadata,
transcribe_local,
)
from .travel import analyze_travel_metadata

__all__ = [
"analyze_beats",
"analyze_quality",
"analyze_scenes",
"analyze_song_metadata",
"analyze_travel_metadata",
"transcribe_local",
]
132 changes: 132 additions & 0 deletions src/facut/analysis/travel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
"""Explainable, conservative travel-footage classification primitives."""

from __future__ import annotations

from datetime import datetime
from pathlib import Path
from typing import Any

from facut.core.models import MediaTechnicalInfo


_TOKENS: dict[str, tuple[str, ...]] = {
"city": ("city", "城市", "街道", "street", "downtown"),
"attraction": ("景点", "museum", "博物馆", "天文馆", "temple", "古城"),
"transport": ("airport", "机场", "train", "高铁", "地铁", "drive", "自驾"),
"hotel": ("hotel", "酒店", "民宿", "room"),
"food": ("food", "美食", "餐厅", "restaurant", "早餐", "晚餐"),
"snow-sports": ("滑雪", "ski", "snowboard", "雪场"),
"aerial": ("drone", "航拍", "无人机", "dji mavic"),
"timelapse": ("timelapse", "time-lapse", "延时"),
"a-roll": ("口播", "talking", "interview", "旁白"),
"detail": ("detail", "细节", "特写", "closeup", "close-up"),
}


def analyze_travel_metadata(
path: str | Path, technical: MediaTechnicalInfo
) -> dict[str, Any]:
"""Return evidence-backed candidates without claiming visual recognition."""

source = Path(path).expanduser().resolve()
searchable = " ".join((source.name, *source.parts[-4:])).casefold()
searchable = searchable.replace("_", " ").replace("-", " ")
candidates: list[dict[str, Any]] = []
for label, tokens in _TOKENS.items():
matched = sorted({token for token in tokens if token.casefold() in searchable})
if matched:
candidates.append(
{
"dimension": "travel_category",
"label": label,
"confidence": 0.68,
"evidence": [{"type": "path_token", "value": item} for item in matched],
}
)

device = _device_candidate(technical)
if device:
candidates.append(device)
daypart = _daypart_candidate(technical.creation_time, technical.timezone_offset)
if daypart:
candidates.append(daypart)
if technical.dynamic_range != "unknown":
candidates.append(
{
"dimension": "dynamic_range",
"label": technical.dynamic_range,
"confidence": 0.98,
"evidence": [
{"type": "ffprobe", "field": "color_transfer", "value": technical.color_transfer}
],
}
)
return {
"source": str(source),
"method": "metadata-and-path-rules-v1",
"candidates": candidates,
"visual_semantics": {
"status": "plugin_required",
"limitation": "Scene meaning, people, actions, reactions and shot quality require a configured vision analyzer.",
},
"uncertainties": [
"Path-token labels describe user organization and are not proof of frame contents."
],
}


def _device_candidate(technical: MediaTechnicalInfo) -> dict[str, Any] | None:
description = " ".join(
item for item in (technical.camera_make, technical.camera_model) if item
)
normalized = description.casefold()
if not normalized:
return None
if any(token in normalized for token in ("mavic", "phantom", "inspire")):
label, confidence = "drone", 0.94
elif any(token in normalized for token in ("gopro", "insta360", "osmo action")):
label, confidence = "action-camera", 0.94
elif any(token in normalized for token in ("iphone", "pixel", "huawei", "xiaomi", "oppo", "vivo")):
label, confidence = "phone", 0.90
else:
label, confidence = "camera", 0.72
return {
"dimension": "capture_device",
"label": label,
"confidence": confidence,
"evidence": [{"type": "camera_metadata", "value": description}],
}


def _daypart_candidate(
creation_time: str | None, timezone_offset: str | None
) -> dict[str, Any] | None:
if not creation_time:
return None
try:
parsed = datetime.fromisoformat(creation_time.replace("Z", "+00:00"))
except ValueError:
return None
hour = parsed.hour
if 5 <= hour < 8:
label = "sunrise-window"
elif 8 <= hour < 17:
label = "day"
elif 17 <= hour < 20:
label = "sunset-window"
else:
label = "night"
reliable_timezone = parsed.tzinfo is not None or timezone_offset is not None
return {
"dimension": "daypart",
"label": label,
"confidence": 0.86 if reliable_timezone else 0.52,
"evidence": [
{
"type": "creation_time",
"value": creation_time,
"timezone_offset": timezone_offset,
}
],
"warning": None if reliable_timezone else "Timezone is missing; local daypart may be wrong.",
}
79 changes: 77 additions & 2 deletions src/facut/cli/analyze_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from __future__ import annotations

import json
import hashlib
import os
import tempfile
from pathlib import Path
from typing import Annotated, Any, Callable

Expand All @@ -13,13 +16,17 @@
analyze_quality,
analyze_scenes,
analyze_song_metadata,
analyze_travel_metadata,
transcribe_local,
)
from facut.cli.common import manager_for, public_error
from facut.responses import success_response
from facut.media.probe import probe_media


analyze_app = typer.Typer(help="Analyze quality, scenes, beats, speech, and song metadata.")
analyze_app = typer.Typer(
help="Analyze quality, scenes, beats, speech, travel metadata, and song metadata."
)


def _state(ctx: typer.Context):
Expand Down Expand Up @@ -53,12 +60,53 @@ def _emit_analysis(
analyzer: Callable[[Path], dict[str, Any]],
*,
save: bool,
cache_parameters: dict[str, Any] | None = None,
) -> None:
from facut.cli.main import emit

try:
path, media_id, manager = _resolve(ctx, target)
result = analyzer(path)
cache_key = None
cache_path = None
cache_hit = False
if media_id is not None and manager is not None:
asset = manager.require_document().find_media(media_id)
assert asset is not None
encoded = json.dumps(
{
"analysis": command,
"algorithm_version": 1,
"media_sha256": asset.sha256,
"parameters": cache_parameters or {},
},
sort_keys=True,
separators=(",", ":"),
).encode("utf-8")
cache_key = hashlib.sha256(encoded).hexdigest()
cache_path = manager.project_dir / "cache" / "analysis" / f"{cache_key}.json"
if cache_path is not None and cache_path.is_file():
result = json.loads(cache_path.read_text(encoding="utf-8"))
cache_hit = True
else:
result = analyzer(path)
if cache_path is not None:
cache_path.parent.mkdir(parents=True, exist_ok=True)
with tempfile.NamedTemporaryFile(
mode="w",
encoding="utf-8",
dir=cache_path.parent,
prefix=f".{cache_key}-",
suffix=".tmp",
delete=False,
) as stream:
json.dump(result, stream, ensure_ascii=False, indent=2)
stream.write("\n")
temporary = Path(stream.name)
os.replace(temporary, cache_path)
result = {
**result,
"cache": {"hit": cache_hit, "key": cache_key},
}
revision = None
if save:
if media_id is None or manager is None:
Expand Down Expand Up @@ -101,6 +149,7 @@ def scenes(
target,
lambda path: analyze_scenes(path, threshold=threshold, ffmpeg=state.config.tools.ffmpeg),
save=save,
cache_parameters={"threshold": threshold},
)


Expand All @@ -121,6 +170,7 @@ def quality(
ffprobe=state.config.tools.ffprobe,
),
save=save,
cache_parameters={},
)


Expand All @@ -137,6 +187,7 @@ def beats(
target,
lambda path: analyze_beats(path, ffmpeg=state.config.tools.ffmpeg),
save=save,
cache_parameters={},
)


Expand All @@ -154,6 +205,7 @@ def transcript(
target,
lambda path: transcribe_local(path, model_path=model, language=language),
save=save,
cache_parameters={"model": str(model), "language": language},
)


Expand All @@ -170,4 +222,27 @@ def song(
target,
lambda path: analyze_song_metadata(path, ffprobe=state.config.tools.ffprobe),
save=save,
cache_parameters={},
)


@analyze_app.command("travel")
def travel(
ctx: typer.Context,
target: str,
save: Annotated[bool, typer.Option("--save")] = False,
) -> None:
"""Classify travel metadata conservatively and expose missing vision capability."""

state = _state(ctx)
_emit_analysis(
ctx,
"analyze.travel",
target,
lambda path: analyze_travel_metadata(
path,
probe_media(path, ffprobe=state.config.tools.ffprobe),
),
save=save,
cache_parameters={},
)
Loading
Loading