41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from scripts.video_analysis.extract_keyframes import (
|
|
build_ffmpeg_scene_select_filter,
|
|
compute_phash,
|
|
dedupe_frames,
|
|
extract_keyframes,
|
|
)
|
|
|
|
|
|
def test_build_ffmpeg_scene_select_filter() -> None:
|
|
filter_str = build_ffmpeg_scene_select_filter(0.4)
|
|
assert "select=gt(scene\\,0.4)" in filter_str
|
|
|
|
|
|
def test_compute_phash_returns_string() -> None:
|
|
from PIL import Image
|
|
img = Image.new("RGB", (100, 100), color="red")
|
|
h = compute_phash(img)
|
|
assert isinstance(h, str)
|
|
assert len(h) >= 8
|
|
|
|
|
|
def test_dedupe_frames_keeps_unique() -> None:
|
|
hashes = ["aaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbb", "aaaaaaaaaaaaaaaa", "cccccccccccccccc"]
|
|
result = dedupe_frames(hashes, hamming_threshold=5)
|
|
assert result == [True, True, False, True]
|
|
|
|
|
|
def test_extract_keyframes_creates_output_dir(tmp_path: Path) -> None:
|
|
fake_video = tmp_path / "fake.mp4"
|
|
fake_video.write_bytes(b"fake")
|
|
with patch("subprocess.run") as mock_run:
|
|
mock_run.return_value = MagicMock(returncode=0, stdout="", stderr="")
|
|
result = extract_keyframes(fake_video, tmp_path / "frames", threshold=0.4)
|
|
assert result.is_ok()
|
|
assert (tmp_path / "frames").exists()
|