mirror of
https://github.com/kkroening/ffmpeg-python.git
synced 2025-08-07 18:39:47 +08:00
Detect: Filter encoders and decoders based on GPU support
This commit is contained in:
parent
267bb71fd6
commit
47cc498aa6
@ -171,6 +171,23 @@ def detect_hwaccels(hwaccels=None, cmd='ffmpeg'):
|
|||||||
hwaccels = [
|
hwaccels = [
|
||||||
hwaccel for hwaccel in hwaccels if hwaccel['name'] in api_avail]
|
hwaccel for hwaccel in hwaccels if hwaccel['name'] in api_avail]
|
||||||
|
|
||||||
|
# Filter encoders and decoders based on what's supported by the GPU
|
||||||
|
for gpu in gpus:
|
||||||
|
for coder_type in ['encoders', 'decoders']:
|
||||||
|
coder_data = gpu.get(coder_type)
|
||||||
|
if coder_data is None:
|
||||||
|
continue
|
||||||
|
for hwaccel in hwaccels:
|
||||||
|
for codec, coders in hwaccel.get('codecs', {}).items():
|
||||||
|
coder_supported = coder_data.get(codec)
|
||||||
|
if coder_supported is None or coder_supported:
|
||||||
|
# This encoder/decoder is supported, no need to filter
|
||||||
|
# it out
|
||||||
|
continue
|
||||||
|
|
||||||
|
# This codec isn't supported by the GPU hjardware
|
||||||
|
coders.pop(coder_type, None)
|
||||||
|
|
||||||
hwaccels.sort(key=lambda hwaccel: (
|
hwaccels.sort(key=lambda hwaccel: (
|
||||||
# Sort unranked hwaccels last, but in the order given by ffmpeg
|
# Sort unranked hwaccels last, but in the order given by ffmpeg
|
||||||
hwaccel['name'] in HWACCELS_BY_PERFORMANCE and 1 or 0,
|
hwaccel['name'] in HWACCELS_BY_PERFORMANCE and 1 or 0,
|
||||||
@ -178,6 +195,7 @@ def detect_hwaccels(hwaccels=None, cmd='ffmpeg'):
|
|||||||
# Sort ranked hwaccels per the constant
|
# Sort ranked hwaccels per the constant
|
||||||
hwaccel['name'] in HWACCELS_BY_PERFORMANCE and
|
hwaccel['name'] in HWACCELS_BY_PERFORMANCE and
|
||||||
HWACCELS_BY_PERFORMANCE.index(hwaccel['name']))))
|
HWACCELS_BY_PERFORMANCE.index(hwaccel['name']))))
|
||||||
|
|
||||||
hwaccels_data['hwaccels'] = hwaccels
|
hwaccels_data['hwaccels'] = hwaccels
|
||||||
return hwaccels_data
|
return hwaccels_data
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user