Skip to content

Commit 35105da

Browse files
committed
probe: added sp_kwargs argument to all ffprobe running functions
1 parent c127626 commit 35105da

1 file changed

Lines changed: 26 additions & 6 deletions

File tree

src/ffmpegio/probe.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ def _exec(
157157
intervals: IntervalSpec | Sequence[IntervalSpec] | None = None,
158158
count_frames: bool | None = False,
159159
count_packets: bool | None = False,
160+
sp_kwargs: dict[str, Any] | None = None,
160161
) -> dict[str, str]:
161162
"""execute ffprobe and return stdout as dict"""
162163

@@ -167,6 +168,9 @@ def _exec(
167168
"encoding": "utf-8",
168169
}
169170

171+
if sp_kwargs is not None:
172+
sp_opts = {**sp_kwargs, **sp_opts}
173+
170174
args = ["-hide_banner", "-of", "json"]
171175

172176
if streams is not None:
@@ -228,6 +232,7 @@ def full_details(
228232
show_chapters: bool | None = False,
229233
select_streams: bool | None = None,
230234
cache_output: bool | None = False,
235+
sp_kwargs: dict[str, Any] | None = None,
231236
):
232237
"""Retrieve full details of a media file or stream
233238
@@ -245,6 +250,9 @@ def full_details(
245250
:type select_streams: seq of int, optional
246251
:param cache_output: True to cache FFprobe output, defaults to False
247252
:type cache_output: bool, optional
253+
:param sp_kwargs: Additional keyword arguments for :py:func:`subprocess.run`,
254+
default to None
255+
:type sp_kwargs: dict[str, Any], optional
248256
:return: media file information
249257
:rtype: dict[str, str|Number|Fraction]
250258
@@ -293,6 +301,7 @@ def format_basic(
293301
url: str | BinaryIO,
294302
entries: Sequence[str] | None = None,
295303
cache_output: bool | None = False,
304+
sp_kwargs: dict[str, Any] | None = None,
296305
):
297306
"""Retrieve basic media format info
298307
@@ -331,13 +340,15 @@ def format_basic(
331340
None,
332341
_resolve_entries("basic format", entries, default_entries),
333342
cache_output,
343+
sp_kwargs,
334344
)
335345

336346

337347
def streams_basic(
338348
url: str | BinaryIO,
339349
entries: Sequence[str] | None = None,
340350
cache_output: bool | None = False,
351+
sp_kwargs: dict[str, Any] | None = None,
341352
):
342353
"""Retrieve basic info of media streams
343354
@@ -367,6 +378,7 @@ def streams_basic(
367378
True,
368379
_resolve_entries("basic streams", entries, default_entries),
369380
cache_output,
381+
sp_kwargs,
370382
)
371383

372384

@@ -375,6 +387,7 @@ def video_streams_basic(
375387
index: int | None = None,
376388
entries: Sequence[str] | None = None,
377389
cache_output: bool | None = False,
390+
sp_kwargs: dict[str, Any] | None = None,
378391
):
379392
"""Retrieve basic info of video streams
380393
@@ -436,6 +449,7 @@ def video_streams_basic(
436449
f"v:{index}" if index else "v",
437450
_resolve_entries("basic video", entries, default_entries, default_dep_entries),
438451
cache_output,
452+
sp_kwargs,
439453
)
440454

441455
def adjust(res):
@@ -478,6 +492,7 @@ def audio_streams_basic(
478492
index: int | None = None,
479493
entries: Sequence[str] | None = None,
480494
cache_output: bool | None = False,
495+
sp_kwargs: dict[str, Any] | None = None,
481496
):
482497
"""Retrieve basic info of audio streams
483498
@@ -532,6 +547,7 @@ def audio_streams_basic(
532547
f"a:{index}" if index else "a",
533548
_resolve_entries("basic audio", entries, default_entries, default_dep_entries),
534549
cache_output,
550+
sp_kwargs,
535551
)
536552

537553
def adjust(res):
@@ -558,6 +574,7 @@ def query(
558574
streams: str | int | bool | None = None,
559575
fields: Sequence[str] | None = None,
560576
cache_output: bool | None = False,
577+
sp_kwargs: dict[str, Any] | None = None,
561578
return_none: bool | None = False,
562579
):
563580
"""Query specific fields of media format or stream
@@ -572,6 +589,9 @@ def query(
572589
:type cache_output: bool, optional
573590
:param return_none: True to return an invalid field in the returned dict with None as its value
574591
:type return_none: bool, optional
592+
:param sp_kwargs: Additional keyword arguments for :py:func:`subprocess.run`,
593+
default to None
594+
:type sp_kwargs: dict[str, Any], optional
575595
:return: field name-value dict. If streams argument is given but does not specify
576596
index, a list of dict is returned instead
577597
:rtype: dict or list or dict
@@ -590,6 +610,7 @@ def query(
590610
url,
591611
{"stream" if get_stream else "format": fields},
592612
streams,
613+
sp_kwargs=sp_kwargs,
593614
cache_output=cache_output,
594615
)
595616

@@ -618,6 +639,7 @@ def frames(
618639
streams: str | int | None = None,
619640
intervals: IntervalSpec | Sequence[IntervalSpec] | None = None,
620641
accurate_time: bool | None = False,
642+
sp_kwargs: dict[str, Any] | None = None,
621643
):
622644
"""get frame information
623645
@@ -632,6 +654,9 @@ def frames(
632654
:param accurate_time: True to return all '\*_time' attributes to be computed from associated timestamps and
633655
stream timebase, defaults to False (= us accuracy)
634656
:param accurate_time: bool, optional
657+
:param sp_kwargs: Additional keyword arguments for :py:func:`subprocess.run`,
658+
default to None
659+
:type sp_kwargs: dict[str, Any], optional
635660
:return: frame information. list of dictionary if entries is None or a sequence; list of the selected entry
636661
if entries is str (i.e., a single entry)
637662
:rtype: list[dict] or list[str|int|float]
@@ -683,12 +708,7 @@ def frames(
683708
if accurate_time and has_time:
684709
entries["stream"] = ["index", "time_base"]
685710

686-
res = _exec(
687-
url,
688-
entries,
689-
streams=streams,
690-
intervals=intervals,
691-
)
711+
res = _exec(url, entries, streams=streams, intervals=intervals, sp_kwargs=sp_kwargs)
692712

693713
out = [_items_to_numeric(d) for d in res["frames"]]
694714

0 commit comments

Comments
 (0)