Spaces:
Sleeping
Sleeping
hugh2023
Add multi-modal agent system with media analysis, web scraping, and enhanced configuration management
adec1cb | #!/usr/bin/env python3 | |
| """ | |
| 检查ffmpeg安装情况 | |
| """ | |
| import subprocess | |
| import os | |
| import sys | |
| def check_ffmpeg(): | |
| """检查ffmpeg是否可用""" | |
| print("🔍 检查ffmpeg安装情况...") | |
| # 方法1: 检查系统PATH中的ffmpeg | |
| try: | |
| result = subprocess.run(['ffmpeg', '-version'], | |
| capture_output=True, text=True, timeout=10) | |
| if result.returncode == 0: | |
| print("✅ ffmpeg在系统PATH中可用") | |
| print(f" 版本信息: {result.stdout.split('ffmpeg version')[1].split('\n')[0]}") | |
| return True | |
| except (subprocess.TimeoutExpired, FileNotFoundError, subprocess.CalledProcessError): | |
| print("❌ ffmpeg不在系统PATH中") | |
| # 方法2: 检查conda环境中的ffmpeg | |
| try: | |
| conda_prefix = os.environ.get('CONDA_PREFIX') | |
| if conda_prefix: | |
| ffmpeg_path = os.path.join(conda_prefix, 'bin', 'ffmpeg') | |
| if os.path.exists(ffmpeg_path): | |
| print(f"✅ 在conda环境中找到ffmpeg: {ffmpeg_path}") | |
| return True | |
| else: | |
| print(f"❌ conda环境中没有ffmpeg: {ffmpeg_path}") | |
| except Exception as e: | |
| print(f"❌ 检查conda环境失败: {e}") | |
| # 方法3: 检查常见的ffmpeg安装路径 | |
| common_paths = [ | |
| r"C:\ffmpeg\bin\ffmpeg.exe", | |
| r"C:\Program Files\ffmpeg\bin\ffmpeg.exe", | |
| r"C:\Program Files (x86)\ffmpeg\bin\ffmpeg.exe", | |
| os.path.expanduser(r"~\ffmpeg\bin\ffmpeg.exe") | |
| ] | |
| for path in common_paths: | |
| if os.path.exists(path): | |
| print(f"✅ 找到ffmpeg: {path}") | |
| return True | |
| print("❌ 未找到ffmpeg") | |
| return False | |
| def install_ffmpeg_conda(): | |
| """通过conda安装ffmpeg""" | |
| print("\n📦 尝试通过conda安装ffmpeg...") | |
| try: | |
| result = subprocess.run(['conda', 'install', '-c', 'conda-forge', 'ffmpeg', '-y'], | |
| capture_output=True, text=True, timeout=60) | |
| if result.returncode == 0: | |
| print("✅ ffmpeg安装成功") | |
| return True | |
| else: | |
| print(f"❌ ffmpeg安装失败: {result.stderr}") | |
| return False | |
| except Exception as e: | |
| print(f"❌ conda安装失败: {e}") | |
| return False | |
| def install_ffmpeg_pip(): | |
| """通过pip安装ffmpeg-python""" | |
| print("\n📦 尝试通过pip安装ffmpeg-python...") | |
| try: | |
| result = subprocess.run([sys.executable, '-m', 'pip', 'install', 'ffmpeg-python'], | |
| capture_output=True, text=True, timeout=60) | |
| if result.returncode == 0: | |
| print("✅ ffmpeg-python安装成功") | |
| return True | |
| else: | |
| print(f"❌ ffmpeg-python安装失败: {result.stderr}") | |
| return False | |
| except Exception as e: | |
| print(f"❌ pip安装失败: {e}") | |
| return False | |
| def test_audio_without_ffmpeg(): | |
| """测试不使用ffmpeg的音频处理""" | |
| print("\n🎵 测试不使用ffmpeg的音频处理...") | |
| try: | |
| import yt_dlp | |
| print("✅ yt-dlp可用") | |
| # 测试下载音频(不转换格式) | |
| test_url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ" | |
| ydl_opts = { | |
| 'format': 'bestaudio/best', | |
| 'outtmpl': 'downloads/test_audio.%(ext)s', | |
| 'quiet': True | |
| } | |
| with yt_dlp.YoutubeDL(ydl_opts) as ydl: | |
| info = ydl.extract_info(test_url, download=True) | |
| audio_path = ydl.prepare_filename(info) | |
| if os.path.exists(audio_path): | |
| print(f"✅ 音频下载成功: {audio_path}") | |
| print(f" 文件大小: {os.path.getsize(audio_path)} bytes") | |
| return True | |
| else: | |
| print(f"❌ 音频下载失败") | |
| return False | |
| except Exception as e: | |
| print(f"❌ 音频处理测试失败: {e}") | |
| return False | |
| def main(): | |
| print("🔧 ffmpeg检查和安装工具") | |
| print("="*50) | |
| # 检查ffmpeg | |
| ffmpeg_available = check_ffmpeg() | |
| if not ffmpeg_available: | |
| print("\n📋 解决方案:") | |
| print("1. 通过conda安装ffmpeg") | |
| print("2. 手动下载ffmpeg并添加到PATH") | |
| print("3. 使用不依赖ffmpeg的音频处理方法") | |
| choice = input("\n选择解决方案 (1/2/3): ").strip() | |
| if choice == "1": | |
| install_ffmpeg_conda() | |
| elif choice == "2": | |
| print("请手动下载ffmpeg并添加到系统PATH") | |
| print("下载地址: https://ffmpeg.org/download.html") | |
| elif choice == "3": | |
| test_audio_without_ffmpeg() | |
| else: | |
| print("无效选择") | |
| else: | |
| print("\n✅ ffmpeg已可用,可以正常进行音频处理") | |
| test_audio_without_ffmpeg() | |
| if __name__ == "__main__": | |
| main() | |