Skip to content

Instantly share code, notes, and snippets.

@mark05e
Created January 2, 2025 19:13
Show Gist options
  • Save mark05e/ed21d843c05d74a5c0634be3f514f0c3 to your computer and use it in GitHub Desktop.
Save mark05e/ed21d843c05d74a5c0634be3f514f0c3 to your computer and use it in GitHub Desktop.
@echo off
:: Display the full path of this batch file for debugging
:: echo Debug: Batch file path: %~f0
:: Get the full path of this batch file
set "batchFilePath=%~f0"
:: Get the base name (without extension) of the batch file
set "baseName=%~n0"
:: echo Debug: Base name of batch file: %baseName%
:: Set the path for the corresponding PowerShell script by appending .ps1
set "psScriptPath=%batchFilePath%\..\%baseName%.ps1"
:: echo Debug: PowerShell script path: %psScriptPath%
:: Check if the PowerShell script exists
if not exist "%psScriptPath%" (
echo Error: PowerShell script not found: "%psScriptPath%"
pause
exit /b 1
)
:: Debug: Confirm the PowerShell script exists
:: echo Debug: PowerShell script found. Preparing to execute...
:: Run the PowerShell script
echo Debug: Executing PowerShell script...
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%psScriptPath%" %*
:: Capture the error level returned by PowerShell
set "exitCode=%errorlevel%"
:: echo Debug: PowerShell script exited with code: %exitCode%
PAUSE
:: Exit with the same code as the PowerShell script
exit /b %exitCode%
# Set the path to ffprobe.exe
$ffprobePath = "C:\MarkTools\ffmpeg\bin\ffprobe.exe"
# Check if ffprobe exists
if (-Not (Test-Path $ffprobePath)) {
Write-Error "ffprobe.exe not found at $ffprobePath"
exit 1
}
# Check if file paths are provided
if (-Not $args) {
Write-Host "Usage: .\Analyze-Audio.ps1 <file1> <file2> ..."
exit 1
}
# Loop through each file path
foreach ($filePath in $args) {
# Validate file existence
if (-Not (Test-Path $filePath)) {
Write-Host "File not found: $filePath"
continue
}
# Run ffprobe and get JSON output
$ffprobeOutput = & $ffprobePath -v quiet -print_format json -show_format -show_streams $filePath | ConvertFrom-Json
# Extract desired keys
$audioStream = $ffprobeOutput.streams | Where-Object { $_.codec_type -eq "audio" }
$format = $ffprobeOutput.format
# Output extracted data
Write-Host "File: $filePath"
Write-Host "codec_name: $($audioStream.codec_name)"
Write-Host "codec_long_name: $($audioStream.codec_long_name)"
Write-Host "codec_type: $($audioStream.codec_type)"
# Write-Host "codec_tag_string: $($audioStream.codec_tag_string)"
# Write-Host "codec_tag: $($audioStream.codec_tag)"
Write-Host "sample_fmt: $($audioStream.sample_fmt)"
Write-Host "sample_rate: $($audioStream.sample_rate)"
Write-Host "channels: $($audioStream.channels)"
Write-Host "bits_per_sample: $($audioStream.bits_per_sample)"
Write-Host "bit_rate: $($audioStream.bit_rate)"
Write-Host "filename: $($format.filename)"
# Write-Host "bit_rate: $($format.bit_rate)"
Write-Host "============================================="
# Check if the values match the required conditions
if ($audioStream.codec_name -eq "pcm_mulaw" -and
$audioStream.codec_long_name -eq "PCM mu-law / G.711 mu-law" -and
$audioStream.codec_type -eq "audio" -and
$audioStream.sample_fmt -eq "s16" -and
$audioStream.sample_rate -eq 8000 -and
$audioStream.channels -eq 1 -and
$audioStream.bits_per_sample -eq 8 -and
$audioStream.bit_rate -eq 64000) {
# Output "OK" in green if the conditions match
Write-Host "OK" -ForegroundColor Green
}
else {
# If the conditions do not match, print "Mismatch"
Write-Host "Mismatch" -ForegroundColor Red
}
Write-Host "============================================="
}
@mark05e
Copy link
Author

mark05e commented Jan 2, 2025

Sample Output

File: C:\Converted\Mass_PM_Meeting_SPA.wav
codec_name: pcm_mulaw
codec_long_name: PCM mu-law / G.711 mu-law
codec_type: audio
sample_fmt: s16
sample_rate: 8000
channels: 1
bits_per_sample: 8
bit_rate: 64000
filename: C:\Converted\Mass_PM_Meeting_SPA.wav
=============================================
OK
=============================================
File: C:\Converted\Mass_PM_Open_SPA.wav
codec_name: pcm_mulaw
codec_long_name: PCM mu-law / G.711 mu-law
codec_type: audio
sample_fmt: s16
sample_rate: 8000
channels: 1
bits_per_sample: 8
bit_rate: 64000
filename: C:\Converted\Mass_PM_Open_SPA.wav
=============================================
OK
=============================================

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment