Closed baltic-tea closed 11 months ago
Hi! I solved this issue on v2.0.6. Thanks for reporting the bug.
@jonghwanhyeon sorry for late comment, but face same error on ffprobe 6.0
and 6.1
. On 4.4.1
and 4.4.2
all is ok.
Binary ffmpeg and ffprobe from here: mwader/static-ffmpeg:6.0 and mwader/static-ffmpeg:6.1
@aa-reznik Can you show me a code you use?
@jonghwanhyeon yes, it's very simple function.
import json
import os
from ffmpeg.asyncio import FFmpeg
async def get_local_media_metadata(local_file_path: str) -> dict:
"""
Retrieves metadata for a local media file.
Args:
local_file_path: The file path of the local media file.
Returns:
dict with results.
"""
ffprobe = FFmpeg(executable="ffprobe").input(
local_file_path,
print_format="json",
show_streams=None,
show_format=None,
)
media = json.loads(await ffprobe.execute())
metadata = {
"duration": round(float(media["format"]["duration"]), 2),
"size": int(media["format"]["size"]),
"size_mb": round(float(media["format"]["size"]) / 1024 / 1024, 2),
"bitrate_kbps": round(float(media["format"]["bit_rate"]) / 1024, 2),
}
try:
video_streams = [
stream for stream in media["streams"] if stream["codec_type"] == "video"
]
width, height = video_streams[0]["width"], video_streams[0]["height"]
metadata.update({"width": width, "height": height})
except Exception:
pass # No video stream, it's ok
return metadata
used python-ffmpeg==2.0.7
and
COPY --from=mwader/static-ffmpeg:6.0 /ffmpeg /usr/local/bin/
COPY --from=mwader/static-ffmpeg:6.0 /ffprobe /usr/local/bin/
in docker file.
Same exception as above, no matter what mp4 file is on input:
File "/usr/local/lib/python3.10/site-packages/ffmpeg/statistics.py", line 19, in <lambda>
"size": lambda item: int(item.replace("kB", "")) * 1024,
ValueError: invalid literal for int() with base 10: "2097152'"
Fixed! Please use version 2.0.8. Thanks for helping me 🙏
Hi, I got a very similar issue on Windows 11 with ffmpeg.
python-ffmpeg 2.0.10
Traceback (most recent call last):
File "D:\proj\python\using-python-ffmpeg\convert.py", line 91, in <module>
convert_file(input=sys.argv[1], output=sys.argv[2])
File "D:\proj\python\using-python-ffmpeg\convert.py", line 85, in convert_file
run_ffmpeg(str(input_path), str(output_path), preset, crf)
File "D:\proj\python\using-python-ffmpeg\utils.py", line 79, in run_ffmpeg
ffmpeg.execute()
File "D:\proj\python\using-python-ffmpeg\.venv\Lib\site-packages\ffmpeg\ffmpeg.py", line 197, in execute
raise exception
File "C:\Users\uj95\AppData\Local\Programs\Python\Python312\Lib\concurrent\futures\thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\proj\python\using-python-ffmpeg\.venv\Lib\site-packages\ffmpeg\ffmpeg.py", line 256, in _handle_stderr
self.emit("stderr", line.decode())
File "D:\proj\python\using-python-ffmpeg\.venv\Lib\site-packages\pyee\base.py", line 208, in emit
handled = self._call_handlers(event, args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\proj\python\using-python-ffmpeg\.venv\Lib\site-packages\pyee\base.py", line 184, in _call_handlers
self._emit_run(f, args, kwargs)
File "D:\proj\python\using-python-ffmpeg\.venv\Lib\site-packages\pyee\base.py", line 160, in _emit_run
f(*args, **kwargs)
File "D:\proj\python\using-python-ffmpeg\.venv\Lib\site-packages\ffmpeg\progress.py", line 37, in _on_stderr
statistics = Statistics.from_line(line)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\proj\python\using-python-ffmpeg\.venv\Lib\site-packages\ffmpeg\statistics.py", line 41, in from_line
fields = {key: _field_factory[key](value) for key, value in statistics.items() if value != "N/A"}
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\proj\python\using-python-ffmpeg\.venv\Lib\site-packages\ffmpeg\statistics.py", line 19, in <lambda>
"size": lambda item: int(item.replace("kB", "")) * 1024,
^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: '0KiB'
I encountered this error while deploying a Docker application on Debian (python:3.11-slim-bullseye).
Full output of error:
I fixed this error by changing the one line in the
./ffmpeg/statistics.py
.Before:
"size": lambda item: int(item.replace("kB")) * 1024
After:"size": lambda item: int(item.rstrip("'kB ")) * 1024