This release is a pre-release and may not be stable for production use.
Video Dataset
This is a python library to create a video dataset. The project is inspired from Video-Dataset-Loading-Pytorch but with a lot of additional features and modifications.
The goal is to have a very moldable and customizable video dataset that can be reused in all possible video dataset situations.
Installation
pip install video-dataset
Dataset Structures
The General dataset structure is the one specified below. One global directory where there is a sub directory for the videos and another one for the annotations, ids files are optional.
- your-dataset
- - videos
- - - video-1
- - - video-2
- - - ...
- - annotations
- - - video-1
- - - video-2
- - - ...
training_ids.txt
testing_ids.txt
validation_ids.txt
An important thing is that each the video must be named (except for the extension) the same way as it's corresponding annotation in order for the VideoDataset to correctly detect it.
When defining a video-dataset multiple components need to be defined:
- videos_dir: The path were the videos are stored.
- annotations_dir The path were the annotations are stored.
- segment_size: The desired number of frames per video $*_1$.
- video_processor: Will be in charge to read the video $*_2$.
- annotations_processor: Will be in charge to read the annotations $*_2$.
$*_1$: Suppose your videos contain 100 frames and you put segment_size=10; from each video you'll have 10 sub videos of 10 frames each. You an also consider the whole video by putting segment_size=-1.
$*_2:$ In the package, a number of predefined video and annotations processor are available and cover practically any case you can encounter, but it is also possible to defined a custom video or annotation processor and use it with the video-dataset.
Video Processors
The Dataset supports multiple video formats, all the supported formats are presented below:
Raw Video Representation
In this format each element in the videos directory need to be a video file (with any of the supported video extensions).
For example:
- your-dataset
- - videos
- - - video-1.mp4
- - - video-2.mp4
- - - ...
- - annotations
- - - ...
The corresponding VideoDataset:
from video_dataset import VideoDataset
from video_dataset.video import VideoFromVideoFile
from video_dataset.annotations import AnnotationsFromFrameLevelTxtFileAnnotations
video_processor: Type[Video]
annotations_processor: Type[Annotations]
dataset = VideoDataset(
videos_dir="./dataset/videos",
annotations_dir="./dataset/annotations",
segment_size=32,
video_processor=VideoFromVideoFile,
annotations_processor=AnnotationsFromFrameLevelTxtFileAnnotations,
)
Frame Level Video Representation
Having the elements of the videos directory as raw videos can be quite slow when loading the videos, an alternative approach is that each element of the videos directory is a directory it self with the name of the video and the content of the directory is images where each image represent a single frame of the video.
- your-dataset
- - videos
- - - video-1
- - - - img_00001.jpg
- - - - img_00002.jpg
- - - - img_00003.jpg
- - - - ...
- - - video-2
- - - ...
- - annotations
- - - ...
The corresponding VideoDataset:
from video_dataset import VideoDataset
from video_dataset.video import VideoFromVideoFramesDirectory
from video_dataset.annotations import AnnotationsFromFrameLevelTxtFileAnnotations
video_processor: Type[Video]
annotations_processor: Type[Annotations]
dataset = VideoDataset(
videos_dir="./dataset/videos",
annotations_dir="./dataset/annotations",
segment_size=32,
video_processor=VideoFromVideoFramesDirectory,
annotations_processor=AnnotationsFromFrameLevelTxtFileAnnotations,
)
This significantly reduces video loading time but at the cost of storage space.
Custom Processor
In order to create a custom video processor you basically need to create a class that implements the Video class as follow:
from video_dataset.video import Video
class CustomVideoProcessor(Video):
def __init__(self, videos_dir_path: str, id: str):
...
def get_id(self):
return self.id
def __len__(self):
...
def __getitem__(self, index: int | slice):
"""
Return the corresponding video frame(s) requested by the index.
"""
...
Annotations Processors
Your video annotations files can be in multiple formats.
Whole Video Annotations
A single csv or txt file describing the classes / labels of all the videos.
- Implementation. Coming Soon..
Frame By Frame Annotations
Each video have a corresponding txt file where each line in the file correspond to a class / label / annotation of a frame in the video.
eating
eating
eating
eating
eating
eating
eating
...
The corresponding VideoDataset:
from video_dataset import VideoDataset
from video_dataset.video import VideoFromVideoFile
from video_dataset.annotations import AnnotationsFromFrameLevelTxtFileAnnotations
video_processor: Type[Video]
annotations_processor: Type[Annotations]
dataset = VideoDataset(
videos_dir="./dataset/videos",
annotations_dir="./dataset/annotations",
segment_size=32,
video_processor=VideoFromVideoFile,
annotations_processor=AnnotationsFromFrameLevelTxtFileAnnotations,
)
Segment Level Annotations
Each video has a corresponding csv file with the following structure:
| acton | starting-timestamp | duration |
|---|---|---|
| eating | 0 | 4000 |
| dancing | 4000 | 6000 |
| eating | 10000 | 8000 |
The corresponding VideoDataset:
from video_dataset import VideoDataset
from video_dataset.video import VideoFromVideoFile
from video_dataset.annotations import AnnotationsFromSegmentLevelCsvFileAnnotations
video_processor: Type[Video]
annotations_processor: Type[Annotations]
dataset = VideoDataset(
videos_dir="./dataset/videos",
annotations_dir="./dataset/annotations",
segment_size=32,
video_processor=VideoFromVideoFile,
annotations_processor=AnnotationsFromSegmentLevelCsvFileAnnotations,
)
Custom Processor
In order to create a custom annotations processor you basically need to create a class that implements the Annotations class as follow:
from video_dataset.annotations import Annotations
class CustomAnnotationsProcessor(Annotations):
def __init__(self, annotations_dir_path: str, id: str):
...
def get_id(self):
return self.id
@abstractmethod
def __getitem__(self, index: int | slice):
"""
Get the annotation(s) of the video file corresponding to the given frame(s) index / indices.
Note that even if an index is given the annotations will be returned in a batch format (Number of frames, Height, Width, Channels).
"""
...
Contributions
All contributions are welcome, just open a pull request.
Release files for video-dataset 0.3.0.dev20250316222650
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| video_dataset-0.3.0.dev20250316222650.tar.gz | 11.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| video_dataset-0.3.0.dev20250316222650-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.5 kB
Release files / video_dataset-0.3.0.dev20250316222650.tar.gz
| Download URL | video_dataset-0.3.0.dev20250316222650.tar.gz |
|---|---|
| Size | 11.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3425c4f4af9dea9fc75dbad9876f1028b4f21b2fc662a561a45dc3bd62e03e32
|
|
BLAKE2b-256 checksum How to use checksums |
151a6b8b367383711ca294d8a2f5aa99687b89af679acc6e94be9eacf36c71cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.1 CPython/3.12.9 Linux/6.8.0-1021-azure
|
Release files / video_dataset-0.3.0.dev20250316222650-py3-none-any.whl
| Download URL | video_dataset-0.3.0.dev20250316222650-py3-none-any.whl |
|---|---|
| Size | 12.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
996e4938653c5c78933fe1a78ef9a909fe471b3b368628688cc7b466a9754496
|
|
BLAKE2b-256 checksum How to use checksums |
97cff3e46775e3512852a4a83bdb4dd8f0eeae550f9092db78e1a909411bb966
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.1 CPython/3.12.9 Linux/6.8.0-1021-azure
|