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
import cv2
import numpy as np
from antidupe import Antidupe
from desplice import Desplice
from PIL import Image
Loading a Video and Processing it
# 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 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.1.tar.gz
.
File metadata
- Download URL: desplice-0.0.1.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64105e763dbfe4396cc2b6025ab80687b93f719a57b39fa1c8b992f42a727466 |
|
MD5 | 9e1a56ba9049505690fec2bfa3589b8e |
|
BLAKE2b-256 | 6e255d2b45c0346ce6f4b065c001806ba7676933e937b8c6be49ed2fd5a0d6a9 |
File details
Details for the file desplice-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: desplice-0.0.1-py3-none-any.whl
- Upload date:
- Size: 8.7 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 | 3d329e442df3962615b1918535a0ea205452741b2297308643f3f38fe48d7ef9 |
|
MD5 | 268cc3d276fe3020f83ea7a37738f4a3 |
|
BLAKE2b-256 | 17f6f311121f72c3cd93d5393500941551edb4e4ad345b721e501062918c1625 |