Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to make sure hardware acceleration is used by PyAV? #1821

Unanswered
Fostereee asked this question in 1. Help
Discussion options

I am working with ffmpeg and hardware acceleration. Using ffmpeg in cli with option hwaccel or c:v can force hardware decoding.
However in PyAV, if I pass the same hwaccel or c:v parameters, such as
av.open(path, options={"hwaccel":"cuda"} ) or av.open(path, options={"c:v":"h264_cuvid"}
it does not seem to use the GPU though I am not completely sure (one cpu reaching 100% in htop).
It also does not throw any exception even if I set hwaccel to gibberish.

Is there a way to force PyAV to use hardware acceleration or at least force it to throw exception when it does not support it?
My pyav version is 10.0.0.

Thanks.

You must be logged in to vote

Replies: 2 comments

Comment options

You can use nvidia-smi (run this from a command prompt non Windows) to see if the NVIDIA GPU is being utilized.

You must be logged in to vote
0 replies
Comment options

I just learned this. Not sure if this is the best way. But WFM!

from av import (
 open as avopen,
 datasets,
)
from av.codec.hwaccel import (
 HWAccel,
)
cuda = HWAccel(device_type='cuda')
fate_vid = 'pexels/time-lapse-video-of-night-sky-857195.mp4'
input_container = avopen(file=datasets.curated(fate_vid), hwaccel=cuda)
# this assumes the first video stream exists
vid = input_container.streams.video[0]
if not vid.codec_context.is_hwaccel:
 raise RuntimeError('HWAccel not enabled')
for i, frame in enumerate(input_container.decode(vid)):
 print(frame)
You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /