11from __future__ import annotations
22
33from typing import BinaryIO , Any , TypeAlias , Literal
4+ from numbers import Number
45from collections .abc import Sequence
56import json , re
67from fractions import Fraction
@@ -251,11 +252,11 @@ def full_details(
251252 show_streams : bool | None = True ,
252253 show_programs : bool | None = False ,
253254 show_chapters : bool | None = False ,
254- select_streams : bool | None = None ,
255+ select_streams : str | int | None = None ,
255256 keep_str_values : bool | None = False ,
256257 cache_output : bool | None = False ,
257258 sp_kwargs : dict [str , Any ] | None = None ,
258- ):
259+ ) -> dict [ str , str | Number | Fraction ] :
259260 """Retrieve full details of a media file or stream
260261
261262 :param url: URL of the media file/stream
@@ -268,8 +269,8 @@ def full_details(
268269 :type show_programs: bool, optional
269270 :param show_chapters: True to return chapter info, defaults to False
270271 :type show_chapters: bool, optional
271- :param select_streams: Indices of streams to get info of, defaults to None
272- :type select_streams: seq of int, optional
272+ :param select_streams: Stream specifier of the streams to get info of, defaults to None to retrieve all
273+ :type select_streams: str, int, optional
273274 :param keep_str_values: True to keep all field values as str,
274275 defaults to False to convert numeric values
275276 :type keep_str_values: bool, optional
@@ -329,13 +330,25 @@ def format_basic(
329330 keep_str_values : bool | None = False ,
330331 cache_output : bool | None = False ,
331332 sp_kwargs : dict [str , Any ] | None = None ,
332- ):
333+ ) -> dict [ str , str | Number | Fraction ] :
333334 """Retrieve basic media format info
334335
335336 :param url: URL of the media file/stream
336337 :type url: str or seekable file-like object or bytes-like object
337338 :param entries: specify to narrow which information entries to retrieve. Default to None, to return all entries
338339 :type entries: seq of str
340+ :param keep_optional_fields: True to return a missing optional field in the
341+ returned dict with None or "N/A" (if keep_str_values
342+ is True) as its value
343+ :type keep_optional_fields: bool, optional
344+ :param keep_str_values: True to keep all field values as str,
345+ defaults to False to convert numeric values
346+ :type keep_str_values: bool, optional
347+ :param cache_output: True to cache FFprobe output, defaults to False
348+ :type cache_output: bool, optional
349+ :param sp_kwargs: Additional keyword arguments for :py:func:`subprocess.run`,
350+ default to None
351+ :type sp_kwargs: dict[str, Any], optional
339352 :return: set of media format information.
340353 :rtype: dict
341354
@@ -380,13 +393,25 @@ def streams_basic(
380393 keep_str_values : bool | None = False ,
381394 cache_output : bool | None = False ,
382395 sp_kwargs : dict [str , Any ] | None = None ,
383- ):
396+ ) -> dict [ str , str | Number | Fraction ] :
384397 """Retrieve basic info of media streams
385398
386399 :param url: URL of the media file/stream
387400 :type url: str or seekable file-like object or bytes-like object
388401 :param entries: specify to narrow which stream entries to retrieve. Default to None, returning all entries
389402 :type entries: seq of str, optional
403+ :param keep_optional_fields: True to return a missing optional field in the
404+ returned dict with None or "N/A" (if keep_str_values
405+ is True) as its value
406+ :type keep_optional_fields: bool, optional
407+ :param keep_str_values: True to keep all field values as str,
408+ defaults to False to convert numeric values
409+ :type keep_str_values: bool, optional
410+ :param cache_output: True to cache FFprobe output, defaults to False
411+ :type cache_output: bool, optional
412+ :param sp_kwargs: Additional keyword arguments for :py:func:`subprocess.run`,
413+ default to None
414+ :type sp_kwargs: dict[str, Any], optional
390415 :return: List of media stream information.
391416 :rtype: list of dict
392417
@@ -423,7 +448,7 @@ def video_streams_basic(
423448 keep_str_values : bool | None = False ,
424449 cache_output : bool | None = False ,
425450 sp_kwargs : dict [str , Any ] | None = None ,
426- ):
451+ ) -> dict [ str , str | Number | Fraction ] :
427452 """Retrieve basic info of video streams
428453
429454 :param url: URL of the media file/stream
@@ -432,6 +457,18 @@ def video_streams_basic(
432457 :type index: int, optional
433458 :param entries: specify to narrow which information entries to retrieve. Default to None, to return all entries
434459 :type entries: seq of str
460+ :param keep_optional_fields: True to return a missing optional field in the
461+ returned dict with None or "N/A" (if keep_str_values
462+ is True) as its value
463+ :type keep_optional_fields: bool, optional
464+ :param keep_str_values: True to keep all field values as str,
465+ defaults to False to convert numeric values
466+ :type keep_str_values: bool, optional
467+ :param cache_output: True to cache FFprobe output, defaults to False
468+ :type cache_output: bool, optional
469+ :param sp_kwargs: Additional keyword arguments for :py:func:`subprocess.run`,
470+ default to None
471+ :type sp_kwargs: dict[str, Any], optional
435472 :return: List of video stream information.
436473 :rtype: list of dict
437474
@@ -528,7 +565,7 @@ def audio_streams_basic(
528565 keep_str_values : bool | None = False ,
529566 cache_output : bool | None = False ,
530567 sp_kwargs : dict [str , Any ] | None = None ,
531- ):
568+ ) -> dict [ str , str | Number | Fraction ] :
532569 """Retrieve basic info of audio streams
533570
534571 :param url: URL of the media file/stream
@@ -537,6 +574,18 @@ def audio_streams_basic(
537574 :type index: int, optional
538575 :param entries: specify to narrow which information entries to retrieve. Default to None, to return all entries
539576 :type entries: seq of str
577+ :param keep_optional_fields: True to return a missing optional field in the
578+ returned dict with None or "N/A" (if keep_str_values
579+ is True) as its value
580+ :type keep_optional_fields: bool, optional
581+ :param keep_str_values: True to keep all field values as str,
582+ defaults to False to convert numeric values
583+ :type keep_str_values: bool, optional
584+ :param cache_output: True to cache FFprobe output, defaults to False
585+ :type cache_output: bool, optional
586+ :param sp_kwargs: Additional keyword arguments for :py:func:`subprocess.run`,
587+ default to None
588+ :type sp_kwargs: dict[str, Any], optional
540589 :return: List of audio stream information.
541590 :rtype: list of dict
542591
@@ -622,14 +671,14 @@ def query(
622671 keep_str_values : bool | None = False ,
623672 cache_output : bool | None = False ,
624673 sp_kwargs : dict [str , Any ] | None = None ,
625- ):
674+ ) -> dict [ str , Any ] | Sequence [ dict [ str , Any ]] :
626675 """Query specific fields of media format or stream
627676
628677 :param url: URL of the media file/stream
629678 :type url: str or seekable file-like object or bytes-like object
630679 :param streams: stream specifier, defaults to None to get format
631680 :type streams: str, int, bool, optional
632- :param fields: info , defaults to None
681+ :param fields: list of format/stream fields to retrieve , defaults to None (all fields)
633682 :type fields: sequence of str, optional
634683 :param keep_optional_fields: True to return a missing optional field in the
635684 returned dict with None or "N/A" (if keep_str_values
@@ -755,24 +804,6 @@ def frames(
755804 if entries is str (i.e., a single entry)
756805 :rtype: list[dict] or list[str|int|float]
757806
758- ``intervals`` argument
759- ----------------------
760-
761- intervals argument can be specified in multiple ways to form the ``-read_intervals`` ffprobe option:
762-
763- 1) ``str`` - pass through the argument as-is to ffprobe
764- 2) ``int`` - read this numbers of packets to read from the beginning of the file
765- 3) ``float`` - read packets over this duration in seconds from the beginning of the file
766- 4) ``seq[str|float, str|int|float]`` - sets start and end points
767- - start: str = as-is, float=starting time in seconds
768- - end: str = as-is, int=offset in # of packets, float=offset in seconds
769- 5) ``dict`` - specifies start and end points with the following keys:
770- - 'start' - (str|float) start time
771- - 'start_offset' - (str|float) start time offset from the previous read. Ignored if 'start' is present.
772- - 'end' - (str|float) end time
773- - 'end_offset' - (str|float|int) end time offset from the start time. Ignored if 'end' is present.
774- 6) - ``seq[dict]`` - specify multiple intervals
775-
776807 """
777808
778809 is_single = isinstance (entries , str )
0 commit comments