11""" DirectShow device"""
22
3- from copy import deepcopy
43from subprocess import PIPE
54from ffmpegio import path
65import re , logging
76
87from pluggy import HookimplMarker
8+ from packaging .version import Version
99
1010hookimpl = HookimplMarker ("ffmpegio" )
1111
@@ -78,7 +78,7 @@ def __call__(self, t, m):
7878
7979def _resolve (infos ):
8080 # TODO Verify if multiple videos/audios allowed (more than 1 each)
81- return ":" .join ([f'{ dev ["media_type" ]} =" { dev ["name" ]} " ' for dev in infos ])
81+ return ":" .join ([f'{ dev ["media_type" ]} ={ dev ["name" ]} ' for dev in infos ])
8282
8383
8484def _list_options (dev ):
@@ -114,6 +114,19 @@ def _list_options(dev):
114114 i1 = m .start ()
115115
116116 re_pin = re .compile (rf'\[{ sign } \] Pin "(.+?)" \(alternative pin name "(.+?)"\)\n' )
117+
118+ re_video = re .compile (
119+ rf"\[{ sign } \] (?:unknown compression type 0x([0-9A-F]+?)|vcodec=(.+?)|pixel_format=(.+?))"
120+ + rf" min s=(\d+)x(\d+) fps=([\d.]+) max s=(\d+)x(\d+) fps=([\d.]+)"
121+ + rf"(?: \((.+?), (.+?)/(.+?)/(.+?)(?:, (.+?))?\))?\n"
122+ )
123+
124+ re_audio = re .compile (
125+ rf"\[{ sign } \] ch=\s*(\d+), bits=\s*(\d+), rate=\s*(\d+)\n"
126+ if v5_or_later
127+ else rf"\[{ sign } \] min ch=\s*(\d+) bits=\s*(\d+) rate=\s*(\d+) max ch=\s*(\d+) bits=\s*(\d+) rate=\s*(\d+)\n"
128+ )
129+
117130 pins = [(m [1 ], * m .span ()) for m in re_pin .finditer (logs )]
118131 ipins = [(pin [2 ], pins [i + 1 ][1 ]) for i , pin in enumerate (pins [:- 1 ])]
119132 ipins .append ((pins [- 1 ][2 ], i1 ))
@@ -122,12 +135,6 @@ def _list_options(dev):
122135
123136 for (pin , * _ ), (i0 , i1 ) in zip (pins , ipins ):
124137
125- re_video = re .compile (
126- rf"\[{ sign } \] (?:unknown compression type 0x([0-9A-F]+?)|vcodec=(.+?)|pixel_format=(.+?))"
127- + rf" min s=(\d+)x(\d+) fps=([\d.]+) max s=(\d+)x(\d+) fps=([\d.]+)"
128- + rf"(?: \((.+?), (.+?)/(.+?)/(.+?)(?:, (.+?))?\))?\n"
129- )
130-
131138 def form_video_config (m ):
132139 # https://docs.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-iamstreamconfig-getstreamcapss
133140 cfg = {"vcodec" : m [2 ]} if m [2 ] else {"pixel_format" : m [3 ]} if m [3 ] else {}
@@ -149,17 +156,22 @@ def form_video_config(m):
149156
150157 return cfg
151158
152- re_audio = re .compile (
153- rf"\[{ sign } \] ch=\s*(\d+), bits=\s*(\d+), rate=\s*(\d+)\n"
154- )
155-
156159 def form_audio_config (m ):
157- return {
158- "audio_pin_name" : pin ,
159- "channels" : int (m [1 ]),
160- "sample_size" : int (m [2 ]),
161- "sample_rate" : int (m [3 ]),
162- }
160+ return (
161+ {
162+ "audio_pin_name" : pin ,
163+ "channels" : int (m [1 ]),
164+ "sample_size" : int (m [2 ]),
165+ "sample_rate" : int (m [3 ]),
166+ }
167+ if v5_or_later
168+ else {
169+ "audio_pin_name" : pin ,
170+ "channels" : (int (m [1 ]), int (m [4 ])),
171+ "sample_size" : (int (m [2 ]), int (m [5 ])),
172+ "sample_rate" : (int (m [3 ]), int (m [6 ])),
173+ }
174+ )
163175
164176 re_cfgs = re_video if is_video else re_audio
165177 form_config = form_video_config if is_video else form_audio_config
0 commit comments