A Python script that creates video previews by extracting and combining short clips from throughout a video file, perfect for creating quick "sampler" videos to preview content.
- Automatic FFmpeg Detection: Finds and lets you select from available FFmpeg installations
- Interactive Video Selection: Browse MP4 files with duration, size, and modification date information
- Customizable Preview Length: Choose clip duration (1-60 seconds) and total preview percentage (1-50%)
- Smart File Handling: Options to overwrite, skip, or rename existing output files
- High Quality Output: Uses optimized encoding settings (CRF 10, 320k audio bitrate)
- Automatic Cleanup: Removes temporary files after processing
- Python 3.6+
- FFmpeg (automatically detected or manually specified)
- Clone this repository:
git clone https://github.com/dataforge/create-video-preview.git
cd create-video-preview- Ensure FFmpeg is installed and accessible:
- Windows: Download from ffmpeg.org or install via package manager
- macOS:
brew install ffmpeg - Linux:
sudo apt install ffmpeg(Ubuntu/Debian) or equivalent for your distribution
python create_preview.pyThis will:
- Detect available FFmpeg installations
- Show all MP4 files in the current directory with metadata
- Let you select a video file
- Configure clip length and preview percentage
python create_preview.py path/to/video.mp4- Select Video: Choose from available MP4 files with duration info
- Set Clip Length: Default 10 seconds (1-60 seconds allowed)
- Choose Preview Percentage: Select what portion of the video to sample
- 5% of a 60-minute video = 3 minutes of preview (18 clips at 10 seconds each)
- 10% of a 30-minute video = 3 minutes of preview (18 clips at 10 seconds each)
- Output: Creates
[original_name] sampler.mp4
The script extracts clips evenly distributed throughout the video:
- Analysis: Gets video duration and calculates clip positions
- Extraction: Creates temporary clips at calculated intervals
- Concatenation: Combines clips into a single preview video
- Cleanup: Removes temporary files
For example, with a 60-minute video and 10% preview:
- Total preview time: 6 minutes
- With 10-second clips: 36 clips extracted
- Clips taken every ~100 seconds throughout the video
- Video Codec: H.264 (libx264) with CRF 10 (high quality)
- Audio Codec: AAC at 320k bitrate
- Naming:
[original_filename] sampler.mp4
- Validates FFmpeg installation and accessibility
- Checks video file existence and readability
- Handles file conflicts with user choices (overwrite/skip/rename)
- Provides clear error messages for common issues
- Uses FFmpeg's
-ss(seek) and-t(duration) parameters for precise clip extraction - Creates a concat file for efficient clip combination
- Temporary files use timestamps to avoid conflicts
- Cross-platform compatibility (Windows, macOS, Linux)
FFmpeg not found:
- Ensure FFmpeg is installed and in your system PATH
- The script will search common installation directories
- You can select from multiple detected installations
Video not processing:
- Check that the video file is a valid MP4
- Ensure sufficient disk space for temporary files
- Verify the video isn't corrupted or encrypted
Output quality issues:
- The script uses high-quality settings (CRF 10)
- For smaller files, increase CRF value in the code (line 230)
This project is open source. Feel free to modify and distribute as needed.