en-US/about_VideoTools.help.txt

TOPIC
    about_VideoTools

SHORT DESCRIPTION
    Inspect media, prepare FFmpeg arguments, and manage optional libraries.

LONG DESCRIPTION
    VideoTools is a 64-bit Windows PowerShell 5.1 module. It requires GPUInfo
    1.3.1.0 or later. Make FFmpeg and FFprobe available to inspect media and
    encode. File probing can take time, particularly when counting frames.

    Import-Module VideoTools loads the commands. For scripts using class or
    enum literals such as [VideoFile], put "using module VideoTools" at the
    beginning of the script, before other statements. Use a fresh PowerShell
    session after changing module classes. Replace the sample paths in these
    examples with files on your computer.

    New-VideoFile reads a playable video and inventories its streams.
    New-VideoConversion initializes an output model from a VideoFile or a file.
    UpdateCommandLine formats a resolved request; it does not run FFmpeg.
    A request must contain its own input, output and stream settings. Changing
    a property on the model alone does not update the request.

    Stream indices identify streams within one input file. Inspect them before
    selecting tracks; do not assume an audio stream is always index 1. Check
    container and codec compatibility before running an output command.

CONSOLE VIEW
    PowerShell uses this table in the console. To select it explicitly, run

        $VO = New-VideoFile -VideoFile (Get-Item -LiteralPath 'C:\Videos\sample.mp4')
        $VO.Streams | Format-Table -View VideoTools.Streams

    The table shows stream indices, codecs, languages, titles and
    dispositions. Filter Streams by Type to focus on audio or subtitles. Use
    Format-List * to see all properties.

    To list only forced subtitles, filter the tracks before formatting.

        $VO.Streams | Where-Object { $_.Type -eq 'subtitle' -and $_.Forced } |
            Format-Table -View VideoTools.Streams

RELEASE HISTORY
    Open the English release changelog included with the module.

        Import-Module VideoTools
        Get-Content -LiteralPath (Join-Path (Get-Module VideoTools).ModuleBase 'CHANGELOG.md')

