-
Notifications
You must be signed in to change notification settings - Fork 977
Record Live Stream
This tutorial will guide you on how to record your live stream and send it to the encoder.
For this tutorial, you will need
- The plugin SendRecordedToEncoder
- Streamer and Nginx Live Stream Server need to be on the same server
- If Streamer and Nginx are separated make sure you configure the getRecordedFile.php
Make sure you update your streamer and encoder. if you are not sure how to do this, check this tutorial
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
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; # Use this line if you NOT 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_publish_done http://192.168.25.16/YouPHPTube/plugin/Live/on_publish_done.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 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;
}
}
}
}
Check your on_record_done directive, it needs to be pointing to the live stream plugin, on_record_done.php file
Restart your Nginx server
sudo /usr/local/nginx/sbin/nginx -s stop && sudo /usr/local/nginx/sbin/nginx
Go to your plugin menu and enable SendRecordedToEncoder plugin
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
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
This URL will be used to validate all recording requests and will always return a JSON
- If it is not legitim it will deny the record with error=true:
{"error":true,"msg":"error message"}
- If the record request is legit, it may respond error=false:
{"error":false,"msg":"message","recordLimit":3600,"username":"admin","password":"123"}
- recordLimit: it is the record time limit in seconds, so 3600 = 1 hour
- username: that is the username that this live will be recorded to, so it will be the owner, this user will be created in case it does not exist
- password: only need in case the user does not exist, we will use this password as its default password
This URL can also be replaced by your own custom validator.
These two features work in a similar way, but when clicking on Download the user will download the video and when clicking on save, the video will be sent to the encoder and saved in the video library
The DVR feature is required to make the Moment work
DVR is a feature that lets your viewers pause, rewind, and continue during the live stream. Once a viewer resumes playing, the live stream will continue from where they hit pause.
Make sure you have this option uncomment on the nginx.conf
hls_playlist_length 60m;
where 60m means you will have a 60-minute DVR saved on your server
Usually, you can edit nginx.conf with this command: sudo nano /usr/local/nginx/conf/nginx.conf
HLS streaming is the process of creating small fragments (typically only a few seconds in length)
You need to pay attention to the hls_fragment size, is recommended to keep it 4 or 5 seconds only, this configuration also reflects in your latency, so 4 or 5 seconds are good enough.
hls_fragment 5s; the amount of time for each segment of your live stream (HLS)
So if you want to set your Save/Download the moment to save the last 20 seconds of the live, you have to set the "Segments Count"=4, so when you click on the button you will save/download the number of segments defined in the option "***The moment Segments Count"
for example, if you have the following configuration:
hls_fragment 5s; Save The moment Segments Count (plugin configuration) = 4
When you click on the Save button we will convert the last 4 segments (5 seconds each) of your live stream into a single 20 seconds MP4 file, so (4x5=20). this count is not always exact, but it comes to a value very close to 20 seconds.