Skip to content

Commit

Permalink
fix: add ffmpeg binaries check
Browse files Browse the repository at this point in the history
  • Loading branch information
Félix Voituret committed Jun 10, 2020
1 parent 05aa98a commit 68ab303
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions spleeter/audio/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

import os
import shutil

# pylint: disable=import-error
import ffmpeg
Expand All @@ -24,6 +25,16 @@
__license__ = 'MIT License'


def _check_ffmpeg_install():
""" Ensure FFMPEG binaries are available.
:raise SpleeterError: If ffmpeg or ffprobe is not found.
"""
for binary in ('ffmpeg', 'ffprobe'):
if shutil.which(binary) is None:
raise SpleeterError('{} binary not found'.format(binary))


def _to_ffmpeg_time(n):
""" Format number of seconds to time expected by FFMPEG.
:param n: Time in seconds to format.
Expand Down Expand Up @@ -66,6 +77,7 @@ def load(
:returns: Loaded data a (waveform, sample_rate) tuple.
:raise SpleeterError: If any error occurs while loading audio.
"""
_check_ffmpeg_install()
if not isinstance(path, str):
path = path.decode()
try:
Expand Down Expand Up @@ -112,6 +124,7 @@ def save(
:param bitrate: (Optional) Bitrate of the written audio file.
:raise IOError: If any error occurs while using FFMPEG to write data.
"""
_check_ffmpeg_install()
directory = os.path.dirname(path)
if not os.path.exists(directory):
raise SpleeterError(f'output directory does not exists: {directory}')
Expand Down

0 comments on commit 68ab303

Please sign in to comment.