Skip to content

Commit aea3584

Browse files
author
The mediapy Authors
committed
Slight API change for running ffmpeg internally.
PiperOrigin-RevId: 747505970
1 parent 2bf4ff4 commit aea3584

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

mediapy/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,10 @@ def _path_is_local(path: _Path) -> bool:
228228
return True
229229

230230

231-
def _search_for_ffmpeg_path() -> list[str] | None:
231+
def _search_for_ffmpeg_path() -> str | None:
232232
"""Returns a path to the ffmpeg program, or None if not found."""
233233
if filename := shutil.which(_config.ffmpeg_name_or_path):
234-
return [str(filename)]
234+
return str(filename)
235235
return None
236236

237237

@@ -1164,7 +1164,7 @@ def _filename_suffix_from_codec(codec: str) -> str:
11641164
return '.gif' if codec == 'gif' else '.mp4'
11651165

11661166

1167-
def _get_ffmpeg_path() -> list[str]:
1167+
def _get_ffmpeg_path() -> str:
11681168
path = _search_for_ffmpeg_path()
11691169
if not path:
11701170
raise RuntimeError(
@@ -1206,9 +1206,8 @@ def _get_video_metadata(path: _Path) -> VideoMetadata:
12061206
"""Returns attributes of video stored in the specified local file."""
12071207
if not pathlib.Path(path).is_file():
12081208
raise RuntimeError(f"Video file '{path}' is not found.")
1209-
12101209
command = [
1211-
*_get_ffmpeg_path(),
1210+
_get_ffmpeg_path(),
12121211
'-nostdin',
12131212
'-i',
12141213
str(path),
@@ -1348,6 +1347,7 @@ def __init__(
13481347
self._proc: subprocess.Popen[bytes] | None = None
13491348

13501349
def __enter__(self) -> 'VideoReader':
1350+
ffmpeg_path = _get_ffmpeg_path()
13511351
try:
13521352
self._read_via_local_file = _read_via_local_file(self.path_or_url)
13531353
# pylint: disable-next=no-member
@@ -1363,7 +1363,7 @@ def __enter__(self) -> 'VideoReader':
13631363
)
13641364

13651365
command = [
1366-
*_get_ffmpeg_path(),
1366+
ffmpeg_path,
13671367
'-v',
13681368
'panic',
13691369
'-nostdin',
@@ -1572,6 +1572,7 @@ def __init__(
15721572
self._proc: subprocess.Popen[bytes] | None = None
15731573

15741574
def __enter__(self) -> 'VideoWriter':
1575+
ffmpeg_path = _get_ffmpeg_path()
15751576
input_pix_fmt = self._get_pix_fmt(self.dtype, self.input_format)
15761577
try:
15771578
self._write_via_local_file = _write_via_local_file(self.path)
@@ -1583,7 +1584,7 @@ def __enter__(self) -> 'VideoWriter':
15831584
height, width = self.shape
15841585
command = (
15851586
[
1586-
*_get_ffmpeg_path(),
1587+
ffmpeg_path,
15871588
'-v',
15881589
'error',
15891590
'-f',

0 commit comments

Comments
 (0)