Skip to content

Commit

Permalink
Merge pull request #51 from Fiereu/main
Browse files Browse the repository at this point in the history
Since ffmpeg 7.0 the file size is shown in KiB.
  • Loading branch information
jonghwanhyeon authored Apr 15, 2024
2 parents c0c4787 + e4e2fea commit 7436dee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ffmpeg/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from typing_extensions import Self

from ffmpeg.utils import parse_time
from ffmpeg.utils import parse_time, parse_size

# Reference: https://github.com/FFmpeg/FFmpeg/blob/release/6.1/fftools/ffmpeg.c#L496

Expand All @@ -16,7 +16,7 @@
_field_factory = {
"frame": int,
"fps": float,
"size": lambda item: int(item.replace("kB", "")) * 1024,
"size": parse_size,
"time": parse_time,
"bitrate": lambda item: float(item.replace("kbits/s", "")),
"speed": lambda item: float(item.replace("x", "")),
Expand Down
8 changes: 8 additions & 0 deletions ffmpeg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ def parse_time(time: str) -> timedelta:
milliseconds=int(match.group(4)) * 10,
)

# https://github.com/FFmpeg/FFmpeg/blob/d38bf5e08e768722096723b5c8781cd2eb18d070/fftools/ffmpeg.c#L618C53-L618C56
def parse_size(item: str) -> int:
if "kB" in item:
return int(item.replace("kB", "")) * 1024
elif "KiB" in item:
return int(item.replace("KiB", "")) * 1024
else:
raise ValueError(f"Unknown size format: {item}")

def is_windows() -> bool:
return sys.platform == "win32"
Expand Down

0 comments on commit 7436dee

Please sign in to comment.