Last active
July 14, 2018 04:01
-
-
Save imorrish/cb01b644d47ce7f9061f6dc5c15fb6c1 to your computer and use it in GitHub Desktop.
Gang record Blackmagic Huperdecks with file name matching source using Windows Task Scheduler
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
# Start recording on multiple Hyperdeck's using Windows Scheduled task | |
# | |
# Executable: “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe” | |
# Arguments: -NoProfile -NonInteractive -command ". c:\scripts\ScheduledRecord.ps1; exit $LASTEXITCODE" | |
# Author: Ian Morrish | |
# Website: https://ianmorrish.wordpress.com | |
# tested on Windows 10. No error checking. Ensure Remote button is on. | |
# Must "set-executionpolicy RemoteSigned" one time from PowerShell running as Administrator | |
# update the IP address and file names as required | |
# | |
$HyperDecks = @("192.168.1.71","192.168.1.72","192.168.1.73","192.168.1.74","192.168.1.75") | |
$DateString = (Get-Date).tostring("dd_MM_yyyy_hh_mm") | |
$fileNames = @("Cam1 - $DateString","Cam2 - $DateString","Cam3 - $DateString","Cam4 - $DateString","Prog - $DateString") | |
$scriptedMode = [bool]1 | |
function send-tcprequest | |
{param( | |
[string] $remoteHost, | |
[int] $port = 9993, | |
[string] $inputObject, | |
[int] $commandDelay = 10 | |
) | |
$socket = new-object System.Net.Sockets.TcpClient($remoteHost, $port) | |
$stream = $socket.GetStream() | |
$writer = new-object System.IO.StreamWriter $stream | |
while($true) | |
{ | |
## Receive the output that has buffered so far | |
$SCRIPT:output += GetOutput | |
foreach($line in $inputObject) | |
{ | |
$writer.WriteLine($line) | |
$writer.Flush() | |
Start-Sleep -m $commandDelay | |
$SCRIPT:output += GetOutput | |
} | |
break | |
} | |
## Close the streams | |
$writer.Close() | |
$stream.Close() | |
## You can check the return code | |
#$output | |
} | |
## Read output from a remote host | |
function GetOutput | |
{ | |
## Create a buffer to receive the response | |
$buffer = new-object System.Byte[] 1024 | |
$encoding = new-object System.Text.AsciiEncoding | |
$outputBuffer = "" | |
$foundMore = $false | |
## Read all the data available from the stream, writing it to the | |
## output buffer when done. | |
do | |
{ | |
## Allow data to buffer for a bit | |
start-sleep -m 5 | |
## Read what data is available | |
$foundmore = $false | |
$stream.ReadTimeout = 50 | |
do | |
{ | |
try | |
{ | |
$read = $stream.Read($buffer, 0, 1024) | |
if($read -gt 0) | |
{ | |
$foundmore = $true | |
$outputBuffer += ($encoding.GetString($buffer, 0, $read)) | |
} | |
} catch { $foundMore = $false; $read = 0 } | |
} while($read -gt 0) | |
} while($foundmore) | |
$outputBuffer | |
} | |
# Start record and set file name for each device | |
$i=0 | |
foreach($HyperDeck in $HyperDecks){ | |
$commands=@("record: name:$($fileNames[$i])") | |
send-tcprequest -remoteHost $HyperDeck -inputObject $commands | |
} | |
<# | |
# use a copy of this file with below to schedule a stop | |
foreach($HyperDeck in $HyperDecks){ | |
$commands=@("stop") | |
send-tcprequest -remoteHost $HyperDeck -inputObject $commands | |
} | |
#> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment