Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds buffer_size argument to parse #129

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pymediainfo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def parse(
legacy_stream_display: bool = False,
mediainfo_options: Optional[Dict[str, str]] = None,
output: Optional[str] = None,
buffer_size: Optional[int] = 64 * 1024,
) -> Union[str, "MediaInfo"]:
"""
Analyze a media file using libmediainfo.
Expand Down Expand Up @@ -392,6 +393,8 @@ def parse(
`MediaInfo_Option` function, for example: ``{"Language": "raw"}``.
Do not use this parameter when running the method simultaneously from multiple threads,
it will trigger a reset of all options which will cause inconsistencies or failures.
:param int buffer_size: size of the buffer used to read the file, in bytes. This is only
used when `filename` is a file-like object.
:param str output: custom output format for MediaInfo, corresponds to the CLI's
``--Output`` parameter. Setting this causes the method to
return a `str` instead of a :class:`MediaInfo` object.
Expand Down Expand Up @@ -467,7 +470,7 @@ def parse(
raise ValueError("File should be opened in binary mode")
lib.MediaInfo_Open_Buffer_Init(handle, file_size, 0)
while True:
buffer = filename.read(64 * 1024)
buffer = filename.read(buffer_size)
if buffer:
# https://github.com/MediaArea/MediaInfoLib/blob/v20.09/Source/MediaInfo/File__Analyze.h#L1429
# 4th bit = finished
Expand Down