{"id":15086026,"url":"https://github.com/materight/pyav-cuda","last_synced_at":"2026-02-01T01:05:29.432Z","repository":{"id":248536348,"uuid":"828970041","full_name":"materight/PyAV-CUDA","owner":"materight","description":"Extension of PyAV with hardware encoding and decoding support. Compatible with PyTorch and Nvidia codecs.","archived":false,"fork":false,"pushed_at":"2024-11-08T08:30:05.000Z","size":39,"stargazers_count":0,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T23:29:17.285Z","etag":null,"topics":["cuda","cuvid","ffmpeg","libav","pytorch"],"latest_commit_sha":null,"homepage":"","language":"Cython","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/materight.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-15T13:44:50.000Z","updated_at":"2024-11-08T08:29:46.000Z","dependencies_parsed_at":"2024-09-10T18:45:31.358Z","dependency_job_id":"8efa220d-91ed-4f70-b223-7df94f415d15","html_url":"https://github.com/materight/PyAV-CUDA","commit_stats":{"total_commits":31,"total_committers":2,"mean_commits":15.5,"dds":"0.032258064516129004","last_synced_commit":"e70b8861b81fef29dcefc2e2cb5878c3f48618de"},"previous_names":["materight/pyav_hw","materight/pyav-hardware","materight/pyav-cuda"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/materight/PyAV-CUDA","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/materight%2FPyAV-CUDA","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/materight%2FPyAV-CUDA/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/materight%2FPyAV-CUDA/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/materight%2FPyAV-CUDA/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/materight","download_url":"https://codeload.github.com/materight/PyAV-CUDA/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/materight%2FPyAV-CUDA/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259426986,"owners_count":22855555,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cuda","cuvid","ffmpeg","libav","pytorch"],"created_at":"2024-09-25T07:03:20.539Z","updated_at":"2026-02-01T01:05:29.402Z","avatar_url":"https://github.com/materight.png","language":"Cython","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmateright%2Fpyav-cuda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmateright%2Fpyav-cuda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmateright%2Fpyav-cuda/lists"}