PyNVVL:NVIDIA 视频加载器 (NVVL) 的 Python 封装,支持 CuPy
项目描述
PyNVVL
PyNVVL 是 NVIDIA 视频加载器 (NVVL) 的一个薄封装。此软件包使您能够将视频直接加载到 GPU 内存中,并以无拷贝方式将其作为 CuPy ndarrays 访问。PyNVVL 的预构建二进制文件包括 NVVL 本身,因此您不需要安装 NVVL。
需求
- CUDA 8.0, 9.0, 9.1 或 9.2
- Python 2.7.6+、3.4.7+、3.5.1+ 或 3.6.0+
- CuPy v4.5.0
测试环境
- Ubuntu 16.04
- Python 2.7.6+、3.4.7+、3.5.1+ 和 3.6.0+
- CUDA 8.0、9.0、9.1 和 9.2
安装预构建二进制文件
请根据您的 CUDA 版本选择合适的软件包。
# [For CUDA 8.0]
pip install pynvvl-cuda80
# [For CUDA 9.0]
pip install pynvvl-cuda90
# [For CUDA 9.1]
pip install pynvvl-cuda91
# [For CUDA 9.2]
pip install pynvvl-cuda92
用法
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')
此视频来自 Moments-In-Time 数据集的 flickr-2-6-3-3-5-2-7-6-5626335276_4.mp4
。
请注意,裁剪是在缩放之后进行的。在上面的示例中,NVVL 首先从 256 x 256 缩放到 512 x 512,然后裁剪区域 [60:60 + 385, 0:512]。有关转换选项的更多信息,请参阅以下部分。
VideoLoader 选项
当创建 NVVLVideoLoader
对象时,请指定 GPU 设备 ID。您还可以通过构造函数的 log_level
参数指定日志级别。
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'.
转换选项
pynvvl.NVVLVideoLoader.read_sequence
可以接受一些选项来指定颜色空间、值范围以及您想要对视频执行的转换。
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.
如何构建
使用 Docker 构建 wheels
需求
- Docker
- nvidia-docker (v1/v2)
bash docker/build_wheels.sh
无 Docker 设置开发环境
脚本 setup.py
会查找必要的库。
需求:以下库在 LIBRARY_PATH
中可用。
- libnvvl.so
- libavformat.so.57
- libavfilter.so.6
- libavcodec.so.57
- libavutil.so.55
您可以在 nvvl
仓库中构建 libnvvl.so
。遵循 nvvl
库的说明。 build
目录必须在 LIBRARY_PATH
中。
其他三个库在 Ubuntu 16.04 中作为软件包提供。它们安装在 /usr/lib/x86_64-linux-gnu
下,因此它们也必须在 LIBRARY_PATH
中。
python setup.py develop
python setup.py bdist_wheel
项目详情
关闭
哈希值 用于 pynvvl_cuda92-0.0.3a2-cp36-cp36m-manylinux1_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 7fade5d37dac0fd2da179b3c2bf3aa6ca5eb430fe512f6d1fb09e06273358b79 |
|
MD5 | a35aa9bcab53cb0d96569fb332774234 |
|
BLAKE2b-256 | 93bd6b683cc0c1e7102bbcca771fd66097f643510cb91e7f3c2e783598133dc9 |
关闭
哈希值 用于 pynvvl_cuda92-0.0.3a2-cp35-cp35m-manylinux1_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | f84347ac2577b9f710a09ff2178255f7389fb4847211fe572a286df4b0e2e501 |
|
MD5 | cc928f129996542fc16b5030b6397a83 |
|
BLAKE2b-256 | b3200135ac884721ac7bc6528d0958e38702f1fa2540d9f7f1b158ce173d821a |
关闭
哈希值 用于 pynvvl_cuda92-0.0.3a2-cp34-cp34m-manylinux1_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 3c7be7cc0aca18429d285bb22f3529325c339437a6513ffd790f2fb9ef2ca402 |
|
MD5 | 9468f4d236016d05a54d5946f5491312 |
|
BLAKE2b-256 | 0fcdf66de5cb71aad77142c5e4572d010e8af0d0667db8444bc71456a9ca6d8a |
关闭
哈希值 用于 pynvvl_cuda92-0.0.3a2-cp27-cp27mu-manylinux1_x86_64.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 3ae9d8e6b357853f503966e4cff9eba53b8a3b0d8928cb7526f49ff8cbe3d53e |
|
MD5 | 719f5bb9726fbf5ef1636bd837960384 |
|
BLAKE2b-256 | 96cd5955aeadb401779c129de7377bc30cc63be0e8f67b5426b458cda558e3ac |