Skip to content

Record Live Stream

Daniel Neto edited this page May 17, 2021 · 38 revisions

This tutorial will guide you on 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 to your file

recorder video{
    # record all manual; # Use this line if you want to use the controls
    record all manual;
    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

Start Record

you can trigger the recording with the following URL: {$global['webSiteRootURL']}plugin/SendRecordedToEncoder/recordStart.json.php?key={live key/name} if you are admin or the video owner this should start recording right the way, but if you trigger it from a third-party app you may need to validate it with the "Start Recorder Callback"

Parameters

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

Start Recorder Callback

This URL will be used to validate all recording requests and will allways resutn a JSON

If the record request is legitm, it may respond error=false: {"error":false,"msg":"message","recordLimit":60,"username":"admin","password":"123"}

If it is not legitm it will deny the record with error=true: {"error":true,"msg":"error message"}

This URL can also be replaced by your own custom validator.

Clone this wiki locally