Question

I'm somewhat of a Powershell newbie, I've been using PS purposefully as my main scripting language for about 6 months now.

I'm trying to generate a basic script using only powershell and mediainfo to parse details from files in a directory (input) to another directory (output) of individual .txt files (Ideally with original file extensions removed).

The source and output filename should be the same, eg: test.mp4 -> test.txt. Here is what I've managed so far:

$indir = "C:\Temp\input"
$outdir = "C:\Temp\output\"
$mediainfo = "C:\Temp\MediaInfo_CLI_x64\MediaInfo.exe "

$files = Get-ChildItem $indir

foreach ($file in $files )
    {
    Write-Host "Scanning " $file.FullName
    Start-Process $mediainfo $file.FullName -NoNewWindow | out-file $outdir $file.Name
    }

I'm running into a lot of issues, and I feel like the solution is quite simple.

Thanks for any assistance.

Was it helpful?

Solution

Start-Process has parameters for redirecting STDIN, STDOUT and STDERR, so try this:

Start-Process $mediainfo $file.FullName -NoNewWindow -Wait `
    -RedirectStandardOutput "$outdir\$($file.Name).txt"

Normally you'd launch external programs with the call operator (&), though, which should let you use the regular output streams:

& $mediainfo $file.FullName | Out-File "$outdir\$($file.Name).txt"

If the program doesn't write to the success output stream (STDOUT) you can redirect the other streams like this (see about_Redirection for details):

& $mediainfo $file.FullName *>&1 | Out-File "$outdir\$($file.Name).txt"

OTHER TIPS

I have compiled a DLL wrapper for MediaInfo so you can use it in PowerShell like this

add-type -path 'C:\Users\username\Documents\WindowsPowerShell\vise_mediainfo.dll'
$MediaInfo = New-Object VISE_MediaInfo.MediaInfo
#Display all codec info about this PC
$MediaInfo.Option("Info_Codecs")
#Display information about a specific file
$MediaInfo.Open('C:\Users\username\Videos\video_name.mp4')
$MediaInfo.Inform()

Download from https://ianmorrish.wordpress.com/v-ise/mediainfo/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top