Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use absolute ffprobe path on macos (Fix #511) #629

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ pillow-heif==0.16.0
pillow-jxl-plugin==1.3.0
Pillow==10.3.0
pydub==0.25.1
PySide6_Addons==6.7.1
PySide6_Essentials==6.7.1
PySide6==6.7.1
PySide6_Addons==6.8.0.1
PySide6_Essentials==6.8.0.1
PySide6==6.8.0.1
rawpy==0.21.0
SQLAlchemy==2.0.34
structlog==24.4.0
Expand Down
23 changes: 22 additions & 1 deletion tagstudio/src/qt/helpers/vendored/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,34 @@
# Vendored from ffmpeg-python and ffmpeg-python PR#790 by amamic1803

import json
import platform
import shutil
import subprocess

import ffmpeg
import structlog
from src.qt.helpers.silent_popen import promptless_Popen

logger = structlog.get_logger(__name__)

def _probe(filename, cmd="ffprobe", timeout=None, **kwargs):
FFMPEG_MACOS_LOCATIONS: list[str] = ["", "/opt/homebrew/bin/", "/usr/local/bin/"]


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


FFPROBE_CMD = _get_ffprobe_location()


def _probe(filename, cmd=FFPROBE_CMD, timeout=None, **kwargs):
"""Run ffprobe on the specified file and return a JSON representation of the output.

Raises:
Expand Down
12 changes: 6 additions & 6 deletions tagstudio/src/qt/widgets/thumb_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,24 +812,24 @@ def _image_vector_thumb(cls, filepath: Path, size: int) -> Image.Image:
"""
im: Image.Image = None
# Create an image to draw the svg to and a painter to do the drawing
image: QImage = QImage(size, size, QImage.Format.Format_ARGB32)
image.fill("#1e1e1e")
q_image: QImage = QImage(size, size, QImage.Format.Format_ARGB32)
q_image.fill("#1e1e1e")

# Create an svg renderer, then render to the painter
svg: QSvgRenderer = QSvgRenderer(str(filepath))

if not svg.isValid():
raise UnidentifiedImageError

painter: QPainter = QPainter(image)
painter: QPainter = QPainter(q_image)
svg.setAspectRatioMode(Qt.AspectRatioMode.KeepAspectRatio)
svg.render(painter)
painter.end()

# Write the image to a buffer as png
buffer: QBuffer = QBuffer()
buffer.open(QBuffer.OpenModeFlag.ReadWrite)
image.save(buffer, "PNG")
q_image.save(buffer, "PNG") # type: ignore[call-overload]

# Load the image from the buffer
im = Image.new("RGB", (size, size), color="#1e1e1e")
Expand Down Expand Up @@ -907,11 +907,11 @@ def _pdf_thumb(cls, filepath: Path, size: int) -> Image.Image:
| QPdfDocumentRenderOptions.RenderFlag.PathAliased
)
# Convert QImage to PIL Image
qimage: QImage = document.render(0, page_size.toSize(), render_options)
q_image: QImage = document.render(0, page_size.toSize(), render_options)
buffer: QBuffer = QBuffer()
buffer.open(QBuffer.OpenModeFlag.ReadWrite)
try:
qimage.save(buffer, "PNG")
q_image.save(buffer, "PNG") # type: ignore[call-overload]
im = Image.open(BytesIO(buffer.buffer().data()))
finally:
buffer.close()
Expand Down
Loading