Skip to content

Record Live Stream

Daniel Neto edited this page Jun 30, 2020 · 38 revisions

This tutorial will guide you how to record your live stream and send it to the encoder.

For this tutorial you will need

  1. The plugin SendRecordedToEncoder
  2. Streamer and nginx Live Stream Server need to be on the same server
  3. If Streamer and nginx are separated make sure you configure the getRecordedFile.php

Step 1

Make sure you update your streamer and encoder. if you are not sure how to do this, check this tutorial

Step 2

create a directory to store your recorded lives, and gives permission to Apache and Nginx to write on it. Make sure this path match with the record_path parameter on Nginx conf

For example:

sudo mkdir /var/www/tmp && sudo chmod 777 /var/www/tmp

Step 3

Change your nginx.conf file

sudo nano /usr/local/nginx/conf/nginx.conf

and then add those lines on your file

recorder video{
    record all;
    record_path /var/www/tmp;
    record_notify on;
    record_max_size 2048M; 
    #will produce files of the form yourUserKey-24-Apr-13-18:23:38.flv
    record_suffix -%d-%b-%y-%T.flv;
}

your rtmp section should look like this.

rtmp {
        server {
                listen 1935;
                allow play all;
                #creates our "live" full-resolution HLS videostream from our incoming encoder stream and $
                application live {
                        allow play all;
                        live on;
                        #record all;
                        #record_path /video_recordings;
                        #record_unique on;
                        hls on;
                        hls_nested on;
                        hls_path /HLS/live;
                        #hls_playlist_length 4s;
                        #hls_fragment 1s;
                        hls_fragment 10s;
                        on_publish http://192.168.25.16/YouPHPTube/plugin/Live/on_publish.php;
                        on_play http://192.168.25.16/YouPHPTube/plugin/Live/on_play.php;
                        on_record_done http://192.168.25.16/YouPHPTube/plugin/Live/on_record_done.php;
                        recorder video{
                            record all;
                            record_path /var/www/tmp;
                            record_notify on;
                            record_max_size 2048M; 
                            #will produce files of the form yourUserKey-24-Apr-13-18:23:38.flv
                            record_suffix -%d-%b-%y-%T.flv;
                        }

                }
        }
}

Check your on_record_done directive, it needs to be pointing to the live stream plugin, on_record_done.php file

Step 3

Restart your nginx server

 sudo /usr/local/nginx/sbin/nginx -s stop && sudo /usr/local/nginx/sbin/nginx 

Step 4

Go to your plugin menu and enable SendRecordedToEncoder plugin

Parameters

getRemoteFile (getRecordedFile.php)

This parameter will inform your plugin, in case the recorded file is not found locally, where should it look for it? In case you need the Livestream and the streamer server in separate hardware, you will need to add a code to get the recorded file remotely. Add a file on your NGINX server and add the following content.

<?php

$record_path = "/var/www/tmp/"; //update this URL

if(empty($_REQUEST['file'])){
    die('file not found');
}
$file = preg_replace("/[^0-9a-z_:-]/i", "", $_REQUEST['file']);

$filename = $record_path.$file.".flv";

header('Content-Type: video/x-flv');
echo file_get_contents($filename);

webSiteRootURL

After a live stream, your video will be sent to the encoder. if you want to force a Streamer URL use this parameter.

This is useful when your Nginx uses a different network to connect with the streamer.

In case you are not sure, just leave this empty

Clone this wiki locally