Skip to main content

PyNVVL: A Python wrapper for NVIDIA Video Loader (NVVL) with CuPy

Project description

PyNVVL

pypi-pynvvl-cuda80 pypi-pynvvl-cuda90 pypi-pynvvl-cuda91 GitHub license

PyNVVL is a thin wrapper of NVIDIA Video Loader (NVVL). This package enables you to load videos directoly to GPU memory and access them as CuPy ndarrays with zero copy. The pre-built binaries of PyNVVL include NVVL itself, so you do not need to install NVVL.

Requirements

  • CUDA 8.0, 9.0, or 9.1
  • Python 2.7.6+, 3.4.7+, 3.5.1+, or 3.6.0+
  • CuPy v4.0.0

Tested Environment

  • Ubuntu 16.04
  • Python 2.7.6+, 3.4.7+, 3.5.1+, and 3.6.0+
  • CUDA 8.0, 9.0, and 9.1

Install the pre-built binary

Please choose a right package depending on your CUDA version.

# [For CUDA 8.0]
pip install pynvvl-cuda80

# [For CUDA 9.0]
pip install pynvvl-cuda90

# [For CUDA 9.1]
pip install pynvvl-cuda91

Usage

import pynvvl
import matplotlib.pyplot as plt

# Create NVVLVideoLoader object
loader = pynvvl.NVVLVideoLoader(device_id=0, log_level='error')

# Show the number of frames in the video
n_frames = loader.frame_count('examples/sample.mp4')
print('Number of frames:', n_frames)

# Load a video and return it as a CuPy array
video = loader.read_sequence(
    'examples/sample.mp4',
    horiz_flip=True,
    scale_height=512,
    scale_width=512,
    crop_y=60,
    crop_height=385,
    crop_width=512,
    scale_method='Linear',
    normalized=True
)

print(video.shape)  # => (91, 3, 385, 512): (n_frames, channels, height, width)
print(video.dtype)  # => float32

# Get the first frame as numpy array
frame = video[0].get()
frame = frame.transpose(1, 2, 0)

plt.imshow(frame)
plt.savefig('examples/sample.png')

This video is flickr-2-6-3-3-5-2-7-6-5626335276_4.mp4 from the Moments-In-Time dataset.

Note that cropping is performed after scaling. In the above example, NVVL performs scaling up from 256 x 256 to 512 x 512 first, then cropping the region [60:60 + 385, 0:512]. See the following section to know more about the transformation options.

VideoLoader options

Please specify the GPU device id when you create a NVVLVideoLoader object. You can also specify the logging level with a argument log_level for the constructor of NVVLVideoLoader.

Wrapper of NVVL VideoLoader

    Args:
        device_id (int): Specify the device id used to load a video.
        log_level (str): Logging level which should be either 'debug',
            'info', 'warn', 'error', or 'none'.
            Logs with levels >= log_level is shown. The default is 'warn'.

Transformation Options

pynvvl.NVVLVideoLoader.read_sequence can take some options to specify the color space, the value range, and what transformations you want to perform to the video.

Loads the video from disk and returns it as a CuPy ndarray.

    Args:
        filename (str): The path to the video.
        frame (int): The initial frame number of the returned sequence.
            Default is 0.
        count (int): The number of frames of the returned sequence.
            If it is None, whole frames of the video are loaded.
        channels (int): The number of color channels of the video.
            Default is 3.
        scale_height (int): The height of the scaled video.
            Note that scaling is performed before cropping.
            If it is 0 no scaling is performed. Default is 0.
        scale_width (int): The width of the scaled video.
            Note that scaling is performed before cropping.
            If it is 0, no scaling is performed. Default is 0.
        crop_x (int): Location of the crop within the scaled frame.
            Must be set such that crop_y + height <= original height.
            Default is 0.
        crop_y (int): Location of the crop within the scaled frame.
            Must be set such that crop_x + width <= original height.
            Default is 0.
        crop_height (int): The height of cropped region of the video.
            If it is None, no cropping is performed. Default is None.
        crop_width (int): The width of cropped region of the video.
            If it is None, no cropping is performed. Default is None.
        scale_method (str): Scaling method. It should be either of
            'Nearest' or 'Lienar'. Default is 'Linear'.
        horiz_flip (bool): Whether horizontal flipping is performed or not.
            Default is False.
        normalized (bool): If it is True, the values of returned video is
            normalized into [0, 1], otherwise the value range is [0, 255].
            Default is False.
        color_space (str): The color space of the values of returned video.
            It should be either 'RGB' or 'YCbCr'. Default is 'RGB'.
        chroma_up_method (str): How the chroma channels are upscaled from
            yuv 4:2:0 to 4:4:4. It should be 'Linear' currently.
        out (cupy.ndarray): Alternate output array where place the result.
            It must have the same shape and the dtype as the expected
            output, and its order must be C-contiguous.

