backup Stream ( is it possible incoming 2 stream to broadcast )

burak guder

Member
Hi Flahphoner

When the rtsp stream is wrong I want to use the broadcast from the 2nd rtsp url.

Is this possible ?

I could not do this on the player. Player gives error code too late

This would be great if flashphoner can do this
 

Max

Administrator
Staff member
Good day.
You can use REST API to do this:
1. Pull the stream using REST query /rtsp/startup
JavaScript:
{
 "uri":"rtsp://myserver.com/live/myStream",
 "toStream": "myRTSPstream"
}
2. Check if stream is captured successfully using REST query /rtsp/find_all
3. If the stream is not captured, pull the backup stream
JavaScript:
{
 "uri":"rtsp://mybackupserver.com/live/myBackupStream",
 "toStream": "myRTSPstream"
}
 

burak guder

Member
I found a solution like this

PHP:
<?php


$backup  =  'rtsp://xxxxxxxxx/live2.sdp';
$main  =  'rtsp://xxxxxxxxxxx/live2.sdp';


$i = 100;
while ($i < 200) {
    
    exec("curl --head --connect-timeout 2 -i -X OPTIONS $main  >out.log");
    $status = 0;
    foreach(file('out.log') as $line) {
        $status = trim($line) ;
        echo "Status : $line \n";
        break;
    }
    
    if ($status == 'RTSP/1.0 200 OK') {
        stopStream($backup);
        startStream($main, 'xxx555');
        echo "Stream Main Active \n ";
        
    } else {
        exec("curl --head --connect-timeout 1 -i -X OPTIONS $backup  >out.log");
        sleep(1);
        $status = 0;
        foreach(file('out.log') as $line) {
            $status = trim($line);
            echo "Status : $line \n";
            break;
        }
        
        if ($status == 'RTSP/1.0 200 OK') {
            stopStream($main);
            usleep(200);
            startStream($backup, 'xxx555');
            echo " Stream Backup Active \n ";
        } else {
            echo " ERROR ALL INPUT  \n ";
        }
        
    }
    
    usleep(500);
}


function stopStream($url) {
    
    $options = array (
        'http' => array (
            'header' => "Content-type: application/json",
            'method' => 'POST',
            'content' => '{
                            "uri":"'.$url.'"
                          }'
        )
    );
    
    @ getInfoHeader ( "http://xxxxxxxxxxxxxxxx:8081/rest-api/rtsp/terminate", $options );
    
}

function startStream($url, $streamName) {
    
    $options = array (
        'http' => array (
            'header' => "Content-type: application/json",
            'method' => 'POST',
            'content' => '{
                            "uri":"'.$url.'",
                            "toStream":"'.$streamName.'"
                          }'
        )
    );
    
    $getlog2 = getInfoHeader ( "http://xxxxxxxxxxxxx:8081/rest-api/rtsp/startup", $options );
    echo $getlog2;
    
}


function getInfoHeader($url, $options) {
    
    
    $context = stream_context_create ( $options );
    $result = file_get_contents ( $url, false, $context );
    if ($result === FALSE) {
        //echo "An error occured!";
    }
    return $result;
}

How do I reload on the player side ?
 
Top