# Video Splitter
An interactive CLI tool for splitting, downloading, and re-encoding videos. Supports YouTube URLs, Google Drive links, and local files with guided timestamp entry.
Features
| Feature | Description |
|---|---|
| Multi-Source | YouTube, Google Drive, local files |
| Interactive | No CLI args, guided prompts |
| Timestamp Entry | Step-by-step clip definition |
| Re-encode | Convert to 1080p/720p or keep original |
| Smart Output | Auto-saves to organized folder |
| Standalone .exe | PyInstaller packaging supported |
Usage
bash
python video_splitter.pyInteractive Workflow
code
--- Step 1: Select Source ---
Choose video source:
1. YouTube URL
2. Google Drive Link
3. Local Video File
Enter choice (1-3): 1
--- Step 2: Enter URL ---
Enter YouTube URL: https://youtube.com/watch?v=xxx
✓ URL validated successfully
--- Step 3: Define Clips ---
How many clips do you want to extract? (1-5): 2
--- Clip 1 ---
Enter start time (HH:MM:SS): 00:01:30
Enter end time (HH:MM:SS): 00:03:45
Enter clip name: Intro Section
--- Clip 2 ---
Enter start time (HH:MM:SS): 00:05:00
Enter end time (HH:MM:SS): 00:07:30
Enter clip name: Main Content
--- Step 4: Export Options ---
Keep original resolution? (Y/N): Y
Or re-encode to: 1. 1080p 2. 720p
Processing clips...
✓ Clip 1 saved: Video Splitter by BPS/Video Title/Intro Section.mp4
✓ Clip 2 saved: Video Splitter by BPS/Video Title/Main Content.mp4Core Implementation
Source Validation
python
def validate_source(source: str) -> str:
if source.startswith(('http://', 'https://')):
if 'youtube.com' in source or 'youtu.be' in source:
return 'youtube'
elif 'drive.google.com' in source:
return 'google_drive'
else:
return 'web_url'
elif os.path.isfile(source):
return 'local_file'
else:
raise ValueError("Invalid source")Video Download (YouTube/Google Drive)
python
import yt_dlp
def download_video(url: str, output_dir: str) -> str:
ydl_opts = {
'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best',
'outtmpl': os.path.join(output_dir, '%(title)s.%(ext)s'),
'quiet': True,
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=True)
return ydl.prepare_filename(info)Video Splitting with FFmpeg
python
def split_video(input_path: str, start_time: str, end_time: str, output_path: str):
# Direct split (fast, loseless)
ffmpeg.input(input_path, ss=start_time, to=end_time).output(
output_path,
vcodec='copy', # Copy without re-encoding
acodec='copy'
).run(overwrite_output=True)Re-encoding Option
python
def split_with_encoding(input_path: str, start: str, end: str, output: str, resolution: str):
# Resolution mapping
resolutions = {
'1080p': '1920:1080',
'720p': '1280:720',
'480p': '854:480'
}
scale = resolutions.get(resolution, None)
ffmpeg.input(input_path, ss=start, to=end).filter(
'scale', scale
).output(
output,
vcodec='libx264',
crf=23,
preset='medium',
acodec='aac'
).run(overwrite_output=True)Output Organization
code
Video Splitter by BPS/
└── [Video Title]/
├── Intro Section.mp4
├── Main Content.mp4
├── Conclusion.mp4
└── (original file, if downloaded)Prerequisites
FFmpeg Installation
Windows: Download from gyan.dev and add to PATH
macOS: brew install ffmpeg
Linux: sudo apt install ffmpeg
yt-dlp for Online Videos
bash
pip install yt-dlpPyInstaller Packaging
bash
pip install pyinstaller
pyinstaller --onefile --name "VideoSplitter" video_splitter.pyOutput: dist/VideoSplitter.exe — works on any Windows machine.
Use Cases
- Tutorial extraction: Pull specific segments from long videos
- Backup local videos: Re-encode to save space
- YouTube clipping: Download and trim YouTube content
- Google Drive processing: Split videos shared via Drive
Architecture Feedback
Spotted a potential optimization or antipattern? Let me know.