How to Enable DVR in HLS — Ant Media Server
The latest version of Ant Media Server has brought many exciting features for developers.
One of them is the DVR feature. This feature is important for clients who want to watch past videos. You can use DVR(Digital Video Recorder) feature in Video JS. It’s supported by default. Here is a step-by-step tutorial that lets you learn how to enable DVR in Video JS with HLS Streaming.
How to enable DVR and what are the use cases of DVR?
The DVR is actually required for all use cases where you need to watch and save stream history and the most well-known use case is IP Camera systems. As you know, it may be necessary to check the history from time to time for various reasons. Now, you can customize this requirement with Ant Media Server.
Now we will explain step-by-step guide how the DVR can be activated in Ant Media Server:
Open your application properties file with your favorite editor. i.e. for LiveApp it’s /usr/local/antmedia/webapps/LiveApp/WEB-INF/red5-web.properties
Set or add the following properties in the file
settings.hlsPlayListType=event
settings.hlsflags=
The Default HLS flag is delete_segments so we just keep it empty
Save the file and restart Ant Media Server
sudo service antmedia restart
Send a Live Stream to Ant Media Server with WebRTC or RTMP. Let’s assume that you’re sending a live stream with stream1 id
Open the HLS player in your browser.
https://YOUR_SERVER:5443/LiveApp/play.html?id=stream1&playOrder=hls
You should see the slider bar in the player as shown below. It’s by default playing the Live edge
Ref: https://resources.antmedia.io/docs/ams-application-configuration
Here is an example use case
Live rewind
Ant Media Server deletes the obsolete HLS segments by default. So we need to make Ant Media Server keep every HLS segment in the list. In order to use live rewind in streams.
- Open your application properties file with your favorite editor. i.e. for LiveApp, it’s
/usr/local/antmedia/webapps/LiveApp/WEB-INF/red5-web.properties
- Set or add the following properties in the file
settings.hlsPlayListType=event settings.hlsflags=
- The default HLS flag is delete_segments so we just keep it empty
- Save the file and restart Ant Media Server
sudo service antmedia restart
- Send a Live Stream to Ant Media Server with WebRTC or RTMP. Let’s assume that you’re sending a live stream with
stream1
id - Open the HLS player in your browser.
https://YOUR_SERVER:5443/LiveApp/play.html?id=stream1&playOrder=hls
You should see the slider bar in the player as shown below. It's by default playing theLive
edge
- You can click anywhere in the slider to rewind back to the live stream as below.
How to set a specific time value for rewinding
You have 2 options for this requirement. Let us explain step by step:
Let’s skip to your requirements. You can calculate your 24h
with the below calculation. You need to have 24h
with segment duration * segment list size
. Let's change the segment duration to 4 seconds. 24h(24 * 60 * 60 = 86400 seconds) = 4 seconds * 21600
So you need to use as below:
Segment duration: 4 Segment list size: 21600
I tried it on my test environment, it’s working for 2–3 minutes. I’m expecting should work 24h
as well. Please keep the settings as below:
settings.hlsPlayListType= settings.hlsflags=delete_segments settings.deleteHLSFilesOnEnded=true
on app settings as well. Please test it first.
Use Ant Media Server for free for 100 hours every month
You don’t need to pay anything in advance. Just get started and only pay for what you use. Ant Media provides 100 hours of free usage every month and you’ll have Ant Media Server with all WebRTC and everything by signing up with zero upfront cost. In addition to the DVR feature, you will have access to all the features.
Originally published at https://antmedia.io on October 11, 2022.