Name | avhardware JSON |
Version |
0.1.6
JSON |
| download |
home_page | None |
Summary | PyAV extension with hardware decoding support. |
upload_time | 2024-09-01 10:12:46 |
maintainer | None |
docs_url | None |
author | Matteo Destro |
requires_python | None |
license | None |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# PyAV-Hardware
[![PyPI version](https://img.shields.io/pypi/v/avhardware)](https://pypi.org/project/avhardware/)
**PyAV-Hardware** 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-Hardware:
```bash
PKG_CONFIG_LIBDIR="/opt/ffmpeg/lib/pkgconfig" CUDA_HOME="/usr/local/cuda" pip install avhwardware
```
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 avhardware
CUDA_DEVICE = 0
with (
av.open("video.mp4") as container,
avhardware.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": "avhardware",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Matteo Destro",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/29/e8/d13463ad7b84b4634d831128d0ded5beb058577779fc876a90339449636f/avhardware-0.1.6.tar.gz",
"platform": null,
"description": "# PyAV-Hardware\n[![PyPI version](https://img.shields.io/pypi/v/avhardware)](https://pypi.org/project/avhardware/)\n\n**PyAV-Hardware** 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-Hardware:\n ```bash\n PKG_CONFIG_LIBDIR=\"/opt/ffmpeg/lib/pkgconfig\" CUDA_HOME=\"/usr/local/cuda\" pip install avhwardware\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 avhardware\n\nCUDA_DEVICE = 0\n\nwith (\n av.open(\"video.mp4\") as container,\n avhardware.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": null,
"summary": "PyAV extension with hardware decoding support.",
"version": "0.1.6",
"project_urls": {
"Repository": "https://github.com/materight/PyAV-Hardware.git"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "29e8d13463ad7b84b4634d831128d0ded5beb058577779fc876a90339449636f",
"md5": "48b7ebe9a4429899ebfd3c2bb362b037",
"sha256": "725c105e329c58426484e3d7196c6a6301be942a72d9e1e5e2038ada3c40b0ea"
},
"downloads": -1,
"filename": "avhardware-0.1.6.tar.gz",
"has_sig": false,
"md5_digest": "48b7ebe9a4429899ebfd3c2bb362b037",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6596,
"upload_time": "2024-09-01T10:12:46",
"upload_time_iso_8601": "2024-09-01T10:12:46.198045Z",
"url": "https://files.pythonhosted.org/packages/29/e8/d13463ad7b84b4634d831128d0ded5beb058577779fc876a90339449636f/avhardware-0.1.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-01 10:12:46",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "materight",
"github_project": "PyAV-Hardware",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "avhardware"
}