Skip to content

Commit

Permalink
Add buffer_size arg to parse(), fixes sbraz#129
Browse files Browse the repository at this point in the history
(cherry picked from commit e6dc1cb)
  • Loading branch information
tsitter-evertz authored and eyMarv committed Mar 30, 2024
1 parent f4568f3 commit d8523bd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pymediainfo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,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 @@ -407,6 +408,8 @@ def parse(
* ``"JSON"``
* ``%``-delimited templates (see ``mediainfo --Info-Parameters``)
: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.
:type filename: str or pathlib.Path or os.PathLike or file-like object.
:rtype: str if `output` is set.
:rtype: :class:`MediaInfo` otherwise.
Expand Down Expand Up @@ -468,7 +471,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

0 comments on commit d8523bd

Please sign in to comment.