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

Mac 下 ffmpeg 的查找问题 #54

Open
3 tasks done
WangLaoShi opened this issue Jun 17, 2024 · 0 comments
Open
3 tasks done

Mac 下 ffmpeg 的查找问题 #54

WangLaoShi opened this issue Jun 17, 2024 · 0 comments
Labels
enhancement New feature or request env Related to execution environment help wanted Extra attention is needed

Comments

@WangLaoShi
Copy link

阅读 README.md 和 dependencies.md

  • 我已经阅读过 README.md 和 dependencies.md 文件

检索 issue 和 discussion

  • 我已经确认之前没有 issue 或 discussion 涉及此 BUG

检查 Forge 版本

  • 我已经确认问题发生在最新代码或稳定版本中

你的issues

在 Mac 系统中,即使安装了 ffmpeg 也无法被加载到,Windows 下是使用拷贝文件到方式,但是Mac下不好拷贝。所以我用到的方法如下:

modules/ffmpeg_env.py

import os
from modules.utils.constants import ROOT_DIR
import logging
import subprocess

logger = logging.getLogger(__name__)

def find_ffmpeg_path():
    try:
        # 执行命令查找ffmpeg路径
        result = subprocess.run(['which', 'ffmpeg'], capture_output=True, text=True)
        ffmpeg_path = result.stdout.strip()
        if ffmpeg_path:
            print(f"ffmpeg found at: {ffmpeg_path}")
            return ffmpeg_path
        else:
            print("ffmpeg not found.")
            return None
    except Exception as e:
        print(f"Error finding ffmpeg: {e}")
        return None


def setup_ffmpeg_path():
    ffmpeg_path = os.path.join(ROOT_DIR, "ffmpeg")
    import platform

    # 获取当前系统名称
    system = platform.system()

    if system == 'Darwin':
        print("当前系统是 Mac 系统")
        # 调用函数查找ffmpeg路径
        ffmpeg_path = find_ffmpeg_path()
    else:
        print(f"当前系统是 {system} 系统")

    logger.info("ffmpeg_path=" + str(ffmpeg_path))
    os.environ["PATH"] = ffmpeg_path + os.pathsep + os.environ["PATH"]

    import pydub.utils

    if pydub.utils.which("ffmpeg") is None:
        logger.error("ffmpeg not found in PATH")
        raise Exception("ffmpeg not found in PATH")
@zhzLuke96 zhzLuke96 added enhancement New feature or request help wanted Extra attention is needed env Related to execution environment labels Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request env Related to execution environment help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants