161 lines
4.6 KiB
Python
161 lines
4.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Video Processor Test CLI
|
|
|
|
Standalone testing tool for video analysis module.
|
|
|
|
Usage:
|
|
# Test audio-first strategy
|
|
python test_video_cli.py --input sample.mp4 --strategy audio
|
|
|
|
# Compare strategies (when direct is implemented)
|
|
python test_video_cli.py --input sample.mp4 --compare
|
|
|
|
# Output to JSON file
|
|
python test_video_cli.py --input sample.mp4 --output result.json
|
|
"""
|
|
|
|
import argparse
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Add parent directory to path for imports
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
|
|
from backend.video_processor import analyze_video
|
|
from backend.video_processor.utils import check_ffmpeg_installed
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(
|
|
description="Test video processing module independently"
|
|
)
|
|
parser.add_argument(
|
|
"--input",
|
|
"-i",
|
|
help="Path to input video file"
|
|
)
|
|
parser.add_argument(
|
|
"--strategy",
|
|
"-s",
|
|
choices=["audio", "direct"],
|
|
default="audio",
|
|
help="Analysis strategy (default: audio)"
|
|
)
|
|
parser.add_argument(
|
|
"--output",
|
|
"-o",
|
|
help="Path to output JSON file (default: print to console)"
|
|
)
|
|
parser.add_argument(
|
|
"--language",
|
|
"-l",
|
|
default="ja",
|
|
help="Video language code (default: ja)"
|
|
)
|
|
parser.add_argument(
|
|
"--compare",
|
|
action="store_true",
|
|
help="Compare both strategies (when available)"
|
|
)
|
|
parser.add_argument(
|
|
"--check-deps",
|
|
action="store_true",
|
|
help="Check if required dependencies are installed"
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
# Check dependencies (can run without --input)
|
|
if args.check_deps:
|
|
print("🔍 Checking dependencies...")
|
|
if check_ffmpeg_installed():
|
|
print("✅ FFmpeg is installed")
|
|
else:
|
|
print("❌ FFmpeg is NOT installed")
|
|
print(" Install: https://ffmpeg.org/download.html")
|
|
if not args.check_deps:
|
|
sys.exit(1)
|
|
|
|
try:
|
|
import openai
|
|
print("✅ OpenAI library is installed")
|
|
except ImportError:
|
|
print("❌ OpenAI library is NOT installed")
|
|
print(" Install: pip install openai")
|
|
if not args.check_deps:
|
|
sys.exit(1)
|
|
|
|
if args.check_deps:
|
|
return
|
|
|
|
# Validate input file is provided for analysis
|
|
if not args.input:
|
|
print("❌ Error: --input is required for video analysis")
|
|
print(" Use --check-deps to only check dependencies")
|
|
sys.exit(1)
|
|
|
|
if not Path(args.input).exists():
|
|
print(f"❌ Error: Video file not found: {args.input}")
|
|
sys.exit(1)
|
|
|
|
try:
|
|
# Run analysis
|
|
print(f"\n{'='*60}")
|
|
print(f"🎬 Video Processor Test CLI")
|
|
print(f"{'='*60}")
|
|
print(f"Input: {args.input}")
|
|
print(f"Strategy: {args.strategy}")
|
|
print(f"Language: {args.language}\n")
|
|
|
|
config = {
|
|
"language": args.language
|
|
}
|
|
|
|
result = analyze_video(
|
|
video_path=args.input,
|
|
strategy=args.strategy,
|
|
config=config
|
|
)
|
|
|
|
# Convert to dict
|
|
result_dict = result.to_dict()
|
|
|
|
# Output results
|
|
if args.output:
|
|
with open(args.output, "w", encoding="utf-8") as f:
|
|
json.dump(result_dict, f, ensure_ascii=False, indent=2)
|
|
print(f"\n✅ Results saved to {args.output}")
|
|
else:
|
|
print(f"\n{'='*60}")
|
|
print("📊 Analysis Results")
|
|
print(f"{'='*60}\n")
|
|
print(json.dumps(result_dict, ensure_ascii=False, indent=2))
|
|
|
|
# Print summary
|
|
print(f"\n{'='*60}")
|
|
print("📈 Summary")
|
|
print(f"{'='*60}")
|
|
print(f"Duration: {result.duration:.2f}s")
|
|
print(f"Segments: {len(result.segments)}")
|
|
print(f"Key Moments: {len(result.key_moments)}")
|
|
print(f"High Importance: {len(result.get_high_importance_segments())}")
|
|
|
|
# Show first few segments
|
|
if result.segments:
|
|
print(f"\n🎯 First 3 Segments:")
|
|
for i, seg in enumerate(result.segments[:3], 1):
|
|
print(f"\n {i}. [{seg.start_time:.1f}s - {seg.end_time:.1f}s]")
|
|
print(f" {seg.transcript}")
|
|
|
|
except Exception as e:
|
|
print(f"\n❌ Error: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
sys.exit(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|