PEACE is a Python-based automated video clipping tool designed to streamline the process of extracting highlights from videos. Whether you're a gamer looking to create montages, a content creator producing highlights, or simply someone who wants to save memorable moments, PEACE provides an efficient, easy-to-use solution.
- Automatic Frame Extraction: Extracts frames from video at specific timestamps.
- Customizable Settings: Allows you to set parameters for precision.
- Fast and Lightweight: Optimized for performance to minimize CPU and GPU usage.
- Supports Multiple Formats: Compatible with a variety of video formats.
-
Clone the repository:
git clone https://github.com/NakshatraSirohi/PEACE.git cd PEACE -
Install the dependencies:
pip install requirements.txt
-
Run the script:
cd Script python3 main.py
This script automates the process of detecting kills in a gaming video, grouping timestamps, and extracting clips around those timestamps. It uses OpenCV for image processing, FFmpeg for video manipulation, and Python for data handling.
- os: Handles file and directory operations.
- cv2: Used for image processing and template matching.
- ffmpeg: Executes video processing tasks like frame extraction and clipping.
- ast: Parses string representations of Python objects.
- datetime: To get current datetime stamp for output folder.
PEACE/
│
├── Script/ # The main script
| ├── KillFeed/ # Folder containing kill feed template images
│ | └── kill_feed_template1.png # Example kill feed template
│ | └── kill_feed_template2.png # Example kill feed template
| ├── main.py
| ├── createDir.py
| ├── screenshotting.py
| ├── scanning.py
| ├── timeGrouping.py
| └── clipping.py
|
├── Test Sample/
| ├── Base_Directory/
| | ├── screenshots/
| | ├── clips/
| | └── grouping.txt
| |
| ├── KillFeed/
| └── testVideo.mp4
|
└── requirements.txt # Required dependencies
Base_Directory/ # Output directory (named after input video)
├── screenshots/ # Folder containing extracted and cropped frames
│ └── frame_00001.png # Example screenshot
│ └── frame_00002.png # Example screenshot
│ └── ... # More frames
|
├── clips/ # Folder containing extracted video clips
| └── gameplay_clip1.mp4 # Example clip
| └── gameplay_clip2.mp4 # Example clip
| └── ... # More clips
|
└── grouping.txt # File listing grouped kill timestamps
- Purpose: Creates a unique directory based on the current timestamp for storing output files.
- Inputs:
- Nothing
- Outputs:
- Returns the path of the newly created directory.
- Purpose: Extracts screenshots from the video at a defined interval, crops the kill feed area, and saves the frames.
- Inputs:
original_video_location(str): Full path to the input video.outputDir(str): Directory where screenshots will be saved.
- Outputs:
- Saves the screenshots in a subfolder named
screenshots.
- Saves the screenshots in a subfolder named
- Purpose: Identifies timestamps of kills in the extracted screenshots using template matching.
- Inputs:
outputDir(str): Directory containing the screenshots.start_time(int): Starting time of the video to calculate absolute kill times.fps="1"(str): FPS at which the video was screenshotted.
- Outputs:
- Returns a list of timestamps where kills were detected.
- Details:
- Loads kill feed templates from a predefined folder (
KillFeed), which must be in the same directory as the script.
- Loads kill feed templates from a predefined folder (
- Purpose: Groups kill timestamps into intervals if they occur within 20 seconds of each other.
- Inputs:
outputDir(str): Directory for saving grouped intervals.input_time(list): List of kill timestamps.
- Outputs:
- Saves grouped intervals to a file named
grouping.txt.
- Saves grouped intervals to a file named
- Purpose: Extracts video clips around the grouped kill timestamps.
- Inputs:
outputDir(str): Directory containing grouping results.original_video_location(str): Full path to the input video.
- Outputs:
- Saves clips in a subfolder named
clips.
- Saves clips in a subfolder named
-
Prepare Kill Feed Templates:
- Place kill feed template images in a folder named
KillFeedin the same directory as the script. - Ensure templates are in
.pngformat.
- Place kill feed template images in a folder named
-
Run the Script:
- Execute the script and provide inputs when prompted:
- Path to the input video.
- Path to output directory.
- Execute the script and provide inputs when prompted:
-
Outputs:
screenshots: Folder containing extracted and cropped frames.grouping.txt: File listing grouped kill timestamps.clips: Folder containing video clips around kill events.- All of the above will be created in the base (output) directory.
-
Example Workflow:
- Input video:
gameplay.mp4. - Kill feed templates placed in
KillFeedfolder. - Start time: 60 seconds, End time: 300 seconds.
- Output structure:
gameplay/screenshots: Contains cropped frames.gameplay/grouping.txt: Lists kill groups.gameplay/clips: Contains MP4 files for each group.- Example: If
Group-1contains kill timestamps[65, 70, 85]:- A clip will be created from
65 - 5 = 60 secondsto85 + 5 = 90 secondsin the original video.
- A clip will be created from
- Input video:
- The script skips screenshots that fail to load and logs errors with filenames.
- If FFmpeg operations fail, the script suppresses errors to prevent termination.
- Change Detection Threshold: Modify the
max_val >= 0.75condition inscanningto adjust sensitivity. - Change Time Buffer for Clipping: Modify the
start_time - 5andend_time + 5logic inclipping.py.
- Python 3.x
- OpenCV (
cv2) - FFmpeg library
- Required Python modules (
os,time,ast)
- Ensure FFmpeg is installed and accessible via the system PATH.
- The
KillFeedfolder must be in the same directory as the script for proper functioning. - I'm actively working to enhance this script and add more features for better usability and performance.