Clipping streams
Version required
MistServer 3.3+
What is clipping
Clipping is generating a small video (often MP4) of interest out of a larger stream available within MistServer. This could be several seconds, but also minutes. The core of it however is that you create a smaller VoD file out of a current available stream.
How do you generate a clip
Clipping can be done either as a push, or as a request to MistServer. Both will work and provide the exact same clip. The only thing you need to do is provide MistServer:
- the stream name
- the start time
- end time (or duration)
- the requested format.
Selecting the start/stop through parameters
MistServer needs to know where to begin and where to end the clip through parameters. Various options could be available depending on the stream information available. A VoD stream would generally only have media time as it doesn't always correspond with an actual point in time. Live streams generally do have a unix time available, recordings of live streams could have stored this information as well.
-
startunix=1234
- Start the stream at the given unix time in seconds. A negative number can be given instead to go back the given amount of seconds compared to current time. -
stopunix=1234
- Stop the stream at the given unix time in seconds. -
duration=1234
- The amount of seconds the clip/VoD should cover. Can be used as stopping point instead of a given?stopunix=1234
or?stop=1234
. -
start=1234
- Start the stream at the given media time in seconds. -
stop=1234
- Stop the stream at the given media time in seconds. -
dl=1
- Requesting out of MistServer only, instead of sending the stream spawn a download for the requested clip. If aname.ext
is given the download will be named as such instead.
Requesting a clip from MistServer
Requesting a clip from MistServer is quite easy, all you need to do is add the start/end point of the stream and you will have a clip. This clip will be provided to the browser as if it's a VoD stream within MistServer. The only difference is that it'll get downloaded to the cache and not be available within MistServer after usage, it needs to be regenerated should you wish to re-use it.
You can even download the clip if it's an output compatible with storage such as MP4 or MKV.
Generating a clip through push
Generating a clip through the push panel can be done like a recording. All you need to do is start a push and add the start/stop parameters. The main difference though is that clipping through the push panel will always create a VoD and cannot be viewed directly.
Things to keep in mind
-
While using
startunix
and a relative time is a great method to quickly get a starting position for a live stream keep in mind that it's hard to reproduce the same result using the request or push again as live streams continuously update this information. -
MistServer needs a keyframe to start on, so if there's no key frame available you will be given the first available keyframe that will contain the requested starting point. Should
duration
be used as well the duration of the clip will be made bigger to contain the requested amount of media data. So your clips could be slightly bigger depending on the stream capabilities. -
You can request a time in the future to stop at, however this could slightly change the recording format and break compatibility for older players/devices. For example MP4 changes to fMP4 for the clip in order to support the request, which has less support over players/browsers compared to normal MP4.
-
If a stream does not provide an accurate timestamp MistServer will try and generate one for live streams. As an example, most RTMP streams will start at 0 instead of providing an accurate time-stamp, thus MistServer will take the receive time as the unix time for unix time start points. This can cause a few seconds offset for start times.
Examples
When the examples contain http://mistserveraddress
you should replace this for either the http or https address of your MistServer instance.
Clipping the last 10 seconds of a live stream
http://mistserveraddress/streamname.mp4?startunix=-10&duration=10
For example for the stream live
this could be:
https://mistserveraddress/live.mp4?startunix=-10&duration=10
Downloading a requested clip
https://mistserveraddress/live.mp4?startunix=-10&duration=10&dl=1
This would download the clip above instead as live.mp4
Downloading a requested clip under a different name
https://mistserveraddress/live.mp4?startunix=-10&duration=10&dl=livestream.mp4
This would download the clip above as livestream.mp4
Clipping the last 10 seconds of a live stream
/tmp/10sec.mp4?startunix=-10&duration=10
This would generate a VoD MP4 in /tmp/
as 10sec.mp4
within the server that can then be used as a new input or to directly play.
Requesting a clip based on Unix time
https://mistserveraddress/live.mp4?startunix=1701961010&duration=30
This would create a clip of 30 seconds starting at: Thursday, December 7, 2023 15:56:50
Now as you can calculate, the starting point would say 15:56:47 on the stream itself, this is because the ingest used is RTMP and the encoder takes about 3 seconds to start sending stream information. Which causes a 3 second delay, as the RTMP stream itself doesn't provide MistServer with a true timestamp MistServer will use the timestamp where it received the data as unix time.