Skip to main content

Recording DVR streams

Version required

MistServer 3.3+

What is DVR

When DVR is mentioned within streaming media as context we're almost always talking about recording a live stream with a retention window and also the capability of providing said recording as a stream towards viewers. This gives you a stream that is live, but also provides a huge history window to search back into, making it a mix of live and Video on Demand.

How do you set it up

Within MistServer every output capable of recording to file can create a DVR stream. However currently we recommend recording to TS format as it is currently the only format we support on the input side.

Important is to remember to that we're setting up a recording for the segments and add a playlist. We're not recording the playlist and adding segments, so you've got to choose the recording location and format for the segments first and then add the playlist through the parameters.

Required push settings

The minimum requirements to create a DVR stream is to add an index file through the m3u8=path/file.m3u8 parameter and to ensure the segments get an unique name per segment using either the $segmentCounter or $currentMediaTime variable.

The parameters can be set up through the interface, the variables need to be inserted in the record path of the TS segments.

Required parameters

  • m3u8=path/file.m3u8 - Will have MistServer output the stream as a segmented stream with a playlist, given is the location of the master playlist (requires either $segmentCounter or $currentMediaTime to be used).

Required variables

  • $segmentCounter - Inserts the number equal to how many segments have been created for this stream so far.

  • $currentMediaTime - Inserts the first media time stamp of the segment.

Optional parameters

  • split=1234 - Restarts recording at a keyframe roughly every given amount of seconds (rounding up to nearest keyframe). Re-parses text replacement varaibles before restarting, allowing for splitting recordings into multiple files with time-based filenames over time in a flexible manner. Defaults to 60 seconds.

  • maxEntries=1234 - Removes oldest entry if there are more than X entries in the playlist.

  • targetAge=1234 - Removes oldest entries if they have an age higher than X in seconds.

  • append=1 - If the push out is restarted append to the previous file if file names match instead of overwriting.

  • noendlist=1 - If set MistServer will not close/finish the playlist even if the stream data stops.

Things to keep in mind for DVR recording

If the split parameter is not set it will default to segments of 60 seconds. This segment size is important as a bigger segment size is beneficial to resource usage. However the segment size is also relevant to the latency when using this DVR stream as an input, your latency will always be at least 1 segment size. So if the goal is to have a relatively low latency DVR window you might not want to set this too high.

If your stream is meant to never stop you will want to include noendlist and append. These parameters play big roles in making sure the playlist stays usable even if the recording stops. noendlist makes sure the playlist won't be finalized. If it does get finalized MistServer will assume it's a VoD from there on and will not parse any new segments. append Will tell mistServer to re-use the current available playlist and add any new recording data to it in the event of a big gap in the recording.

If you want to limit the amount of size a DVR stream can take up you will need to set either a targetAge or a maxEntries. Once either of these values is reached MistServer will start deleting segments on the older end of the stream, making room for future recordings. Obviously anything deleted will be no longer available.

MistServer can "stop" the input and create a DTSH to provide a catch up point. However while it's creating this DTSH it cannot serve outputs or input new segments. It is not recommended to have the input stop for if you can avoid it for this reason. We recommend using it with the always on flag enabled.

Benefits to DVR recording

For MistServer the biggest benefit for DVR streaming is that you can use your harddrive space as a buffer, which is more scalable than your RAM. If you're recording to a network drive you can also "share" the DVR stream over multiple servers without having to send the entirety of the stream to another server.

It is also the only realistic way to provide a stream with several days of buffer.

Downsides to DVR recording

DVR recording will always add "some" latency and generally takes more CPU usage. The split parameter determines how often new data will be stored, and only stored data can be used as an input. Therefore you will always be at least 1 split duration behind on your live source.

The other thing to keep in mind is that the input keeps track of all the segments available within the playlist. If your playlist contains multiple days divided in segments of several seconds that can grow to a tremendous playlist. At some point the amount of segments in the playlist will slow down the input.

Example

The example will contain paramters and variables, even if they are not required for the DVR feature. We recommend familiarizing yourself with these as they can significantly impact the effectiveness of your usage of MistServer.

TS based DVR with segments every 24 seconds for a 24/7 stream and a 1 day buffer

You can fill in all information directly in the source, or fill it in using the parameter options once they appear after writing down the file format to record into. There is no difference as the source options will be parsed and filled in later, which you can verify by editing & viewing the setting after saving.

Target

/path/to/recordfolder/$basename/$yday/$hour/$minute_$segmentCounter.ts?m3u8=../../$basename.m3u8&split=24&maxEntries=3600&append=1&noendlist=1

Image of the settings in the interface as shown above

Note that the picture mentions #### in the segment naming instead of $segmentCounter, this is a short hand that will be added later. It is not available in current versions of MistServer!

Reason for options set

source & file selection - This needs to record to a folder & filetype that we can work with. As segmented streams can easily flood a folder with segments. So this is set to /path/to/recordfolder/$basename/$yday/$hour/$minute_$segmentCounter.ts to have MistServer record to a given recording folder saving the recordings under the stream name of the stream. To make sure the segments aren't flooding the folder these are divided in first what day of the year it is and then at what hour of the day. Then finally the segments themselves are saved with both the minute and number of segment.

?m3u8=../../$basename.m3u8 - This sets the location of the index relative to the segments. As this will go up two folders it will be within the folder already named after the stream creating a stream_name.m3u8 containing a playlist that will update itself with all available segments.

&split=24 This sets the segment size for recording to 24 seconds. Which gets us a relatively acceptable latency while also keeping the segments big enough to allow for efficient storage/usage.

&maxEntries=3600 This tells MistServer there should be a maximum of 3600 segments, which means a day of streaming if you use the current segment size of 24 seconds.

&append=1 This tells MistServer that should "something" happen that causes the stream to stop recording it should not remove the playlist when it restarts, but instead add to the playlist.

&noendlist=1 This tells MistServer that should "something" happen that causes the stream to stop recording it should not finalize the playlist, instead just close down and assume we'll start writing into it later. This is important to allow re-using the playlist later on.