A Python library designed to process video files by removing duplicate frames
Project description
Desplice
Desplice is a Python library designed to process video files by removing duplicate frames, still images, and certain transitions. This helps in deduplicating video content, making it more efficient for storage or further processing.
Features
- Heal: Drops duplicate frames from the output.
- Keep: Retains one instance of each duplicate frame in the output.
- Explode: Removes duplicate frames from the video output and returns separate clips for each splice.
Installation
To install Desplice, you can use pip:
pip install desplice
Usage
Below are some examples demonstrating how to use Desplice.
Importing the Library
from desplice import Desplice
Loading a Video and Processing it
Take note that in the input value may be a path to the target video or alternatively a list of frames list[np.ndarray]
that has already been captured/loaded.
# Initialize the Desplice class
desplice = Desplice(debug=True)
# Load a video file into memory
video_frames = desplice.load_video_to_memory('path_to_your_video.mp4')
# Process the video to deduplicate frames
result, is_slideshow = desplice.process(video_frames, mode='heal', show=True, show_breaks=True)
If show
is set to True
processing and results will be displayed using cv2.imshow()
.
If show_breaks
is set to True
one black frame will be inserted between each slice.
If debug
is set to True
measurements and detections will be returned to console.
Example of Different Modes:
Heal Mode
Removes the detected content from output entirely.
result, is_slideshow = desplice.process('path_to_your_video.mp4', mode='heal')
Keep Mode
Keeps 1 frame of the duplicated content in the output.
result, is_slideshow = desplice.process('path_to_your_video.mp4', mode='keep')
Explode Mode
Returns each segment inbetween each duplicated sequence as it's own sequence.
result, is_slideshow = desplice.process('path_to_your_video.mp4', mode='explode')
Results are returned in a nested tuple object:
(
(
[video-1, video-2, video-3...], # List of videos: list[list[np.ndarray]]
[still-1, still-2, still-3] # List of still images: list[np.ndarray]
),
slideshow # Is the video a slideshow: Bool
)
Deduplication weights can be passed to augment the behavior of the antidupe
module:
custom_thresholds = {
'ih': 0.0, # Image Hash
'ssim': 0.1, # SSIM
'cs': 0.02, # Cosine Similarity
'cnn': 0.03, # CNN
'dedup': 0.005 # Mobilenet
}
desplice = Desplice(thresholds=custom_thresholds)
Further information on using antidupe
can be found here
Class and Method Descriptions
Desplice
Methods
-
__init__(self, thresholds: dict = None, device: str = 'cpu', debug: bool = False)
: Initializes the Desplice class with optional threshold values, device, and debug mode. -
load_video_to_memory(file_path: str) -> list
: Loads a video from the given file path into memory. -
show_video_from_frames(frames: list)
: Displays a video from a list of frames. -
deduplicate_frames(self, frames: list) -> tuple
: Deduplicates frames from the input video and returns a tuple containing processed video frames and images. -
process(self, file_path_or_array: [str, list[np.ndarray]], mode: modes = 'heal', show: bool = False, show_breaks: bool = False) -> tuple
: Processes the video based on the specified mode and returns the processed result and a boolean indicating if the output is a slideshow.
License
This project is licensed under the Apache License, Version 2.0. See the LICENSE file for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file desplice-0.0.2.tar.gz
.
File metadata
- Download URL: desplice-0.0.2.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75efd6916e3ff8507cc2802f6c6ce3d72c0bf143a9441c6d0e842e2d82a345a2 |
|
MD5 | e2a591678dacb070887b3151684e028f |
|
BLAKE2b-256 | 0a2fabee874d70c50752141df728356b91233961d6aa7574fd4e6ffc2f505dbb |
File details
Details for the file desplice-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: desplice-0.0.2-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e004c11f93d17f9c0ca53a493baf72f784842a06fa1006b8f4ce83cf29cd32eb |
|
MD5 | f27db5a42719b819920f7084645bdaa7 |
|
BLAKE2b-256 | 87e203ee806da41f2c52836677409958d263747be316c72fe2f8e56e291ca0a8 |