我正在尝试使用powershell和rtmpdump来监控直播电视频道rtmp feed。我要监视的流保存在“streams.txt”文件中,该文件遵循以下csv格式。
Name,feed,file
tv1,rtmp://server/live/tv1,tv1.flv
tv2,rtmp://server/live/tv1,tv2.flv
tv3,rtmp://server/live/tv1,tv3.flv
tv4,rtmp://server/live/tv1,tv4.flv
导入csv文件并转换对象中的数据后,我遍历每个对象并使用feed属性i启动rmtpdump命令一旦此过程正常工作,其余的powershell将暂停。
解决这个问题我尝试使用计时器,但是当rtmpdump在循环中捕获第一个Feed时,它们甚至没有解决我的问题。
Register-ObjectEvent -InputObject $timer -EventName elapsed –SourceIdentifier thetimer -Action $action
$colStats = Import-CSV streams.txt
foreach ($objBatter in $colStats)
{
$timer.start()
$objBatter.feed + "," + $objBatter.file
.\rtmpdump.exe -r $objBatter.feed -o $objBatter.file
}
#to stop run
$timer.stop()
#cleanup
Unregister-Event thetimer
#loop through flv files and all 0 bytes files are faulty channel
#deleting files with 0 size
#dir | ? {$_.length -eq 0} | del
我需要捕获Feed的输出30秒播放,然后终止rtmpdump进程,并在循环的下一次迭代中我想捕获第二个feed 30秒。
如果一个流不工作,它将生成0字节的flv文件,我以后会发送通知
答案 0 :(得分:3)
cls;
Set-Location "C:\users\najam.sikander\Desktop\rtmpdump"
#deleting flv files
dir *.flv | del
get-process -name rtmp* | kill
<#
$timer = new-object timers.timer
$action = {
write-host "Time to kill rtmp: $(get-date -Format ‘HH:mm:ss’)"
#get-process -name rtmp* | kill
}
$timer.Interval = 30000 #3 seconds
Register-ObjectEvent -InputObject $timer -EventName elapsed –SourceIdentifier thetimer -Action $action
#>
$colStats = Import-CSV streams.txt
$files = (dir *.flv | measure).Count
Write-Host $files
While ($files -lt $colStats.Length)
{
$arguments = "-r " + $colStats[$files].feed + " -o " + $colStats[$files].file + " -m 20 -v"
Start-Process "C:\users\najam.sikander\Desktop\rtmpdump\rtmpdump.exe" $arguments
do
{
Write-Host $colStats[$files].feed
Write-Host $colStats[$files].file
$streaming = $true;
$fileCh = (dir $colStats[$files].file | measure).Count
Write-Host $files
if($fileCh -gt 0)
{
while ((dir $colStats[$files].file).Length -lt 1000){
$dump = (get-process -name rtmp* | measure).Count
if($dump -eq 0)
{
break
}
}
$streaming = $false
get-process -name rtmp* | kill
}
}
while ( $streaming -eq $true)
$files = (dir *.flv | measure).Count
Write-Host $files
}
#getting working and not workign streams sets based on flv files
$working = dir *.flv | ? {$_.length -ge 1000}
$notworking = dir *.flv | ? {$_.length -eq 0}
Write-Host "working = " ($working |measure).Count
$working
Write-Host "not working = " ($notworking |measure).Count
$notworking
#deleting flv files
dir *.flv | del
答案 1 :(得分:2)
我相信这会做你想要的......它将遍历csv文件,运行rempdump进程30秒,杀死它,然后转到下一个feed。
#Import the streams
$colStats = Import-CSV streams.txt
#Loop through the streams
foreach ($objBatter in $colStats)
{
$Process = ".\rtmpdump.exe"
$arguments = "-r $objBatter.feed -o $objBatter.file"
#Launch Process
$Ps = Start-Process -FilePath $Process -ArgumentList $Arguments -PassThru
#Wait 30 seconds
Sleep -Seconds 30
#Kill the process
$Ps.Kill()
}
#loop through flv files and all 0 bytes files are faulty channel
#deleting files with 0 size
#dir | ? {$_.length -eq 0} | del