2013-08-27 45 views
4

我正在嘗試使用powershell和rtmpdump監視實時電視頻道rtmp提要。希望監視的流保存在遵循以下csv格式的「streams.txt」文件中。使用powershell和rtmpdump監視rtmpdump提要

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文件和轉換數據後我遍歷每個對象並使用進料屬性我啓動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過程和在循環的下一個迭代i想要捕獲第二進料進行30秒。

如果一個流不工作就會genrate 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 
2

我相信這你想要做什麼的FLV文件...這將通過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 
+0

我已經嘗試過,你發佈的代碼。睡眠的東西不會工作cuz rtmpdump過程將採取連接到遠程服務器的飼料。睡眠過程會過早發生,PowerShell不會做任何事情。 – najam