Get-FFProbeAudioStreams.ps1


Description

Purpose

Retrieve structured audio stream metadata for a video file using ffprobe.

Detailed Description

Get-FFProbeAudioStreams wraps ffprobe to output the audio streams from a media file as easy-to-filter PowerShell objects. It parses ffprobe’s JSON response, returning each stream with its index, codec, language tag, and originating file path. The function accepts a literal path or pipeline input, making it simple to chain with file discovery commands or pass the results directly into Remove-FFMpegVideoFileAudioStream.

Back to Top

Usage

Example 1

Get-FFProbeAudioStreams -VideoFile "C:\\Media\\Movies\\Alien (1979).mkv"

Returns all audio streams for the specified video file as structured objects.

Example 2

"C:\\Media\\Movies\\Alien (1979).mkv" | Get-FFProbeAudioStreams

Demonstrates pipeline input, outputting the same stream information without explicitly naming the parameter.

Example 3

Get-FFProbeAudioStreams -VideoFile "C:\\Media\\Movies\\Alien (1979).mkv" | Where-Object { $_.Language -eq 'eng' }

Filters the returned streams to locate the English-language track before taking further action.

Back to Top

Notes

  • Requires the ffprobe executable to be available on the system PATH. Install FFmpeg using FFMpeg-Install if needed.
  • Outputs objects with index, codec_name, Language, and File properties to simplify filtering or piping into other automation.
  • Designed to feed directly into Remove-FFMpegVideoFileAudioStream for automated audio stream removal.

Back to Top


Script

<#
.SYNOPSIS
Gets audio stream information from a video file using ffprobe.

.DESCRIPTION
Parses ffprobe JSON output to retrieve audio stream details including index, codec, language, and file path.

.PARAMETER VideoFile
The video file to analyze. Accepts pipeline input.

.EXAMPLE
Get-FFProbeAudioStreams -VideoFile "C:\movies\Alien (1979).mkv"

.EXAMPLE
"C:\movies\Alien (1979).mkv" | Get-FFProbeAudioStreams

#>
function Get-FFProbeAudioStreams {
    [CmdletBinding()]
    param (
        [Parameter(ValueFromPipeline = $true, Position = 0, HelpMessage = "The video file to analyze.")]
        [string]$VideoFile
    )

    process {
        try {
            $json = ffprobe -v quiet -print_format json -show_streams $VideoFile 2>$null
            if ($LASTEXITCODE -ne 0) {
                Write-Error "ffprobe failed to analyze $VideoFile"
                return
            }

            $data = $json | ConvertFrom-Json
            $audioStreams = $data.streams | Where-Object { $_.codec_type -eq 'audio' } |
            Select-Object index, codec_name,
            @{Name = 'Language'; Expression = { $_.tags.language } },
            @{Name = 'File'; Expression = { $VideoFile } }

            return $audioStreams
        }
        catch {
            Write-Error "Error processing $VideoFile : $_"
        }
    }
}

Back to Top

Download

Please feel free to copy parts of the script or if you would like to download the entire script, simply click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.


Report Issues

You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.

Issue


Back to Top