Name | avcuda JSON |
Version |
0.2.4
JSON |
| download |
home_page | None |
Summary | PyAV extension with hardware encoding/decoding support on Nvidia GPUs. |
upload_time | 2024-11-08 08:30:35 |
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_decode.py`. The output should show something like:
```
Running CPU decoding... took 34.99s
Running GPU decoding... took 8.30s
```
## Usage
### Decoding
```python
import av
import avcuda
CUDA_DEVICE = 0
with av.open("video.mp4") as container:
stream = container.streams.video[0]
avcuda.init_hwcontext(stream.codec_context, CUDA_DEVICE)
for avframe in container.decode(stream):
frame_tensor = avcuda.to_tensor(avframe, CUDA_DEVICE)
```
### Encoding
```python
import av
import avcuda
CUDA_DEVICE = 0
NUM_FRAMES = 100
FPS = 30
WIDTH = 640
HEIGHT = 480
with av.open("video.mp4", "w") as container:
stream = container.add_stream("h264_nvenc", rate=FPS)
stream.pix_fmt, stream.width, stream.height = "yuv420p", WIDTH, HEIGHT
avcuda.init_hwcontext(stream.codec_context, CUDA_DEVICE)
for _ in range(NUM_FRAMES):
frame_tensor = torch.randint(0, 255, (HEIGHT, WIDTH, 3), dtype=torch.uint8, device=CUDA_DEVICE)
avframe = avcuda.from_tensor(frame_tensor, stream.codec_context)
for packet in stream.encode(avframe):
container.mux(packet)
```
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/9b/0d/b5edffba19eae88a75e06a280488b9c41a84963a7da99efc5554436d7252/avcuda-0.2.4.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_decode.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\n### Decoding\n\n```python\nimport av\nimport avcuda\n\nCUDA_DEVICE = 0\n\nwith av.open(\"video.mp4\") as container:\n stream = container.streams.video[0]\n avcuda.init_hwcontext(stream.codec_context, CUDA_DEVICE)\n\n for avframe in container.decode(stream):\n frame_tensor = avcuda.to_tensor(avframe, CUDA_DEVICE)\n```\n\n### Encoding\n\n```python\nimport av\nimport avcuda\n\nCUDA_DEVICE = 0\n\nNUM_FRAMES = 100\nFPS = 30\nWIDTH = 640\nHEIGHT = 480\n\nwith av.open(\"video.mp4\", \"w\") as container:\n stream = container.add_stream(\"h264_nvenc\", rate=FPS)\n stream.pix_fmt, stream.width, stream.height = \"yuv420p\", WIDTH, HEIGHT\n\n avcuda.init_hwcontext(stream.codec_context, CUDA_DEVICE)\n\n for _ in range(NUM_FRAMES):\n frame_tensor = torch.randint(0, 255, (HEIGHT, WIDTH, 3), dtype=torch.uint8, device=CUDA_DEVICE)\n avframe = avcuda.from_tensor(frame_tensor, stream.codec_context) \n\n for packet in stream.encode(avframe):\n container.mux(packet)\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.2.4",
"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": "9b0db5edffba19eae88a75e06a280488b9c41a84963a7da99efc5554436d7252",
"md5": "a5c930b7d2608c8aa3736613364fb2ae",
"sha256": "3a815255c5639dbc1a6a97f03e06fd24c1d1ace6aced7b713f9bf7a2becaca0f"
},
"downloads": -1,
"filename": "avcuda-0.2.4.tar.gz",
"has_sig": false,
"md5_digest": "a5c930b7d2608c8aa3736613364fb2ae",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8898,
"upload_time": "2024-11-08T08:30:35",
"upload_time_iso_8601": "2024-11-08T08:30:35.725186Z",
"url": "https://files.pythonhosted.org/packages/9b/0d/b5edffba19eae88a75e06a280488b9c41a84963a7da99efc5554436d7252/avcuda-0.2.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-08 08:30:35",
"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"
}