mirror of
https://github.com/YuzuZensai/spleeter.git
synced 2026-01-31 14:58:23 +00:00
Merge pull request #416 from deezer/error-mgmt
fix: add ffmpeg binaries check
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
import ffmpeg
|
import ffmpeg
|
||||||
@@ -24,6 +25,16 @@ __author__ = 'Deezer Research'
|
|||||||
__license__ = 'MIT License'
|
__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):
|
def _to_ffmpeg_time(n):
|
||||||
""" Format number of seconds to time expected by FFMPEG.
|
""" Format number of seconds to time expected by FFMPEG.
|
||||||
:param n: Time in seconds to format.
|
:param n: Time in seconds to format.
|
||||||
@@ -66,6 +77,7 @@ class FFMPEGProcessAudioAdapter(AudioAdapter):
|
|||||||
:returns: Loaded data a (waveform, sample_rate) tuple.
|
:returns: Loaded data a (waveform, sample_rate) tuple.
|
||||||
:raise SpleeterError: If any error occurs while loading audio.
|
:raise SpleeterError: If any error occurs while loading audio.
|
||||||
"""
|
"""
|
||||||
|
_check_ffmpeg_install()
|
||||||
if not isinstance(path, str):
|
if not isinstance(path, str):
|
||||||
path = path.decode()
|
path = path.decode()
|
||||||
try:
|
try:
|
||||||
@@ -112,6 +124,7 @@ class FFMPEGProcessAudioAdapter(AudioAdapter):
|
|||||||
:param bitrate: (Optional) Bitrate of the written audio file.
|
:param bitrate: (Optional) Bitrate of the written audio file.
|
||||||
:raise IOError: If any error occurs while using FFMPEG to write data.
|
:raise IOError: If any error occurs while using FFMPEG to write data.
|
||||||
"""
|
"""
|
||||||
|
_check_ffmpeg_install()
|
||||||
directory = os.path.dirname(path)
|
directory = os.path.dirname(path)
|
||||||
if not os.path.exists(directory):
|
if not os.path.exists(directory):
|
||||||
raise SpleeterError(f'output directory does not exists: {directory}')
|
raise SpleeterError(f'output directory does not exists: {directory}')
|
||||||
|
|||||||
Reference in New Issue
Block a user