Created
May 27, 2015 08:51
-
-
Save imorrish/58d637aeaf918acfba14 to your computer and use it in GitHub Desktop.
PowerShell to start recording on multiple Blackmagic HyperDeck devices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# record on multiple HyperDecks | |
$HyperDecks = @('10.0.0.34','10.0.0.35','10.0.0.36','10.0.0.37') | |
$fileName = 'Recording' + (Get-Date).tostring("dd_MM_yyyy_hh_mm") | |
$sb = { | |
param ([string] $HyperDeckIP, [string] $HDcommand) | |
try { | |
$socket = new-object System.Net.Sockets.TcpClient($HyperDeckIP, 9993) | |
$stream = $socket.GetStream() | |
$writer = new-object System.IO.StreamWriter($stream) | |
$buffer = new-object System.Byte[] 1024 | |
$encoding = new-object System.Text.AsciiEncoding | |
$writer.WriteLine('remote: override: true') | |
$writer.Flush() | |
#Start-Sleep -m 50 | |
$writer.WriteLine($HDcommand) | |
$writer.Flush() | |
$writer.Close() | |
while($stream.DataAvailable) { | |
$read = $stream.Read($buffer, 0, 1024) | |
$HyperDeckInfo = ($encoding.GetString($buffer, 0, $read)) | |
} | |
$stream.Close() | |
return $HyperDeckInfo | |
} catch { | |
throw 'Failed to process HyperDeck {0}. The error was "{1}".' -f $HyperDeck, $_ | |
} | |
} | |
# Loop through each HyperDeck | |
$jobs = @() | |
foreach($HyperDeck in $HyperDecks) { | |
$jobs += Start-Job -ScriptBlock $sb -ArgumentList $HyperDeck, 'record: name:' + $fileName | |
} | |
# Wait for remaining. | |
Wait-Job -Job $jobs > $null | |
do {$strResponse = Read-Host "q when you want to stop recording?" | |
} | |
until ($strResponse -eq 'q') | |
foreach($HyperDeck in $HyperDecks) { | |
$jobs += Start-Job -ScriptBlock $sb -ArgumentList $HyperDeck, 'stop' | |
} | |
# Check for failed jobs. | |
$failed = @($jobs | ? {$_.State -eq 'Failed'}) | |
if ($failed.Count -gt 0) { | |
$failed | % { | |
$_.ChildJobs[0].JobStateInfo.Reason.Message | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment