From e30242977b4346f3e658cfd8317bf47d9be269fe Mon Sep 17 00:00:00 2001 From: XXXXRT666 <157766680+XXXXRT666@users.noreply.github.com> Date: Thu, 15 May 2025 13:19:00 +0100 Subject: [PATCH] Expose FFmpeg Errors, Copy Only Part of Visual C++ Runtime --- .github/build_windows_packages.ps1 | 14 ++++++-------- tools/my_utils.py | 10 ++++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/build_windows_packages.ps1 b/.github/build_windows_packages.ps1 index 68937386..a23b7766 100644 --- a/.github/build_windows_packages.ps1 +++ b/.github/build_windows_packages.ps1 @@ -52,20 +52,19 @@ $tar = Get-ChildItem "$tmpDir" -Filter "*.tar" | Select-Object -First 1 & "C:\Program Files\7-Zip\7z.exe" x $tar.FullName -o"$tmpDir\extracted" -aoa Move-Item "$tmpDir\extracted\python\install" "$srcDir\runtime" +Write-Host "[INFO] Copying Redistributing Visual C++ Runtime..." $vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" $vsPath = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath $redistRoot = Join-Path $vsPath "VC\Redist\MSVC" -Get-ChildItem $redistRoot $targetVer = Get-ChildItem -Path $redistRoot -Directory | Where-Object { $_.Name -match "^14\." } | Sort-Object Name -Descending | Select-Object -First 1 $x64Path = Join-Path $targetVer.FullName "x64" -Write-Host 111 -Get-ChildItem $x64Path -Get-ChildItem -Path $x64Path -Directory -Filter "Microsoft.*" | ForEach-Object { +Get-ChildItem -Path $x64Path -Directory | Where-Object { + $_.Name -match '^Microsoft\..*\.(CRT|OpenMP)$' +} | ForEach-Object { Get-ChildItem -Path $_.FullName -Filter "*.dll" | ForEach-Object { - Write-Host "Copy $($_.FullName)" Copy-Item -Path $_.FullName -Destination "$srcDir\runtime" -Force } } @@ -82,7 +81,6 @@ function DownloadAndUnzip($url, $targetRelPath) { if (Test-Path $destPath) { Remove-Item $destPath -Recurse -Force } - Move-Item $sourcePath $destRoot Remove-Item $tmpZip } @@ -109,8 +107,8 @@ $ffZip = "$tmpDir\ffmpeg.zip" Invoke-WebRequest -Uri $ffUrl -OutFile $ffZip Expand-Archive $ffZip -DestinationPath $tmpDir -Force $ffDir = Get-ChildItem -Directory "$tmpDir" | Where-Object { $_.Name -like "ffmpeg*" } | Select-Object -First 1 -Move-Item "$($ffDir.FullName)\bin\ffmpeg.exe" "$srcDir" -Move-Item "$($ffDir.FullName)\bin\ffprobe.exe" "$srcDir" +Move-Item "$($ffDir.FullName)\bin\ffmpeg.exe" "$srcDir\runtime" +Move-Item "$($ffDir.FullName)\bin\ffprobe.exe" "$srcDir\runtime" Remove-Item $ffZip Remove-Item $ffDir.FullName -Recurse -Force diff --git a/tools/my_utils.py b/tools/my_utils.py index 7f70db26..59a7cd3c 100644 --- a/tools/my_utils.py +++ b/tools/my_utils.py @@ -1,8 +1,6 @@ import ctypes -import glob import os import sys -import traceback from pathlib import Path import ffmpeg @@ -21,7 +19,7 @@ def load_audio(file, sr): # This launches a subprocess to decode audio while down-mixing and resampling as necessary. # Requires the ffmpeg CLI and `ffmpeg-python` package to be installed. file = clean_path(file) # 防止小白拷路径头尾带了空格和"和回车 - if os.path.exists(file) == False: + if os.path.exists(file) is False: raise RuntimeError("You input a wrong audio path that does not exists, please fix it!") out, _ = ( ffmpeg.input(file, threads=0) @@ -29,7 +27,11 @@ def load_audio(file, sr): .run(cmd=["ffmpeg", "-nostdin"], capture_stdout=True, capture_stderr=True) ) except Exception: - traceback.print_exc() + out, _ = ( + ffmpeg.input(file, threads=0) + .output("-", format="f32le", acodec="pcm_f32le", ac=1, ar=sr) + .run(cmd=["ffmpeg", "-nostdin"], capture_stdout=True) + ) # Expose the Error raise RuntimeError(i18n("音频加载失败")) return np.frombuffer(out, np.float32).flatten()