60 lines
1.6 KiB
Python
60 lines
1.6 KiB
Python
"""
|
|
Video Processing Module
|
|
|
|
Provides two strategies for analyzing video content:
|
|
1. Direct Analysis: Send video directly to Gemini 1.5 Pro
|
|
2. Audio-First: Extract audio → Whisper transcription → Text analysis
|
|
|
|
Usage:
|
|
from backend.video_processor import analyze_video
|
|
|
|
result = analyze_video(
|
|
video_path="input.mp4",
|
|
strategy="audio", # or "direct"
|
|
config={"language": "ja"}
|
|
)
|
|
"""
|
|
|
|
from .schemas import VideoAnalysisResult, VideoSegment, KeyMoment
|
|
from .utils import extract_audio, get_video_duration
|
|
|
|
__all__ = [
|
|
"analyze_video",
|
|
"VideoAnalysisResult",
|
|
"VideoSegment",
|
|
"KeyMoment",
|
|
"extract_audio",
|
|
"get_video_duration",
|
|
]
|
|
|
|
|
|
def analyze_video(
|
|
video_path: str,
|
|
strategy: str = "audio",
|
|
config: dict | None = None
|
|
) -> VideoAnalysisResult:
|
|
"""
|
|
Main entry point for video analysis.
|
|
|
|
Args:
|
|
video_path: Path to video file
|
|
strategy: "audio" or "direct"
|
|
config: Optional configuration dict
|
|
|
|
Returns:
|
|
VideoAnalysisResult object with segments and key moments
|
|
"""
|
|
if config is None:
|
|
config = {}
|
|
|
|
if strategy == "audio":
|
|
# Lazy import to avoid dependency issues when just checking deps
|
|
from .strategy_audio import AudioFirstStrategy
|
|
processor = AudioFirstStrategy(config)
|
|
return processor.analyze(video_path)
|
|
elif strategy == "direct":
|
|
# TODO: Implement in next sprint
|
|
raise NotImplementedError("Direct video analysis coming in next sprint")
|
|
else:
|
|
raise ValueError(f"Unknown strategy: {strategy}")
|