Utility script that allows you to convert videos into preprocessed frames. The main use is preprocessing video data for Neural Networks.
python3 run.py -s "./data" -f 1
python3 run.py -s "./data" -f 1 --width 128 --height 128 -g
Credits to Homeless. (https://drive.google.com/drive/folders/1-nK8-WthZyB9G1O9MmAgD3h6CQsYkhUr)
- Make sure you have these dependencies installed on your computer:
- Python3 (3.8-3.9): https://www.python.org/downloads/
- Docker: https://docs.docker.com/engine/install/
- Build the container video with the following command (takes a minute & approx. 1.1GB):
python3 build.py- Process videos with the following command:
python3 run.py -s "your_folder_path_with_videos"When running the script, by default it will create a new folder out/ in your current working directory with all the frames split into separate folders.
There is also the option to run without Docker. However, this can cause errors as you need to manually install and setup opencv-python to work with cv2.VideoCapture().
Make sure to have Python3 installed (see above versions & download link).
- Set
IS_DOCKERtoFalsein variables.py - Create virtualenv (optional):
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip- Install dependencies:
pip install -r requirements/requirments.txt- Process videos with this command (same options as the other 'run.py' command):
python3 main.py -s "your_folder_path_with_videos"You can view all of the available options with the following command:
python3 run.py -hThe options include:
| Arguments | Description | Required | Default | Type |
|---|---|---|---|---|
| -s --src | The source folder | Yes | - | str |
| -d --dest | The destination folder | No | "./out" |
str |
| -f --fps | The output target fps | No | 10 |
int |
| --width | The output frame width. If not provied, the width will not be resized | No | None |
int |
| --height | The output frame height. If not provied, the height will not be resized | No | None |
int |
| --cxmin | The output frame crop min x. If not provided, the frames will not be cropped | No | None |
int |
| --cxmax | The output frame crop max x. If not provided, the frames will not be cropped | No | None |
int |
| --cymin | The output frame crop min y. If not provided, the frames will not be cropped | No | None |
int |
| --cymax | The output frame crop max y. If not provided, the frames will not be cropped | No | None |
int |
| -g --gray | Convert frames to grayscale | No | False |
bool |
| --silent | No console logging | No | False |
bool |
| -t --threads | The numbers of thread to create in order to process the videos (1 file == 1 thread) | No | 4 |
int |
| -ni --noinput | Prevent the script from asking user input | No | False |
bool |
| -h --help | Show the list of options | No | False |
bool |
To remove the container, simply run:
python3 clean.pyYou might see this error message in the console:
FATAL: exception not rethrown
For the moment just ignore it.
Feel free to open a issue if you encounter any problems. [Open Issue]
First make sure you have installed the dependencies found in the requirements.txt. (see Without Docker)
Test python formatting:
black --check .Test python linting:
flake8 .Python run test suite:
python3 -m unittest discover testsHere again there is a option to run the tests with or without Docker by toggling the IS_DOCKER boolean in variables.py.

