Name | avcuda JSON |
Version |
0.1.7
JSON |
| download |
home_page | None |
Summary | PyAV extension with hardware encoding/decoding support on Nvidia GPUs. |
upload_time | 2024-09-02 07:39:37 |
maintainer | None |
docs_url | None |
author | Matteo Destro |
requires_python | None |
license | MIT License Copyright (c) 2024 Matteo Destro Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
av
cuda
torch
ffmpeg
libav
video
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# PyAV-CUDA
[![PyPI version](https://img.shields.io/pypi/v/avcuda)](https://pypi.org/project/avcuda/)
**PyAV-CUDA** is an extension of [PyAV](https://github.com/PyAV-Org/PyAV) that adds support for hardware-accelerated video decoding using Nvidia GPUs. It integrates with FFmpeg and PyTorch, providing CUDA-accelerated kernels for efficient color space conversion.
## Installation
1. Build and install FFmpeg with [hardware acceleration support](https://pytorch.org/audio/stable/build.ffmpeg.html).
2. To enable hardware acceleration in PyAV, it needs to be reinstalled from source. Assuming FFmpeg is installed in `/opt/ffmpeg`, run:
```bash
pip uninstall av
PKG_CONFIG_LIBDIR="/opt/ffmpeg/lib/pkgconfig" pip install av --no-binary av --no-cache
```
If the installation was successful, `h264_cuvid` should appear between the available codecs:
```python
import av
print(av.codecs_available)
```
3. Install PyAV-CUDA:
```bash
PKG_CONFIG_LIBDIR="/opt/ffmpeg/lib/pkgconfig" CUDA_HOME="/usr/local/cuda" pip install avcuda
```
4. Test the installation by running `python examples/benchmark.py`. The output should show something like:
```
Running CPU decoding... took 34.99s
Running GPU decoding... took 8.30s
```
## Usage
To use hardware decoding, instantiate an `HWDeviceContext` and attach it to a `VideoStream`. Note that an `HWDeviceContext` can be shared by multiple `VideoStream` instances to save memory.
```python
import av
import avcuda
CUDA_DEVICE = 0
with (
av.open("video.mp4") as container,
avcuda.HWDeviceContext(CUDA_DEVICE) as hwdevice_ctx,
):
stream = container.streams.video[0]
hwdevice_ctx.attach(stream.codec_context)
# Convert frames into RGB PyTorch tensors on the same device
for frame in container.decode(stream):
frame_tensor = hwdevice_ctx.to_tensor(frame)
```
Raw data
{
"_id": null,
"home_page": null,
"name": "avcuda",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "av, cuda, torch, ffmpeg, libav, video",
"author": "Matteo Destro",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/8e/e8/96332b43122e5111866f4be2b3c134e090efc30803ff9689816f993fec0b/avcuda-0.1.7.tar.gz",
"platform": null,
"description": "# PyAV-CUDA\n[![PyPI version](https://img.shields.io/pypi/v/avcuda)](https://pypi.org/project/avcuda/)\n\n**PyAV-CUDA** is an extension of [PyAV](https://github.com/PyAV-Org/PyAV) that adds support for hardware-accelerated video decoding using Nvidia GPUs. It integrates with FFmpeg and PyTorch, providing CUDA-accelerated kernels for efficient color space conversion.\n\n## Installation\n\n1. Build and install FFmpeg with [hardware acceleration support](https://pytorch.org/audio/stable/build.ffmpeg.html).\n\n2. To enable hardware acceleration in PyAV, it needs to be reinstalled from source. Assuming FFmpeg is installed in `/opt/ffmpeg`, run:\n ```bash\n pip uninstall av\n PKG_CONFIG_LIBDIR=\"/opt/ffmpeg/lib/pkgconfig\" pip install av --no-binary av --no-cache\n ```\n If the installation was successful, `h264_cuvid` should appear between the available codecs:\n ```python\n import av\n print(av.codecs_available)\n ```\n\n3. Install PyAV-CUDA:\n ```bash\n PKG_CONFIG_LIBDIR=\"/opt/ffmpeg/lib/pkgconfig\" CUDA_HOME=\"/usr/local/cuda\" pip install avcuda\n ```\n\n4. Test the installation by running `python examples/benchmark.py`. The output should show something like:\n ```\n Running CPU decoding... took 34.99s\n Running GPU decoding... took 8.30s\n ```\n\n\n## Usage\n\nTo use hardware decoding, instantiate an `HWDeviceContext` and attach it to a `VideoStream`. Note that an `HWDeviceContext` can be shared by multiple `VideoStream` instances to save memory.\n\n```python\nimport av\nimport avcuda\n\nCUDA_DEVICE = 0\n\nwith (\n av.open(\"video.mp4\") as container,\n avcuda.HWDeviceContext(CUDA_DEVICE) as hwdevice_ctx,\n):\n stream = container.streams.video[0]\n hwdevice_ctx.attach(stream.codec_context)\n\n # Convert frames into RGB PyTorch tensors on the same device\n for frame in container.decode(stream):\n frame_tensor = hwdevice_ctx.to_tensor(frame)\n```\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 Matteo Destro Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "PyAV extension with hardware encoding/decoding support on Nvidia GPUs.",
"version": "0.1.7",
"project_urls": {
"Homepage": "https://github.com/materight/PyAV-CUDA.git",
"Repository": "https://github.com/materight/PyAV-CUDA.git"
},
"split_keywords": [
"av",
" cuda",
" torch",
" ffmpeg",
" libav",
" video"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8ee896332b43122e5111866f4be2b3c134e090efc30803ff9689816f993fec0b",
"md5": "eea2507ee03e263885e6a8eff9604521",
"sha256": "12f5559c404704b2c46d5fba9e07669f56def81b0a584feea2c867ae34677275"
},
"downloads": -1,
"filename": "avcuda-0.1.7.tar.gz",
"has_sig": false,
"md5_digest": "eea2507ee03e263885e6a8eff9604521",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6917,
"upload_time": "2024-09-02T07:39:37",
"upload_time_iso_8601": "2024-09-02T07:39:37.893730Z",
"url": "https://files.pythonhosted.org/packages/8e/e8/96332b43122e5111866f4be2b3c134e090efc30803ff9689816f993fec0b/avcuda-0.1.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-02 07:39:37",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "materight",
"github_project": "PyAV-CUDA",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "avcuda"
}