A library for automatically generating and selecting video screenshots.
Project description
screenshotgenerator
This library 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 first model's score makes up 75% of the total score while the second 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 will increase prediction speeds:
pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 --extra-index-url https://download.pytorch.org/whl/cu116
Usage
Download and extract models.zip then execute the generate
function.
Parameters
models_directory: str
The path to themodels
directory extracted frommodels.zip
.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.pool_directory: str
The directory in which to store the screenshot pool. Defaults to the temp 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 surpressffmpeg
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(
models_directory=r"C:\Users\user\Downloads\models",
screenshot_directory=r"B:\screenshots",
video_path=r"B:\myvideo.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.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1903f26ca4baf463e08a8ca3fc73c832d58af8007af0c31900eb50e5b5418f6 |
|
MD5 | 85925fcf605db4fd0d41482920d1c210 |
|
BLAKE2b-256 | 4b269ed9728507589688d036bf5fb9bea7e2f28753e944719ff9155d4237fdc8 |
Hashes for screenshotgenerator-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 698e17068e5d997f32c0ebdf1ba284d27a07b425ab13ce7ac288a944d667783f |
|
MD5 | f399cd7782d68087f29afa6c61da89e4 |
|
BLAKE2b-256 | d315acebb15349488a8a7bf607c3fd1011ceffda45aeecb77196781d1c93534d |