Отчёт по кодекам видео
Собирает таблицу с кодеком, разрешением, длительностью и битрейтом каждого файла.
Что делает скрипт
Скрипт читает метаданные через ffprobe и извлекает первый видеопоток и первый аудиопоток. Результат можно смотреть в консоли или выгрузить в CSV для инвентаризации. Файлы не изменяются.
Быстрый старт
powershell -File Get-VideoReport.ps1 -Path C:\video
Скачайте файл, откройте терминал в папке со скриптом и выполните команду. Запускайте в PowerShell 5.1 или PowerShell 7.
Другие варианты
powershell -File Get-VideoReport.ps1 -Path C:\videopowershell -File Get-VideoReport.ps1 -Path .\media -Recurse -Csv video-report.csvpowershell -File Get-VideoReport.ps1 -Path D:\films -Extensions mkv,mp4
Что понадобится
Встроен в Windows 10/11 (PowerShell 5.1)
winget install Gyan.FFmpeg
Get-VideoReport.ps1
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$Path,
[switch]$Recurse,
[string[]]$Extensions = @('mp4', 'mkv', 'webm', 'mov', 'avi', 'm4v', 'ts'),
[string]$Csv
)
$ErrorActionPreference = 'Stop'
foreach ($tool in @('ffmpeg', 'ffprobe')) {
if (-not (Get-Command $tool -ErrorAction SilentlyContinue)) {
throw "$tool не найден в PATH. Установите FFmpeg."
}
}
if (-not (Test-Path -LiteralPath $Path -PathType Container)) {
throw "Папка не найдена: $Path"
}
function Convert-Rate {
param([string]$Value)
if ($Value -match '^(\d+)/(\d+)$') {
$numerator = [double]$matches[1]
$denominator = [double]$matches[2]
if ($denominator -ne 0) {
return [math]::Round($numerator / $denominator, 2)
}
}
if ($Value -match '^\d+([.]\d+)?$') {
return [double]$Value
}
return 0
}
$root = (Resolve-Path -LiteralPath $Path).Path
$wanted = $Extensions | ForEach-Object { $_.TrimStart('.').ToLowerInvariant() }
$files = @(
Get-ChildItem -LiteralPath $root -File -Recurse:$Recurse |
Where-Object { $wanted -contains $_.Extension.TrimStart('.').ToLowerInvariant() }
)
if ($files.Count -eq 0) {
Write-Host 'Видеофайлы не найдены.'
return
}
$results = foreach ($file in $files) {
$jsonText = & ffprobe -v error -print_format json -show_format -show_streams $file.FullName 2>$null | Out-String
if ($LASTEXITCODE -ne 0) {
Write-Warning "Пропуск, ffprobe не прочитал файл: $($file.FullName)"
continue
}
try {
$info = $jsonText | ConvertFrom-Json
}
catch {
Write-Warning "Пропуск, некорректный JSON: $($file.FullName)"
continue
}
$video = $info.streams | Where-Object { $_.codec_type -eq 'video' } | Select-Object -First 1
$audio = $info.streams | Where-Object { $_.codec_type -eq 'audio' } | Select-Object -First 1
$duration = 0.0
if ($info.format.duration) { $duration = [double]$info.format.duration }
$size = 0.0
if ($info.format.size) { $size = [double]$info.format.size }
$bitrate = 0.0
if ($info.format.bit_rate) { $bitrate = [double]$info.format.bit_rate }
$videoCodec = ''
$width = 0
$height = 0
$fps = 0
if ($video) {
$videoCodec = [string]$video.codec_name
$width = [int]$video.width
$height = [int]$video.height
$fps = Convert-Rate ([string]$video.r_frame_rate)
}
$audioCodec = ''
$channels = 0
if ($audio) {
$audioCodec = [string]$audio.codec_name
$channels = [int]$audio.channels
}
[pscustomobject]@{
File = $file.FullName
DurationSec = [math]::Round($duration, 1)
SizeMB = [math]::Round($size / 1MB, 2)
VideoCodec = $videoCodec
Width = $width
Height = $height
Fps = $fps
AudioCodec = $audioCodec
Channels = $channels
BitrateKbps = [math]::Round($bitrate / 1000, 0)
}
}
$results | Format-Table -AutoSize
if ($Csv) {
$results | Export-Csv -LiteralPath $Csv -NoTypeInformation -Encoding UTF8
Write-Host "Отчёт сохранён: $Csv"
}
Скрипты работают с файлами и настройками системы. Перед запуском прочитайте код и проверьте пути. Особенно если скрипт удаляет, перезаписывает или перемещает данные.