2

過去に exec() 関数を使用して、コマンド ライン実行可能ファイルから情報を取得したことがあり、RTMPDump.exe を使用してこれを再度実行するつもりでした。PHP コードは次のとおりで、これまでに使用した他のコマンド ラインの例で動作しますが、この場合は $output に何も生成されません。

    $cmd = 'c:\rtmpdump\rtmpdump -r "rtmp://fms.domain.com/live/live_800"';
    exec($cmd, $output);
    foreach ($output as $item){
        // do something with this $item
    }

Windowsコマンドラインを.batファイルに入れて実行してみました.ase $outputには、batファイルにエコーされたものだけが含まれますが、以下に示す出力は含まれません。コマンドラインからコマンドを手動で実行します。

C:\rtmpdump>rtmpdump -r "rtmp://fms.domain.com/live/live_800"
RTMPDump v2.3
(c) 2010 Andrej Stepanchuk, Howard Chu, The Flvstreamer Team; license: GPL
Connecting ...
INFO: Connected...
ERROR: rtmp server sent error
Starting Live Stream
For duration: 2.000 sec
INFO: Metadata:
INFO:   author
INFO:   copyright
INFO:   description
INFO:   keywords
INFO:   rating
INFO:   title
INFO:   presetname            Custom
INFO:   creationdate          Tue May 08 03:00:23 2012
INFO:   videodevice           Osprey-440 Video Device 1B
INFO:   framerate             25.00
INFO:   width                 480.00
INFO:   height                360.00
INFO:   videocodecid          avc1
INFO:   videodatarate         800.00
INFO:   avclevel              30.00
INFO:   avcprofile            66.00
INFO:   videokeyframe_frequency10.00
INFO:   audiodevice           Osprey-440 Audio Device 1B
INFO:   audiosamplerate       22050.00
INFO:   audiochannels         1.00
INFO:   audioinputvolume      75.00
INFO:   audiocodecid          mp4a
INFO:   audiodatarate         48.00
#######
Download complete

C:\rtmpdump>rtmpdump

プログラムは実行されます。それは問題ではありません。ビデオ データ ダンプを示す出力ファイルがあるため、実行可能ファイルの構文は問題ではありません。問題は、rtmpdump.exe が出力しているものをインターセプトする他の方法があるかどうかです。 exec() を介して PHP から実行することによってキャプチャされていないコマンド ウィンドウ。

そして、それが重要な場合、私が使用したいと思っているのは「INFO:...」です。ライブ ビデオ ストリームがストリーミングされているかどうかを判断しようとしています。サーバーは稼働していますが、特定のストリーム (live_800) がストリーミングされているかどうかを知る必要があります。

4

2 に答える 2

7

JohnF が私を正しい軌道に乗せてくれたおかげで、他の初心者がこれを達成する必要がある場合は、proc_openを使用してそれを行った方法を次に示します。

$descriptorspec = array(
0 => array("pipe", "r"),    // stdin is a pipe that the child will read from
1 => array("pipe", "w"),    // stdout is a pipe that the child will write to
2 => array("pipe", "w")     // stderr is a pipe that the child will write to
);
$cmd = c:\rtmpdump\rtmpdump -r "rtmp://fms.domain.com/live/live_800 -B 1 -m 3";
$process = proc_open($cmd, $descriptorspec, $pipes);
if (is_resource($process)) {
    $stdin = stream_get_contents($pipes[0]);
    $stdout = stream_get_contents($pipes[1]);
    $stderr = stream_get_contents($pipes[2]);
    fclose($pipes[0]);  fclose($pipes[1]);  fclose($pipes[2]);
    // It is important that you close any pipes before calling proc_close in order to avoid a deadlock
    $return_value = proc_close($process);   
}
于 2012-05-11T20:34:58.283 に答える
0

パススルー機能をお試しください。

于 2012-05-09T01:37:05.487 に答える