This application automatically extracts highlight moments from full-length basketball games by analyzing audio peaks. It identifies the most exciting moments based on crowd noise and commentator reactions while filtering out referee whistles.
- Automatic Highlight Detection: Finds exciting moments in basketball games based on audio peaks
- Referee Whistle Filtering: Uses frequency analysis to differentiate between whistles and genuine excitement
- Well-Distributed Highlights: Ensures at least 1 minute between highlights for better game coverage
- High-Quality Output: Downloads videos at the best available quality (up to 1080p)
- Customizable Parameters: Adjust the number of highlights, buffer durations, and more
- Highlight Compilation: Automatically combines individual clips into a single highlight reel
- Python 3.8+
- FFmpeg installed and available in your system path
- Internet connection for downloading YouTube videos
- Clone this repository:
git clone https://github.com/yourusername/basketball-highlights-extractor.git
cd basketball-highlights-extractor- Install the required dependencies:
pip install -r requirements.txt- Ensure FFmpeg is installed on your system:
- Windows: Download from FFmpeg website and add to PATH
- Mac:
brew install ffmpeg - Linux:
sudo apt install ffmpegor equivalent for your distribution
Run the main script with a YouTube URL of a basketball game:
python highlight_extractor.py --url "https://www.youtube.com/watch?v=YOUTUBE_VIDEO_ID" --num_highlights 10--url: YouTube URL of the basketball game (required)--num_highlights: Number of highlights to extract (default: 10)--pre_buffer: Seconds to include before the peak (default: 5)--post_buffer: Seconds to include after the peak (default: 5)--output: Output directory for highlights (default: "highlights")--compile: Whether to compile clips into a single video (default: True)
The script will:
- Download the YouTube video at the highest available quality (up to 1080p)
- Extract and analyze the audio track
- Identify the loudest moments, filter out referee whistles, and ensure at least 1 minute between highlights
- Extract video clips around those moments
- Optionally compile them into a single highlight video
Results will be saved in the specified output directory, including:
- Individual highlight clips
- Optional compilation video
- Audio analysis visualizations showing detected peaks and whistle filtering
- Video Downloading: Uses yt-dlp to download the YouTube video at high quality (up to 1080p)
- Audio Extraction: Extracts audio using FFmpeg
- Audio Analysis:
- Calculates audio energy over time
- Performs frequency analysis to detect and filter out referee whistles
- Enforces a minimum 1-minute separation between highlights for better distribution
- Finds and ranks the most significant non-whistle peaks
- Clip Extraction: Extracts video clips around those peaks using FFmpeg
- Compilation: Combines clips into a single highlight reel
MIT