News

23 Oct 2017

[Blog] Recording live streams with MistServer

Hey everyone, lately we've had some questions regarding recording and how to set it up. I thought it would be a good subject to talk about as while it's quite easy to use, there are always a few things to keep in mind.

The basics of recording in MistServer

All recording in MistServer is done through the push panel within your MistServer interface. This is because we see recording as pushing the stream to a local file. To set one up we'll only have to push towards a path/file.ext, I’ll talk more about that below. At the time of writing this blog post MistServer can only record in FLV, TS, MP3 and WAV files, but we will be adding additional protocols in the future, our aim is to have a recording possibility for any protocol that makes sense to record in.

There's two flavors of pushing, push and automatic push.

Normal pushes

Normal pushes are one time events. A push, or recording in this case will be started of your selected stream and after it's done it will be removed and disappear leaving just your recording. These pushes are unaffected by the push settings at the top of the menu as they’re single non-restarting recordings. It's the easiest method to start a recording with if you just want a single recording and be done with it.

Automatic pushes

Automatic pushes are set to monitor a stream and start recording the moment that stream becomes active. This could be a live stream or the wildcard streams of a live stream, any recording set up using this method will be recorded under the settings used. It's the method to choose if you want to setup something that automatically records live streams.

Push settings: stream name, target and target options

Stream name

Stream name is the stream you'll be recording with this push command. There’s 3 options here: streamname, streamname+ and streamname+wildcard. Streamname will just use the stream with the matching stream name, streamname+ will use all wildcard streams of the chosen stream and streamname+wildcard will just use the chosen wildcard stream.

Target

Target is the push method. To record you must choose a path/file.flv or path/file.ts, for example /media/recordings/recording01.ts.

Target options

We have two types of target options, variables and parameters. Variables are replaced by their corresponding variable upon push/recording while parameters change the way the recording is handled. Variables are used by $variable while parameters should be used as ?parameter, however, using multiple parameters follows a different syntax: ?parameter01&parameter02&parameter03&etc. Variables are available in every MistServer that has pushing functionality, while parameters will be available from MistServer version 2.13 and up.

Variables

VariableBehaviour
$streamreplaced by the `streamname+wildcard` in the file name
$dayreplaced by the day number in the file name
$monthreplaced by the month number in the file name
$yearreplaced by the year number in the file name
$hourreplaced by the hour (00-23) at recording start in the file name
$minutereplaced by the minute (00-59) at recording start in the file name
$secondsreplaced by the seconds (00-59) at recording start in the file name
$datetimereplaced by $year.$month.$day.$hour.$minute.$seconds at recording start in the file name

Parameters

ParameterBehaviour
?recstart=time_in_MSStarts the recording at the closest frame when the given time in milliseconds is reached.
?recstop=time_in_MSStops the recording at the closest frame after the given time in milliseconds is reached
?recstartunix=time_in_SECONDSStarts the recording at the closest frame when the given UNIX time in seconds is reached
?recstopunix=time_in_SECONDSStops the recording at the closest frame when the given UNIX time in seconds is reached
?passthrough=1Activates passthrough: All inputs will be used in the push/recording.

Things to keep in mind, common mistakes

Here I will list a few things that are handy to keep in mind or usually go wrong the first time when setting up recordings.

Variables are necessary to not automatically overwrite automatic recordings

Without using variables you will overwrite your automatic recordings the second your stream source becomes active. Adding a date and timestamp will make sure your file gets an unique enough name to avoid this. This is especially important if your source tends to be unstable and restarts when recording.

When using recstart/stop parameters, the timestamp used is not necessary the same timestamp used by players

Players usually start their playback starting at 0 seconds no matter what the stream data says, but depending on the source a recording can contain information starting from a timestamp higher than 0ms. A stream could for example claim to start at timestamp 120000 if you started recording after the stream was active for 2 minutes already. This will mean you will have to account for this timestamp as well.

When using recstart/stopunix the unix time between machines doesn’t have to be the same

The unix time used is the unix time of the machine running MistServer, this time is changeable depending on the machine settings so make sure you do not assume that this time is the same over every machine.

Make sure you have write access to the folder you are writing

It sounds obvious, but MistServer will not be able to record anything if it is not allowed to write files. Make sure the given path is a path that can be used.

If you start a single record of a live stream before it is available you have about 10 seconds before it gets auto removed

Any streams that are not available within 10 seconds of starting the recording will be assumed not working/active and removed. Automatic recordings should be used if you do not plan to set the source live right before or after setting the recording.

Make sure the protocol you want to record as is active and available

If MistServer cannot access the protocol you want to record in (HTTPTS for TS and FLV for FLV) it will not be able to record the file at all.

A few examples

Lastly I will leave a few examples of how you could set up recordings.

Automatic recording of wildcard streams with their name+month.day.hour.minute added

Stream: live+

Target: /media/recording/$stream$month$day$hour$minute.ts

Automatic recording of wildcard streams and automatically grabbing any multibitrate tracks

Stream: live+

Target: /media/recording/$stream.ts?passthrough=1

Recording of a stream as myrecording.ts starting at 1 minute for 2 minutes

Stream:live

Target: /media/recording/myrecording.ts?recstart=60000&recstop=180000

Automatic recording of the wildcard stream live+specific_stream as a multibitrate ts file named mymultibitratefile.ts

Stream:live+specific_stream

Target: /media/recording/mymultibitratefile.ts?passthrough=1

That should cover you for most uses when recording. The next blog will be by Carina covering how to set up MistServer when you've got to work with a huge library