Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion tagstudio/src/qt/helpers/vendored/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,23 @@ def _get_ffprobe_location() -> str:
if shutil.which(loc + cmd):
cmd = loc + cmd
break
logger.info(f"[FFPROBE] Using FFmpeg location: {cmd}")
logger.info(f"[FFMPEG] Using FFprobe location: {cmd}")
return cmd


def _get_ffmpeg_location() -> str:
cmd: str = "ffmpeg"
if platform.system() == "Darwin":
for loc in FFMPEG_MACOS_LOCATIONS:
if shutil.which(loc + cmd):
cmd = loc + cmd
break
logger.info(f"[FFMPEG] Using FFmpeg location: {cmd}")
return cmd


FFPROBE_CMD = _get_ffprobe_location()
FFMPEG_CMD = _get_ffmpeg_location()


def _probe(filename, cmd=FFPROBE_CMD, timeout=None, **kwargs):
Expand Down
16 changes: 5 additions & 11 deletions tagstudio/src/qt/helpers/vendored/pydub/audio_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from pydub.logging_utils import log_conversion, log_subprocess_output
from pydub.utils import fsdecode
from src.qt.helpers.vendored.ffmpeg import FFMPEG_CMD

try:
from itertools import izip
Expand All @@ -37,7 +38,6 @@
audioop,
db_to_float,
get_array_type,
get_encoder_name,
ratio_to_db,
)
from src.qt.helpers.silent_popen import silent_Popen
Expand Down Expand Up @@ -159,7 +159,7 @@ class _AudioSegment:
slice = a[5000:10000] # get a slice from 5 to 10 seconds of an mp3
"""

converter = get_encoder_name() # either ffmpeg or avconv
converter = FFMPEG_CMD

# TODO: remove in 1.0 release
# maintain backwards compatibility for ffmpeg attr (now called converter)
Expand Down Expand Up @@ -725,7 +725,7 @@ def is_format(f):
stdin_parameter = None
stdin_data = None
else:
if cls.converter == "ffmpeg":
if cls.converter == FFMPEG_CMD:
conversion_command += [
"-read_ahead_limit",
str(read_ahead_limit),
Expand All @@ -737,14 +737,8 @@ def is_format(f):
stdin_parameter = subprocess.PIPE
stdin_data = file.read()

if codec:
info = None
else:
# PATCHED
try:
info = _mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
except FileNotFoundError:
raise ChildProcessError
# PATCHED
info = None if codec else _mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
if info:
audio_streams = [x for x in info["streams"] if x["codec_type"] == "audio"]
# This is a workaround for some ffprobe versions that always say
Expand Down
4 changes: 2 additions & 2 deletions tagstudio/src/qt/helpers/vendored/pydub/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
_fd_or_path_or_tempfile,
fsdecode,
get_extra_info,
get_prober_name,
)
from src.qt.helpers.silent_popen import silent_Popen
from src.qt.helpers.vendored.ffmpeg import FFPROBE_CMD


def _mediainfo_json(filepath, read_ahead_limit=-1):
"""Return json dictionary with media info(codec, duration, size, bitrate...) from filepath."""
prober = get_prober_name()
prober = FFPROBE_CMD
command_args = [
"-v",
"info",
Expand Down
8 changes: 4 additions & 4 deletions tagstudio/src/qt/modals/ffmpeg_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from PySide6.QtCore import Qt, QUrl
from PySide6.QtGui import QDesktopServices
from PySide6.QtWidgets import QMessageBox
from src.qt.helpers.vendored.ffmpeg import FFPROBE_CMD
from src.qt.helpers.vendored.ffmpeg import FFMPEG_CMD, FFPROBE_CMD

logger = structlog.get_logger(__name__)

Expand Down Expand Up @@ -39,7 +39,7 @@ def __init__(self):

def installed(self):
"""Checks if both FFmpeg and FFprobe are installed and in the PATH."""
if which("ffmpeg"):
if which(FFMPEG_CMD):
self.ffmpeg = True
if which(FFPROBE_CMD):
self.ffprobe = True
Expand All @@ -60,15 +60,15 @@ def version(self):
version["ffprobe"] = ret.stdout.split("\n")[1].replace("-", "=").split("=")[1]
if self.ffmpeg:
ret = subprocess.run(
["ffmpeg", "-version"], shell=False, capture_output=True, text=True
[FFMPEG_CMD, "-version"], shell=False, capture_output=True, text=True
)
if ret.returncode == 0:
with contextlib.suppress(Exception):
version["ffmpeg"] = ret.stdout.replace("-", " ").split(" ")[2]
return version

def show_warning(self):
"""Displays the warning to the user and awaits respone."""
"""Displays the warning to the user and awaits response."""
missing = "FFmpeg"
# If ffmpeg is installed but not ffprobe
if not self.ffprobe and self.ffmpeg:
Expand Down
3 changes: 1 addition & 2 deletions tagstudio/src/qt/widgets/thumb_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
)
from PIL.Image import DecompressionBombError
from pillow_heif import register_avif_opener, register_heif_opener
from pydub import exceptions
from PySide6.QtCore import (
QBuffer,
QFile,
Expand Down Expand Up @@ -555,7 +554,7 @@ def _audio_waveform_thumb(

im.resize((size, size), Image.Resampling.BILINEAR)

except exceptions.CouldntDecodeError as e:
except Exception as e:
logger.error("Couldn't render waveform", path=filepath.name, error=type(e).__name__)

return im
Expand Down
Loading