Skip to content

Instantly share code, notes, and snippets.

@VonXXGhost
Created January 17, 2024 06:47
Show Gist options
  • Save VonXXGhost/a2f2a334cc65c6bbd90daff6b50ba542 to your computer and use it in GitHub Desktop.
Save VonXXGhost/a2f2a334cc65c6bbd90daff6b50ba542 to your computer and use it in GitHub Desktop.
使用ffmpeg的频谱图生成功能,对指定目录下的指定类型文件批量生成的Powershell脚本
$scan_types = @('.mp3', '.flac')
$scan_path = '.'
$pic_save_path = '.\spectrumpic'
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
function Get-FilesOfType {
param (
[string]$path,
[string[]]$types
)
Get-ChildItem -Path $path -File -Depth 0 |
Where-Object { $_.Extension -in $types } |
ForEach-Object { $_.FullName }
}
function Main {
# 检查 pic_save_path 是否存在,不存在则新建对应目录
if (-not (Test-Path -Path $pic_save_path)) {
New-Item -Path $pic_save_path -ItemType Directory | Out-Null
}
$log_file = Join-Path -Path $pic_save_path -ChildPath 'process.log' # 日志
$files = Get-FilesOfType -path $scan_path -types $scan_types
foreach ($file_path in $files) {
$file_name = Split-Path -Leaf $file_path
Write-Host "Processing: $file_name"
# 调用外部命令
Invoke-Expression "ffmpeg -y -i `"$file_path`" -lavfi showspectrumpic=s=1200x600:mode=combined:color=intensity `"$pic_save_path\$file_name.png`" 2>&1 | Tee-Object -FilePath $log_file -Append"
}
}
Main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment