Changed "prepare data on the fly" functionality (#2217)
* Added ability to upload meta information with video & some fixes * Added documentation for data on the fly preparation * Added ability to prepare meta information for video manually * fix * style: fix codacy issues * Refactoring * docs: add optional parameter * Add test * Add license header * Update CHANGELOG Co-authored-by: Boris Sekachev <boris.sekachev@yandex.ru>main
parent
e9552f84f3
commit
072482ffe8
@ -0,0 +1,35 @@
|
||||
# Data preparation on the fly
|
||||
|
||||
## Description
|
||||
Data on the fly processing is a way of working with data, the main idea of which is as follows:
|
||||
Minimum necessary meta information is collected, when task is created.
|
||||
This meta information allows in the future to create a necessary chunks when receiving a request from a client.
|
||||
|
||||
Generated chunks are stored in a cache of limited size with a policy of evicting less popular items.
|
||||
|
||||
When a request received from a client, the required chunk is searched for in the cache.
|
||||
If the chunk does not exist yet, it is created using a prepared meta information and then put into the cache.
|
||||
|
||||
This method of working with data allows:
|
||||
- reduce the task creation time.
|
||||
- store data in a cache of limited size with a policy of evicting less popular items.
|
||||
|
||||
## Prepare meta information
|
||||
Different meta information is collected for different types of uploaded data.
|
||||
### Video
|
||||
For video, this is a valid mapping of key frame numbers and their timestamps. This information is saved to `meta_info.txt`.
|
||||
|
||||
Unfortunately, this method will not work for all videos with valid meta information.
|
||||
If there are not enough keyframes in the video for smooth video decoding, the task will be created in the old way.
|
||||
|
||||
#### Uploading meta information along with data
|
||||
|
||||
When creating a task, you can upload a file with meta information along with the video,
|
||||
which will further reduce the time for creating a task.
|
||||
You can see how to prepare meta information [here](/utils/prepare_meta_information/README.md).
|
||||
|
||||
It is worth noting that the generated file also contains information about the number of frames in the video at the end.
|
||||
|
||||
### Images
|
||||
Mapping of chunk number and paths to images that should enter the chunk
|
||||
is saved at the time of creating a task in a files `dummy_{chunk_number}.txt`
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 42 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
@ -0,0 +1,29 @@
|
||||
# Simple command line for prepare meta information for video data
|
||||
|
||||
**Usage**
|
||||
```bash
|
||||
usage: prepare.py [-h] [-chunk_size CHUNK_SIZE] video_file meta_directory
|
||||
|
||||
positional arguments:
|
||||
video_file Path to video file
|
||||
meta_directory Directory where the file with meta information will be saved
|
||||
|
||||
optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
-chunk_size CHUNK_SIZE
|
||||
Chunk size that will be specified when creating the task with specified video and generated meta information
|
||||
```
|
||||
|
||||
**NOTE**: For smooth video decoding, the `chunk size` must be greater than or equal to the ratio of number of frames
|
||||
to a number of key frames.
|
||||
You can understand the approximate `chunk size` by preparing and looking at the file with meta information.
|
||||
|
||||
**NOTE**: If ratio of number of frames to number of key frames is small compared to the `chunk size`,
|
||||
then when creating a task with prepared meta information, you should expect that the waiting time for some chunks
|
||||
will be longer than the waiting time for other chunks. (At the first iteration, when there is no chunk in the cache)
|
||||
|
||||
**Examples**
|
||||
|
||||
```bash
|
||||
python prepare.py ~/Documents/some_video.mp4 ~/Documents
|
||||
```
|
||||
@ -0,0 +1,37 @@
|
||||
# Copyright (C) 2020 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
import argparse
|
||||
import sys
|
||||
import os
|
||||
|
||||
def get_args():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('video_file',
|
||||
type=str,
|
||||
help='Path to video file')
|
||||
parser.add_argument('meta_directory',
|
||||
type=str,
|
||||
help='Directory where the file with meta information will be saved')
|
||||
parser.add_argument('-chunk_size',
|
||||
type=int,
|
||||
help='Chunk size that will be specified when creating the task with specified video and generated meta information')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
def main():
|
||||
args = get_args()
|
||||
try:
|
||||
smooth_decoding = prepare_meta_for_upload(prepare_meta, args.video_file, None, args.meta_directory, args.chunk_size)
|
||||
print('Meta information for video has been prepared')
|
||||
|
||||
if smooth_decoding != None and not smooth_decoding:
|
||||
print('NOTE: prepared meta information contains too few key frames for smooth decoding.')
|
||||
except Exception:
|
||||
print('Impossible to prepare meta information')
|
||||
|
||||
if __name__ == "__main__":
|
||||
base_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
sys.path.append(base_dir)
|
||||
from cvat.apps.engine.prepare import prepare_meta, prepare_meta_for_upload
|
||||
main()
|
||||
Loading…
Reference in New Issue