Отчёт по битрейту и длительности
Собирает CSV с кодеком, битрейтом, частотой, каналами и подозрительно короткими треками.
Что делает скрипт
Скрипт проходит по библиотеке и читает параметры каждого файла через ffprobe. В отчёт попадают кодек, битрейт, sample rate, каналы, длительность и теги. Файлы с низким битрейтом или короткой длительностью помечаются, чтобы их можно было проверить вручную.
Быстрый старт
powershell -File Get-AudioReport.ps1 -Path C:\Music -Csv audio-report.csv
Скачайте файл, откройте терминал в папке со скриптом и выполните команду. Запускайте в PowerShell 5.1 или PowerShell 7.
Другие варианты
powershell -File Get-AudioReport.ps1 -Path C:\Music -Csv C:\Reports\audio.csvpowershell -File Get-AudioReport.ps1 -Path D:\Podcasts -LowKbps 96 -MinDuration 30
Что понадобится
Встроен в Windows 10/11 (PowerShell 5.1)
winget install Gyan.FFmpeg
Get-AudioReport.ps1
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$Path,
[string]$Csv,
[ValidateRange(8, 1024)]
[int]$LowKbps = 128,
[ValidateRange(1, 3600)]
[int]$MinDuration = 5
)
$ErrorActionPreference = 'Stop'
$ffprobe = Get-Command ffprobe -ErrorAction SilentlyContinue
if (-not $ffprobe) {
throw 'ffprobe не найден. Установите FFmpeg через winget.'
}
$resolved = Resolve-Path -LiteralPath $Path -ErrorAction Stop
$extensions = @('.mp3', '.wav', '.flac', '.ogg', '.m4a', '.aac', '.wma')
if (Test-Path -LiteralPath $resolved.Path -PathType Container) {
$files = @(Get-ChildItem -LiteralPath $resolved.Path -File -Recurse -ErrorAction SilentlyContinue |
Where-Object { $extensions -contains $_.Extension.ToLowerInvariant() })
} else {
$item = Get-Item -LiteralPath $resolved.Path
if ($extensions -notcontains $item.Extension.ToLowerInvariant()) {
throw "Формат не похож на аудио: $($item.Extension)"
}
$files = @($item)
}
if ($files.Count -eq 0) {
Write-Host 'Аудиофайлы не найдены.'
exit 0
}
$records = @()
foreach ($file in $files) {
$raw = & $ffprobe.Source -v quiet -print_format json -show_format -show_streams $file.FullName
if ($LASTEXITCODE -ne 0) {
Write-Host "Пропуск: $($file.FullName)" -ForegroundColor Red
continue
}
try {
$info = $raw | ConvertFrom-Json
} catch {
Write-Host "Пропуск: $($file.FullName): некорректный JSON" -ForegroundColor Red
continue
}
$audio = @($info.streams | Where-Object { $_.codec_type -eq 'audio' }) | Select-Object -First 1
if (-not $audio) {
Write-Host "Пропуск: нет аудиопотока в $($file.FullName)" -ForegroundColor Red
continue
}
$bitrate = [int64]0
if ($audio.bit_rate) {
[void][int64]::TryParse([string]$audio.bit_rate, [ref]$bitrate)
}
if ($bitrate -le 0 -and $info.format.bit_rate) {
[void][int64]::TryParse([string]$info.format.bit_rate, [ref]$bitrate)
}
$kbps = if ($bitrate -gt 0) { [math]::Round($bitrate / 1000, 0) } else { 0 }
$duration = 0.0
if ($info.format.duration) {
[void][double]::TryParse([string]$info.format.duration, [ref]$duration)
}
$tags = $info.format.tags
$artist = if ($tags -and $tags.artist) { [string]$tags.artist } else { '' }
$title = if ($tags -and $tags.title) { [string]$tags.title } else { '' }
$flags = @()
if ($kbps -gt 0 -and $kbps -lt $LowKbps) { $flags += 'низкий битрейт' }
if ($duration -gt 0 -and $duration -lt $MinDuration) { $flags += 'короткий файл' }
$records += [pscustomobject]@{
File = $file.FullName
Codec = [string]$audio.codec_name
BitrateKbps = $kbps
SampleRate = [int]$audio.sample_rate
Channels = [int]$audio.channels
DurationSec = [math]::Round($duration, 2)
SizeMB = [math]::Round($file.Length / 1MB, 2)
Artist = $artist
Title = $title
Flags = ($flags -join '; ')
}
}
if ($records.Count -eq 0) {
Write-Host 'Не удалось прочитать ни одного файла.'
exit 1
}
$records | Format-Table File, Codec, BitrateKbps, SampleRate, Channels, DurationSec, Flags -AutoSize
$low = @($records | Where-Object { $_.Flags -match 'низкий' }).Count
$short = @($records | Where-Object { $_.Flags -match 'короткий' }).Count
Write-Host "Файлов: $($records.Count), с низким битрейтом: $low, коротких: $short"
if ($Csv) {
$csvPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Csv)
$records | Export-Csv -LiteralPath $csvPath -NoTypeInformation -Encoding UTF8
Write-Host "Отчёт сохранён: $csvPath"
}
Скрипты работают с файлами и настройками системы. Перед запуском прочитайте код и проверьте пути. Особенно если скрипт удаляет, перезаписывает или перемещает данные.