4

我正在尝试使用 powershell 和 rtmpdump 监控直播电视频道 rtmp 提要。我要监视的流保存在遵循 csv 格式的“streams.txt”文件中。

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 属性,一旦此过程正常工作,我就会启动 rmtpdump 命令,其余的 powershell 将停止。

为了解决这个问题,我尝试使用计时器,但是当 rtmpdump 捕获循环内的第一个提要时,即使它们也没有解决我的问题。

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

我需要捕获 30 秒播放的提要输出,然后终止 rtmpdump 进程,在循环的下一次迭代中,我想捕获 30 秒的第二个提要。

如果一个流不起作用,它将生成 0 字节的 flv 文件,我稍后会发送通知

4

2 回答 2

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
于 2013-09-07T06:13:06.733 回答
2

我相信这可以满足您的需求...它将遍历 csv 文件,运行 rempdump 过程 30 秒,将其杀死,然后转到下一个提要。

#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
于 2013-08-30T23:51:58.207 回答