Video analysis: download, keyframes, transcripts, thumbnail grids and AI summaries of what's on screen.

0 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-video.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-video.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-video.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 Update README with live PyPI link c32f6df 1 year, 1 month ago History
pipeline.py · 3.3 KB · 109 lines
1#!/usr/bin/env python3
2"""
3Run complete video analysis pipeline
4"""
5
6import argparse
7import sys
8from pathlib import Path
9
10
11def run_pipeline(url, output_dir="output", skip_download=False, video_file=None):
12 """Run complete analysis pipeline."""
13 from .download_video import download_video
14 from .extract_keyframes import extract_keyframes
15 from .get_transcript import download_transcript
16 from .make_grid import create_thumbnail_sheet
17 from .analyze_visuals import analyze_grid
18 from .summarize import create_comprehensive_summary
19
20 output_path = Path(output_dir)
21 output_path.mkdir(exist_ok=True)
22
23 print("=" * 80)
24 print("DBBASIC VIDEO ANALYSIS PIPELINE")
25 print("=" * 80)
26
27 # Step 1: Download video
28 if not skip_download:
29 print("\n[1/6] Downloading video...")
30 video_file = str(output_path / "video.mp4")
31 if not download_video(url, video_file):
32 return 1
33 else:
34 print(f"\n[1/6] Using existing video: {video_file}")
35
36 # Step 2: Extract keyframes
37 print("\n[2/6] Extracting keyframes...")
38 keyframes_dir = str(output_path / "keyframes")
39 extract_keyframes(video_file, keyframes_dir)
40
41 # Step 3: Create thumbnail grid
42 print("\n[3/6] Creating thumbnail grid...")
43 grid_file = str(output_path / "thumbnail_grid.jpg")
44 create_thumbnail_sheet(keyframes_dir, grid_file)
45
46 # Step 4: Download transcript
47 print("\n[4/6] Downloading transcript...")
48 video_id = url.split('v=')[-1].split('&')[0] if 'v=' in url else url.split('/')[-1]
49 transcript_file = str(output_path / "transcript.json")
50 download_transcript(video_id, transcript_file)
51
52 # Step 5: Analyze visuals
53 print("\n[5/6] Analyzing visuals with AI...")
54 visual_analysis = str(output_path / "visual_analysis.txt")
55 analyze_grid(grid_file, visual_analysis)
56
57 # Step 6: Create comprehensive summary
58 print("\n[6/6] Creating comprehensive summary...")
59 summary_file = str(output_path / "comprehensive_summary.txt")
60 create_comprehensive_summary(transcript_file, visual_analysis, summary_file)
61
62 print("\n" + "=" * 80)
63 print("PIPELINE COMPLETE")
64 print("=" * 80)
65 print(f"\nOutput directory: {output_path}")
66 print(f" - Video: video.mp4")
67 print(f" - Keyframes: keyframes/")
68 print(f" - Thumbnail grid: thumbnail_grid.jpg")
69 print(f" - Transcript: transcript.json, transcript.txt")
70 print(f" - Visual analysis: visual_analysis.txt")
71 print(f" - Summary: comprehensive_summary.txt")
72
73 return 0
74
75
76def main():
77 parser = argparse.ArgumentParser(
78 description="Run complete video analysis pipeline"
79 )
80 parser.add_argument(
81 "url",
82 help="YouTube URL"
83 )
84 parser.add_argument(
85 "-o", "--output",
86 default="output",
87 help="Output directory (default: output)"
88 )
89 parser.add_argument(
90 "--skip-download",
91 action="store_true",
92 help="Skip download step (use existing video)"
93 )
94 parser.add_argument(
95 "--video",
96 help="Path to existing video file (requires --skip-download)"
97 )
98
99 args = parser.parse_args()
100
101 if args.skip_download and not args.video:
102 print("Error: --video required when using --skip-download", file=sys.stderr)
103 return 1
104
105 return run_pipeline(args.url, args.output, args.skip_download, args.video)
106
107
108if __name__ == "__main__":
109 sys.exit(main())