Per PLAN.md: ingest (yt-dlp) → probe/audio (ffmpeg) → STT (Parakeet v3 ONNX, faster-whisper, OpenAI-transcriptions/Groq hosted) → diarization (sherpa-onnx, optional pyannote) → shots (PySceneDetect + phash dedup) → vision (pydantic-ai over llama-server Qwen3-VL-4B or hosted DeepSeek) → synthesis (map-reduce VideoReport + grounded Q&A). Content-addressed per-stage cache, fully-local or fully-hosted profiles (VA_PROFILE), typer CLI with doctor, FastMCP server with six agent-facing tools, structured pydantic outputs throughout. 316 tests passed, 2 skipped (opt-in heavy tests); ruff clean. STT/diarization/shot/media/MCP-stdio paths verified with real models and fixtures; vision/synthesis covered by offline FunctionModel tests (no llama-server available in-session). See README.md for usage and limitations.
221 lines
7.7 KiB
Python
221 lines
7.7 KiB
Python
"""Offline tests for the deterministic Markdown report renderer."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from video_analyse.models import (
|
|
Highlight,
|
|
Segment,
|
|
Shot,
|
|
ShotDescription,
|
|
SpeakerTurn,
|
|
Transcript,
|
|
VideoReport,
|
|
)
|
|
from video_analyse.report import format_timestamp, render_markdown
|
|
|
|
|
|
@pytest.fixture
|
|
def report() -> VideoReport:
|
|
"""A fully-populated report exercising every rendered section."""
|
|
transcript = Transcript(
|
|
language="en",
|
|
duration=95.0,
|
|
backend="parakeet",
|
|
model="nemo-parakeet-tdt-0.6b-v3",
|
|
segments=[
|
|
Segment(start=0.0, end=5.5, text=" Hello and welcome to the demo. ", speaker="S1"),
|
|
Segment(start=65.25, end=70.0, text="Let us look\nat the results.", speaker="S2"),
|
|
Segment(start=70.0, end=72.0, text="Any questions?"),
|
|
],
|
|
speaker_turns=[
|
|
SpeakerTurn(start=0.0, end=5.5, speaker="S1"),
|
|
SpeakerTurn(start=65.25, end=72.0, speaker="S2"),
|
|
],
|
|
)
|
|
shots = [
|
|
Shot(
|
|
index=0,
|
|
start=0.0,
|
|
end=15.4,
|
|
keyframe=Path("/media/keyframes/000.jpg"),
|
|
phash="8000000000000000",
|
|
transcript_slice="Hello and welcome to the demo.",
|
|
description=ShotDescription(
|
|
summary="Title slide on a blue background.",
|
|
on_screen_text="DEMO 2026",
|
|
shot_type="screen",
|
|
notable_objects=["slide"],
|
|
setting="studio",
|
|
),
|
|
),
|
|
Shot(
|
|
index=1,
|
|
start=15.4,
|
|
end=95.0,
|
|
keyframe=Path("/media/keyframes/001.jpg"),
|
|
description=ShotDescription(
|
|
summary="Presenter standing at a whiteboard.",
|
|
shot_type="medium",
|
|
people=["Alice"],
|
|
),
|
|
),
|
|
]
|
|
return VideoReport(
|
|
source="/media/sample.mp4",
|
|
title="Demo report",
|
|
duration=95.0,
|
|
summary="A short demo about testing.\nIt covers two topics.",
|
|
topics=["testing", "demo"],
|
|
people=["Alice", "Bob"],
|
|
highlights=[
|
|
Highlight(start=65.25, end=70.0, description="[01:05] Results are shown."),
|
|
Highlight(start=0.0, end=5.5, description="Intro and agenda."),
|
|
],
|
|
shots=shots,
|
|
transcript=transcript,
|
|
metadata={"format": "mp4"},
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("seconds", "expected"),
|
|
[
|
|
(0.0, "00:00"),
|
|
(5.9, "00:05"),
|
|
(65.25, "01:05"),
|
|
(599.0, "09:59"),
|
|
(3599.9, "59:59"),
|
|
(3661.0, "61:01"),
|
|
(-3.0, "00:00"),
|
|
(float("nan"), "00:00"),
|
|
(float("inf"), "00:00"),
|
|
],
|
|
)
|
|
def test_format_timestamp_renders_mm_ss(seconds: float, expected: str) -> None:
|
|
assert format_timestamp(seconds) == expected
|
|
|
|
|
|
def test_render_markdown_has_the_expected_sections_in_order(report: VideoReport) -> None:
|
|
markdown = render_markdown(report)
|
|
headings = [
|
|
"# Demo report",
|
|
"## Summary",
|
|
"## Highlights",
|
|
"## Shot-by-shot",
|
|
"## Transcript",
|
|
]
|
|
positions = [markdown.index(heading) for heading in headings]
|
|
assert positions == sorted(positions)
|
|
assert markdown.startswith("# Demo report\n")
|
|
assert markdown.endswith("\n") and not markdown.endswith("\n\n")
|
|
|
|
|
|
def test_render_markdown_renders_media_facts_and_summary(report: VideoReport) -> None:
|
|
markdown = render_markdown(report)
|
|
assert "- **Source:** `/media/sample.mp4`" in markdown
|
|
assert "- **Duration:** 01:35" in markdown
|
|
assert "- **Language:** en" in markdown
|
|
assert "- **Transcript:** parakeet (nemo-parakeet-tdt-0.6b-v3)" in markdown
|
|
assert "A short demo about testing. It covers two topics." in markdown
|
|
assert "- **Topics:** testing, demo" in markdown
|
|
assert "- **People:** Alice, Bob" in markdown
|
|
|
|
|
|
def test_render_markdown_renders_highlights_with_mmss(report: VideoReport) -> None:
|
|
markdown = render_markdown(report)
|
|
assert "- **[01:05-01:10]** [01:05] Results are shown." in markdown
|
|
assert "- **[00:00-00:05]** Intro and agenda." in markdown
|
|
|
|
|
|
def test_render_markdown_renders_shot_headings_and_descriptions(report: VideoReport) -> None:
|
|
markdown = render_markdown(report)
|
|
assert "### Shot 0 — [00:00-00:15]" in markdown
|
|
assert "### Shot 1 — [00:15-01:35]" in markdown
|
|
assert "- **Type:** screen" in markdown
|
|
assert "- **Summary:** Title slide on a blue background." in markdown
|
|
assert "- **On-screen text:** DEMO 2026" in markdown
|
|
assert "- **Objects:** slide" in markdown
|
|
assert "- **Setting:** studio" in markdown
|
|
assert "- **People:** Alice" in markdown
|
|
assert "- **Transcript:** Hello and welcome to the demo." in markdown
|
|
|
|
|
|
def test_render_markdown_links_keyframes_relative_to_the_document(report: VideoReport) -> None:
|
|
markdown = render_markdown(report, keyframes_relpath=Path("assets/keyframes"))
|
|
assert "" in markdown
|
|
assert "" in markdown
|
|
assert "/media/keyframes" not in markdown
|
|
|
|
|
|
def test_render_markdown_keeps_the_shots_keyframe_subdirectory(report: VideoReport) -> None:
|
|
"""Namespaced keyframes stay linked: keyframes/<shots-key>/shot-N.jpg."""
|
|
report.shots[0].keyframe = Path("/media/keyframes/0123456789ab/000.jpg")
|
|
markdown = render_markdown(report, keyframes_relpath=Path("keyframes"))
|
|
assert "" in markdown
|
|
|
|
|
|
def test_render_markdown_defaults_to_bare_keyframe_filenames(report: VideoReport) -> None:
|
|
markdown = render_markdown(report)
|
|
assert "" in markdown
|
|
assert "/media/keyframes" not in markdown
|
|
|
|
|
|
def test_render_markdown_dot_relative_keyframes_are_clean(report: VideoReport) -> None:
|
|
markdown = render_markdown(report, keyframes_relpath=Path("."))
|
|
assert "" in markdown
|
|
|
|
|
|
def test_render_markdown_renders_the_speaker_labelled_transcript(report: VideoReport) -> None:
|
|
markdown = render_markdown(report)
|
|
appendix = markdown.split("## Transcript", 1)[1]
|
|
assert "**[00:00] S1:** Hello and welcome to the demo." in appendix
|
|
assert "**[01:05] S2:** Let us look at the results." in appendix
|
|
assert "**[01:10]** Any questions?" in appendix
|
|
|
|
|
|
def test_render_markdown_handles_empty_sections() -> None:
|
|
empty = VideoReport(
|
|
source="/media/empty.mp4",
|
|
duration=1.0,
|
|
summary="",
|
|
topics=[],
|
|
people=[],
|
|
highlights=[],
|
|
shots=[],
|
|
)
|
|
markdown = render_markdown(empty)
|
|
assert markdown.startswith("# empty.mp4\n")
|
|
assert "No summary available." in markdown
|
|
assert "- **Topics:** none identified" in markdown
|
|
assert "- **People:** none identified" in markdown
|
|
assert "No highlights were identified." in markdown
|
|
assert "No shots were detected." in markdown
|
|
assert "No transcript available." in markdown
|
|
|
|
|
|
def test_render_markdown_marks_undescribed_shots() -> None:
|
|
report = VideoReport(
|
|
source="/media/sample.mp4",
|
|
title="Sparse",
|
|
duration=10.0,
|
|
summary="Sparse report.",
|
|
topics=["t"],
|
|
people=[],
|
|
highlights=[],
|
|
shots=[Shot(index=3, start=2.0, end=8.0)],
|
|
)
|
|
markdown = render_markdown(report)
|
|
assert "### Shot 3 — [00:02-00:08]" in markdown
|
|
assert "- **Description:** no visual description available" in markdown
|
|
|
|
|
|
def test_render_markdown_is_deterministic(report: VideoReport) -> None:
|
|
first = render_markdown(report, keyframes_relpath=Path("keyframes"))
|
|
second = render_markdown(report, keyframes_relpath=Path("keyframes"))
|
|
assert first == second
|
|
assert first.count("\n") == second.count("\n")
|