EXAMPLES
    EXAMPLE 1 - Inspect video metadata

    Probe a file and show the video properties. FrameCountSource describes
    whether the count came from metadata, an FFprobe scan or MediaInfo.
    Zero with source Unknown means no count was determined.

        Import-Module VideoTools
        $VO = New-VideoFile -VideoFile (Get-Item -LiteralPath 'C:\Videos\sample.mp4')
        $VO | Select-Object VideoCodecName, Resolution, FPS, LengthSec, TotalFrames, FrameCountSource

    EXAMPLE 2 - Inspect available tracks

    Inventory all streams, then inspect audio and subtitle details. These
    collections retain the input stream indices needed for a conversion.

        Import-Module VideoTools
        $VO = New-VideoFile -VideoFile (Get-Item -LiteralPath 'C:\Videos\sample.mp4')
        $VO.Streams | Format-Table StreamIndex, Type, Codec, Language, Title
        $VO.AudioTracks | Format-Table StreamIndex, Codec, Language, Channels, Default
        $VO.SubtitleTracks | Format-Table StreamIndex, Codec, Language, Forced

    EXAMPLE 3 - Prepare a stream-copy preview

    Reuse the inspected metadata and format a copy request. AudioStream is -1
    when no audio was selected. The returned string is only a preview: it
    does not create the output. The default is not to overwrite an existing
    output. Verify the chosen container supports the source streams.

        Import-Module VideoTools
        $source = Get-Item -LiteralPath 'C:\Videos\sample.mp4'
        $VO = New-VideoFile -VideoFile $source
        $VOt = New-VideoConversion -InputVideo $VO
        $request = @{
            InputPath = $source.FullName
            OutputPath = Join-Path $source.DirectoryName 'sample-copy.mkv'
            VideoStream = $VO.VideoStreamId
            Encoder = 'copy'
            AudioStream = $VO.AudioStreamId
            AudioCodec = 'copy'
        }
        $VOt.UpdateCommandLine($request)

    EXAMPLE 4 - Prepare an H.264 resize

    Format a software-encode request at half the original size without audio.
    It requires libx264 when executed and input dimensions divisible by four.
    This preview does not execute FFmpeg. Use a different output path from the
    input and check the preview before invoking a conversion.

        Import-Module VideoTools
        $source = Get-Item -LiteralPath 'C:\Videos\sample.mp4'
        $VO = New-VideoFile -VideoFile $source
        $VOt = New-VideoConversion -InputVideo $VO
        $request = @{
            InputPath = $source.FullName
            OutputPath = Join-Path $source.DirectoryName 'sample-half.mkv'
            VideoStream = $VO.VideoStreamId
            Encoder = 'libx264'
            AudioStream = -1
            Filters = '-vf scale=iw/2:ih/2'
            PixelFormat = '-pix_fmt yuv420p'
            Preset = 'fast'
        }
        $VOt.UpdateCommandLine($request)

    EXAMPLE 5 - Select an audio track

    Use an input containing audio. This request copies the video and the first
    audio track only. Select a different track using its StreamIndex. An
    explicit empty AudioTracks array selects no audio.

        Import-Module VideoTools
        $source = Get-Item -LiteralPath 'C:\Videos\sample.mp4'
        $VO = New-VideoFile -VideoFile $source
        $track = $VO.AudioTracks | Select-Object -First 1
        if (!$track) { throw 'The input has no audio track.' }
        $VOt = New-VideoConversion -InputVideo $VO
        $request = @{
            InputPath = $source.FullName
            OutputPath = Join-Path $source.DirectoryName 'sample-audio.mkv'
            VideoStream = $VO.VideoStreamId
            Encoder = 'copy'
            AudioTracks = @(@{ StreamIndex = $track.StreamIndex; Enabled = $true; Encoder = 'copy' })
        }
        $VOt.UpdateCommandLine($request)

    EXAMPLE 6 - Probe a standalone audio file

    Save the following as a script. The generic probe works even when the
    input has no playable video stream. Wait returns a result with State,
    Metadata and Error; check the state and dispose the operation.

        using module VideoTools
        $source = Get-Item -LiteralPath 'C:\Videos\audio.wav'
        $ffprobe = Get-Item -LiteralPath (Get-Command ffprobe.exe -CommandType Application).Source
        $probe = [VideoFile]::StartMetadataProbe($source, $ffprobe)
        try {
            $result = $probe.Wait([Threading.CancellationToken]::None)
            if ($result.State -ne 'Completed') { throw $result.Error }
            [VideoFile]::GetStreams($source, $result.Metadata) |
                Format-Table StreamIndex, Type, Codec, Language
        }
        finally { $probe.Dispose() }

    EXAMPLE 7 - Count the selected video stream

    Save this as a script. It first probes metadata, then starts a count for
    the selected video stream. The count can use existing metadata, an
    FFprobe scan or MediaInfo. A long scan may take up to 15 minutes before
    fallback. Dispose both operations even if a probe fails.

        using module VideoTools
        $source = Get-Item -LiteralPath 'C:\Videos\sample.mp4'
        $ffprobe = Get-Item -LiteralPath (Get-Command ffprobe.exe -CommandType Application).Source
        $probe = [VideoFile]::StartMetadataProbe($source, $ffprobe)
        try {
            $result = $probe.Wait([Threading.CancellationToken]::None)
            if ($result.State -ne 'Completed') { throw $result.Error }
            $VO = [VideoFile]::new()
            $VO.FFprobe = $ffprobe
            $VO.LoadMetadata($source, $result.Metadata, $false)
            $count = $VO.StartFrameCountProbe($source, $result.Metadata, $VO.VideoStreamId)
            try { $count.Wait([Threading.CancellationToken]::None) }
            finally { $count.Dispose() }
        }
        finally { $probe.Dispose() }

    EXAMPLE 8 - Read a MediaInfo report

    Save this as a script. It reads a report using the selected MediaInfo DLL
    without installing or updating anything. The operation must be disposed.

        using module VideoTools
        $source = Get-Item -LiteralPath 'C:\Videos\sample.mp4'
        $probe = [MediaInfo]::StartProbe($source)
        try {
            $result = $probe.Wait([Threading.CancellationToken]::None)
            if ($result.State -ne 'Completed') { throw $result.Error }
            $result.Metadata.media.track | Select-Object '@type', Format, Duration
        }
        finally { $probe.Dispose() }

    EXAMPLE 9 - Update MediaInfo

    Save this as a script and run it as a standard user only when an update is
    wanted. It downloads and verifies MediaInfo, then activates it in the
    per-user store. Check State and Error; a failed update preserves the
    existing working copy.

        using module VideoTools
        $result = [VideoFile]::UpdateMediaInfo()
        if ($result.State -ne 'Completed') { throw $result.Error }
        $result | Select-Object State, Version, Path

    EXAMPLE 10 - Run and inspect a software conversion

    Save this as a script. It requires FFmpeg with libx264 and input dimensions
    divisible by four. This example writes a new file and refuses to overwrite
    an existing output. It reads both redirected process streams concurrently,
    checks FFmpeg's exit code and then probes the finished video.

        using module VideoTools
        $source = Get-Item -LiteralPath 'C:\Videos\sample.mp4'
        $ffmpeg = Get-Item -LiteralPath (Get-Command ffmpeg.exe -CommandType Application).Source
        $VO = [VideoFile]::new($source)
        $VOt = [VideoConversion]::new()
        $output = Join-Path $source.DirectoryName 'sample-encoded.mkv'
        $VOt.Initialize($VO, $output, $false, @())
        $request = @{
            InputPath = $source.FullName
            OutputPath = $output
            VideoStream = $VO.VideoStreamId
            Encoder = 'libx264'
            AudioStream = -1
            Filters = '-vf scale=iw/2:ih/2'
            PixelFormat = '-pix_fmt yuv420p'
            Preset = 'fast'
        }
        $arguments = $VOt.UpdateCommandLine($request)
        $process = [FFmpeg]::StartEncoding($ffmpeg, $arguments)
        try {
            $progress = $process.StandardOutput.ReadToEndAsync()
            $errors = $process.StandardError.ReadToEndAsync()
            $process.WaitForExit()
            if ($process.ExitCode -ne 0) { throw $errors.Result }
        }
        finally { $process.Dispose() }
        $result = [VideoFile]::new((Get-Item -LiteralPath $output))
        $result | Select-Object VideoCodecName, Resolution

    EXAMPLE 11 - Inspect optional libraries and tools

    Save this as a script. This only inspects managed tools and libraries; it
    does not download them. An empty result means that the corresponding
    managed bundle is unavailable, even if executables are on the PATH.

        using module VideoTools
        [FFmpeg]::GetExecutableTools() | Select-Object Version, FFmpeg, FFprobe
        [FFmpeg]::GetVersion()
        [MediaInfo]::GetLibrary() | Select-Object FullName

TROUBLESHOOTING
    If PowerShell cannot find a class, use a script with "using module
    VideoTools" at the top and ensure VideoTools and GPUInfo are discoverable.
    If FFprobe is missing, install it or pass its executable path to a probe.
    Check State and Error before reading asynchronous results; Cancel() stops
    pending operations and Dispose() releases them. Probe results can be
    Pending, Completed, Failed, TimedOut or Cancelled.

    A formatted command is not proof that FFmpeg can encode it. Check the
    encoder, driver, pixel format and output container, then inspect FFmpeg
    errors and verify the resulting streams with FFprobe.

    GPUInfo tables describe reference capabilities. Use the executable probe
    to confirm that the current FFmpeg build and driver can encode at a
    tested bit depth. For decoding, test the selected input stream.
    See Docs\Class-Manual.md for the executable and decoder probes.

SEE ALSO
    Get-Help New-VideoFile -Full
    Get-Help New-VideoConversion -Examples
    https://github.com/hacksoft2/VideoTools