#!/usr/bin/env python

"""gulp2_kinetics

Gulp a 20bn dataset that is specified using a JSON format and where the input
data are video files.

Usage:
    gulp2_kinetics [--videos_per_chunk <videos_per_chunk>]
                  [--num_workers <num_workers>]
                  [--image_size <image_size>]
                  [--shuffle]
                  [--shm_dir <shm_dir>]
                  <input_json> <videos_directory> <output_directory>
    gulp2_kinetics (-h | --help)
    gulp2_kinetics --version

Arguments:
    input_json:                             Input JSON file
    videos_directory:                       Base directory for video files
    output_directory:                       Output directory for GulpIO files

Options:
    -h --help                               Show this screen.
    --version                               Show version.
    --videos_per_chunk=<videos_per_chunk>   Number of videos in one chunk [default: 100]
    --num_workers=<num_workers>             Number of parallel processes [default: 4]
    --image_size=<image_size>               Size of smaller edge of resized frames [default: -1]
    --shuffle                               Shuffle the dataset before ingestion
    --shm_dir=<shm_dir>                     Temporary directory for bursting frames [default: /dev/shm]
"""

from docopt import docopt

from gulpio2.adapters import KineticsAdapter
from gulpio2.fileio import GulpIngestor

if __name__ == '__main__':
    arguments = docopt(__doc__)
    print(arguments)

    input_json = arguments['<input_json>']
    videos_path = arguments['<videos_directory>']
    output_folder = arguments['<output_directory>']
    videos_per_chunk = int(arguments['--videos_per_chunk'])
    num_workers = int(arguments['--num_workers'])
    img_size = int(arguments['--image_size'])
    shuffle = arguments['--shuffle']
    shm_dir = arguments['--shm_dir']

    adapter = KineticsAdapter(input_json, videos_path,
                              shuffle=shuffle,
                              frame_size=img_size,
                              shm_dir_path=shm_dir,
                              )
    ingestor = GulpIngestor(adapter, output_folder, videos_per_chunk,
                            num_workers=num_workers)
    ingestor()
