A library for automatically generating and selecting video screenshots.
Project description
screenshotgenerator
This project aims to automate the selection of video screenshots. It employs ffmpeg
to generate a pool of screenshots then calls on two autogluon
machine learning models to score the screenshots in order to select the best of them. The first model attempts to determine whether a screenshot is focused while the second model attempts to determine whether the screenshot is a portrait (a close-up of one or more people). The focused model's score makes up 75% of the total score while the portrait model's score makes up 25% of the total score.
Dependencies
The following must be installed on your system:
- ffmpeg
- MediaInfo
- Microsoft Visual C++ Redistributable (if you're on Windows)
CUDA
autogluon
uses the CPU version of PyTorch, by default. If you have a CUDA-enabled GPU, installing the CUDA version of PyTorch may increase prediction speed:
pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 --extra-index-url https://download.pytorch.org/whl/cu116
Usage
CLI
Usage: screenshotgenerator [OPTIONS]
Options:
--end-time [%H:%M:%S] The time at which to stop taking
screenshots. Defaults to 95% of the video
duration, to exclude credits.
--ffmpeg-path TEXT The path to ffmpeg. Defaults to 'ffmpeg',
which requires ffmpeg to be in your path.
--models-directory TEXT The path to the directory containing the
autogluon models. If the directory doesn't
exist, the pretrained models will be
downloaded to this location. Defaults to a
subdirectory in the user data directory.
--pool-directory TEXT The directory in which to store the
screenshot pool. Defaults to the temporary
directory.
--pool-report-path TEXT A JSON file detailing the screenshot pool,
sorted by descending preference.
--pool-size INTEGER The size of the pool from which to select
screenshots. [default: 64]
--portrait-preference [mixed|noportrait|portrait]
Preference regarding portrait screenshots.
[default: portrait]
--screenshot-count INTEGER The number of screenshots to select.
[default: 4]
--screenshot-directory TEXT The directory into which to copy the
selected screenshots. [required]
--silent Suppress ffmpeg and autogluon output.
--start-time [%H:%M:%S] The time at which to start taking
screenshots. [default: 00:00:00]
--video-path TEXT The path to the video for which to generate
screenshots. [required]
--help Show this message and exit.
Example
screenshotgenerator --screenshot-directory "B:\Screenshots" --video-path "Z:\Encodes\A Great Movie (2023).mkv --portrait-preference mixed
Library
The library provides the following:
generate
functionPortraitPreference
enumScreenshot
class
Parameters
screenshot_directory: str
The directory into which to copy the selected screenshots.video_path: str
The path to the video for which to generate screenshots.end_time: datetime
The time at which to stop taking screenshots. Defaults to 95% of the video duration, to exclude credits.ffmpeg_path: str
The path toffmpeg
. Defaults to 'ffmpeg', which requiresffmpeg
to be in your path.models_directory: str
The path to the directory containing the autogluon models. Defaults to a subdirectory in the user data directory.
If the directory doesn't exist, the pretrained models will be downloaded to this location.pool_directory: str
The directory in which to store the screenshot pool. Defaults to the temporary directory.pool_size: int
The size of the pool from which to select screenshots. Defaults to 64.portrait_preference: PortraitPreference
Preference regarding portrait screenshots. Defaults toPortraitPreference.PORTRAIT
.screenshot_count: int
The number of screenshots to select. Defaults to 4.silent: bool
True to suppressffmpeg
andautogluon
output. Defaults to false.start_time: datetime
The time at which to start taking screenshots. Defaults to 00:00:00.
Returns
list[Screenshot]
The screenshot pool, sorted by descending preference.
Example
import screenshotgenerator
screenshots = screenshotgenerator.generate(
screenshot_directory=r"B:\Screenshots",
video_path=r"Z:\Encodes\A Great Movie (2023).mkv",
portrait_preference = screenshotgenerator.PortraitPreference.MIXED)
Project details
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
Hashes for screenshotgenerator-0.3.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 465a349e2d7205a02255e8ad7d2dfffc547d50e12fd69e0a5814b493a0fd9fdd |
|
MD5 | 57893189ed5edeb4cb27fe4624f837ba |
|
BLAKE2b-256 | 724c53e30547693f29be1428a23af5a05e035efedf5f528109c3e95e574bb97b |
Hashes for screenshotgenerator-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8be02a678d61470b0104e7175d8266256e31bdcc84b4ece3970c1a829231b01f |
|
MD5 | 0bd44a9f29bd03ba80ea2c69364dfed2 |
|
BLAKE2b-256 | 4ce5f1eebecc92a0cbfe148acbb8c039d5a8b4f9532b4bcc0fa5dc0cb097a09c |