PowerShell Scripting¶
StaxRip can be automated via PowerShell scripting.
Events¶
In order to run scripts on certain events the following events are available:
ProjectLoadedAfter Project LoadedJobProcessedAfter Project ProcessedVideoEncodedAfter Video EncodedBeforeJobProcessedBefore Job ProcessedAfterSourceLoadedAfter Source LoadedApplicationExitApplication ExitProjectOrSourceLoadedAfter Project Or Source LoadedJobsEncodedAfter Jobs Encoded
Assign to an event by saving a script file in the scripting folder using the event name as file name.
The scripting folder can be opened with:
Main Menu > Tools > Scripts > Open script folder
Use one of the following file names:
- ProjectLoaded.ps1
- JobProcessed.ps1
- VideoEncoded.ps1
- BeforeJobProcessed.ps1
- AfterSourceLoaded.ps1
- ApplicationExit.ps1
- ProjectOrSourceLoaded.ps1
- JobsEncoded.ps1
Default Scripts¶
HDR to 10bit 1000nits(Rec.2100)AVS.ps1¶
$code = @"
# HDR to 10bit 1000nits (BT.2100) High Dynamic Range Video for Full HDR10.
# This is not Designed to Scale HDR to SDR.
# Don't Forget to Check all the Flags Before Starting.
# You can Use other Color Options like Tweak, Level or Range to make any other needed changes to the Color & Brightness(If Needed).
"@
$activeProject = [ShortcutModule]::p
if ($activeProject.Script.Engine -ne [ScriptEngine]::Avisynth) {
[MainModule]::MsgError("Load Avisynth first", "Filters > Filter Setup > Avisynth")
exit
}
if ($activeProject.VideoEncoder.GetType().Name -ne "x265Enc") {
[MainModule]::MsgError("Load x265 first")
exit
}
$commands = [ShortcutModule]::g.DefaultCommands
$commands.SetFilter("HDR", "Color", $code)
$commands.ImportVideoEncoderCommandLine("--output-depth 10 --hdr --colorprim bt2020 --colormatrix bt2020nc --transfer smpte2084 --master-display G(8500,39850)B(6550,2300)R(35400,14600)WP(15635,16450)L(10000000,1) --hrd --aud --repeat-headers --max-cll 1000,180")
HDR to 10bit 1000nits(Rec.2100)VS.ps1¶
$code = @"
# HDR to 10bit 1000nits (BT.2100) High Dynamic Range Video for Full HDR10.
# This is not Designed to Scale HDR to SDR.
# Don't Forget to Check all the Flags Before Starting.
# You can Use other Color Options like Tweak, Level or Range to make any other needed changes to the Color & Brightness(If Needed).
"@
$activeProject = [ShortcutModule]::p
if ($activeProject.Script.Engine -ne [ScriptEngine]::VapourSynth) {
[MainModule]::MsgError("Load VapourSynth first", "Filters > Filter Setup > VapourSynth")
exit
}
if ($activeProject.VideoEncoder.GetType().Name -ne "x265Enc") {
[MainModule]::MsgError("Load x265 first")
exit
}
$commands = [ShortcutModule]::g.DefaultCommands
$commands.SetFilter("HDR", "Color", $code)
$commands.ImportVideoEncoderCommandLine("--output-depth 10 --hdr --colorprim bt2020 --colormatrix bt2020nc --transfer smpte2084 --master-display G(8500,39850)B(6550,2300)R(35400,14600)WP(15635,16450)L(10000000,1) --hrd --aud --repeat-headers --max-cll 1000,180")
Re-mux v4.ps1¶
$msg = @"
This script does the following:
- Sets video to mux from source or previous encoding
- Sets audio to mux
- Sets MP4Box or mkvmerge as muxer
With MKV output you can cut/trim in the preview dialog.
Edit the script if you want this message to disappear.
"@
$td = new-object "TaskDialog[string]"
$td.MainInstruction = "Re-mux"
$td.Content = $msg
$td.AddButton("Continue", "c")
$td.AddButton("Abort" , "")
$result = $td.Show()
$td.Dispose()
if ($result -ne "c") {exit}
# active project
$p = [ShortcutModule]::p
#global object with miscelenius stuff
$g = [ShortcutModule]::g
$td = new-object "TaskDialog[string]"
$td.MainInstruction = "Select a muxer."
$td.AddCommandLink("MKV using mkvmerge", "mkv")
$td.AddCommandLink("MP4 using MP4Box" , "mp4")
$result = $td.Show()
$td.Dispose()
if ($result -eq "mkv") {
$muxer = new-object "MkvMuxer"
} elseif ($result -eq "mp4") {
$muxer = new-object "MP4Muxer"
} else {exit}
$nullVideoEncoder = New-Object "NullEncoder"
$g.LoadVideoEncoder($nullVideoEncoder)
$p.VideoEncoder.LoadMuxer($muxer)
$muxAudio0 = new-object "MuxAudioProfile"
$g.LoadAudioProfile0($muxAudio0)
$muxAudio1 = new-object "MuxAudioProfile"
$g.LoadAudioProfile1($muxAudio1)
_AfterSourceLoaded.ps1¶
# This script handles the AfterSourceLoaded event, remove the underscore from the
# filename in order to enable it. The script sets QTGMC filter to type 0 (Interlaced) if the
# MediaInfo property 'ScanType' returns 'Interlaced'.
# However if it's not 'interlaced' and the Scantype is Progressive it will set QTGMC to type 1 (Progressive) if the
# MediaInfo property 'ScanType' returns 'Progressive'.
# active project
$p = [ShortcutModule]::p
#global object with miscelenius stuff
$g = [ShortcutModule]::g
if ([MediaInfo]::GetVideo($p.FirstOriginalSourceFile, "ScanType") -eq "Interlaced")
{
$p.Script.SetFilter("QTGMC", "Field", "QTGMC(Preset = "Medium", InputType=0, SourceMatch=3, Sharpness=0.2, EdiThreads=8)")
}
elif ([MediaInfo]::GetVideo($p.FirstOriginalSourceFile, "ScanType") -eq "Progressive")
{
$p.Script.SetFilter("QTGMC", "Field", "QTGMC(Preset = "Medium", InputType=1, Sharpness=0.2, EdiThreads=8)")
}