How to build

Build wheels using Docker:

Requirements:

  • Docker
  • nvidia-docker (v1/v2)
bash docker/build_wheels.sh

Setup development environment without Docker:

The setup.py script searches for necessary libraries.

Requirements: the following libraries are available in LIBRARY_PATH.

  • libnvvl.so
  • libavformat.so
  • libavcodec.so
  • libavutil.so

You can build libnvvl.so in the nvvl repository. Follow the instructions of nvvl library. The build directory must be in LIBRARY_PATH.

Other three libraries are available as packages in Ubuntu 16.04. They are installed under /usr/lib/x86_64-linux-gnu, so they must be in LIBRARY_PATH as well.

python setup.py develop
python setup.py bdist_wheel

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

pynvvl_cuda92-0.0.3a1-cp36-cp36m-manylinux1_x86_64.whl (804.7 kB view details)

Uploaded CPython 3.6m

pynvvl_cuda92-0.0.3a1-cp35-cp35m-manylinux1_x86_64.whl (800.3 kB view details)

Uploaded CPython 3.5m

pynvvl_cuda92-0.0.3a1-cp34-cp34m-manylinux1_x86_64.whl (803.1 kB view details)

Uploaded CPython 3.4m

pynvvl_cuda92-0.0.3a1-cp27-cp27mu-manylinux1_x86_64.whl (788.4 kB view details)

Uploaded CPython 2.7mu

File details

Details for the file pynvvl_cuda92-0.0.3a1-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pynvvl_cuda92-0.0.3a1-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 804.7 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.3

File hashes

Hashes for pynvvl_cuda92-0.0.3a1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 0c993ed0ce5f3d9c9b10601c74a2ea662302a81e4eac6c353184168694b613c5
MD5 99b68a9c6202accf1bd86c3794d984c9
BLAKE2b-256 271fb94706a922e91fa709ea97a02b380d569de3e76665a7987978faeaed9633

See more details on using hashes here.

File details

Details for the file pynvvl_cuda92-0.0.3a1-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pynvvl_cuda92-0.0.3a1-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 800.3 kB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.3

File hashes

Hashes for pynvvl_cuda92-0.0.3a1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 78498e4ad2c65da2ede60185ab7706bd5a44c7a999d31f732f64e037c77ab277
MD5 37b5eb037bed4c6b12cd252786c439d6
BLAKE2b-256 edd3e0f739c49d69685cbab8be00ffef2f374c03f62a85f0e8c619ad4a28fdba

See more details on using hashes here.

File details

Details for the file pynvvl_cuda92-0.0.3a1-cp34-cp34m-manylinux1_x86_64.whl.

File metadata

  • Download URL: pynvvl_cuda92-0.0.3a1-cp34-cp34m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 803.1 kB
  • Tags: CPython 3.4m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.3

File hashes

Hashes for pynvvl_cuda92-0.0.3a1-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 906c8b4f7a36ddb6947c6f4d3adba2f4b6f1b23a635c4dc181fef1a32b2c723c
MD5 f11eade0f66e6c0d02db72e05fdfae10
BLAKE2b-256 1dca676b8b6a8e4c2e4caadb98fa08f874634fea67b9c77906d5e1c0a1c65cae

See more details on using hashes here.

File details

Details for the file pynvvl_cuda92-0.0.3a1-cp27-cp27mu-manylinux1_x86_64.whl.

File metadata

  • Download URL: pynvvl_cuda92-0.0.3a1-cp27-cp27mu-manylinux1_x86_64.whl
  • Upload date:
  • Size: 788.4 kB
  • Tags: CPython 2.7mu
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.3

File hashes

Hashes for pynvvl_cuda92-0.0.3a1-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 461d5228a603326ef4903d53c4152dcd23f64e9fb80417632b7d0463a52b3650
MD5 98950e798ecd7fb4b7d8e0f93283d2cd
BLAKE2b-256 f926a51261796572f21ab333395b914c9565e9a9a73a2348aa091cbe45d8dd25

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page