Clip a livestream
Learn how to create clips from your livestream
Introduction
You can use Livepeer Studio to create clips of active streams provided via API. Currently, you can create clips from the most recent N seconds of a given stream. You may also clip specific sections of a long-running stream, such as a particular session from a live-streamed conference.
This guide offers a comprehensive walkthrough of the clipping functionality.
Clipping is currently only supported by livestreams and livestream recordings. Check back later for further support.
Create a stream
Follow our previous guide on creating a stream to get a stream key to provide to the creator on your platform. They can then start broadcasting to that stream.
Create a clip
Clips are created from the perspective of the user who initiates the clip. For example, if a viewer clips the most recent 30 seconds, it will be the most recent 30 seconds that they saw.
Submit a request to the Create Clip API using the following request parameters:
UNIX timestamp (in milliseconds) of clip’s starts from the browser’s playhead (commonly supplied by HLS players).
UNIX timestamp (in milliseconds) of clip’s end from the browser’s playhead (commonly supplied by HLS players).
Active stream’s Playback ID
(Optional) Output clip’s name
Ensure the startTime
aligns with or postdates the stream’s initiation, and
that the endTime
isn’t set in the future.
API + Player Integration
If you are using HLS.js, it provides an API for getting the program date time,
hls.playingDate
, which can be used to get the browser’s current playhead. This
returns a Date object which is used similar to:
HLS players typically provide a Program-Date-Time
for each segment when
parsing an HLS manifest. You can utilize Program-Date-Time
to create a
clipping user interface (UI) and generate the correct timestamps.
If you are using the Livepeer Player, you use the Clip Trigger, which abstracts this functionality into an easy-to-use primitive. You will need to call the Livepeer Clip API from your backend, and perform sanitization on the user input.
Monitor the clip’s status
After calling the clip API, Livepeer generates an asset. You’ll receive the asset’s details in the response.
There are two approaches to track the clip’s status:
- using the
/api/asset/$ASSET_ID
API
You can poll this endpoint to retrieve the current status of the asset. Keep
polling until the asset.status
field is ready
.
- using webhooks
If you have configured a webhook in Livepeer to listen for the asset.ready
event, you will receive a notification when the clip processing is complete. You
can use the assetId
received in the previous response to determine when your
clip is ready.
To determine if an asset you are polling or receiving as an event is a clip, you
can check the source
field. If the source
field contains a clip
type and
the relative session ID, then it is indeed a clip.
You can always fetch clips by stream using the Clips for Livestream API:
Clips offer source playback just like other assets. On completion, a transcode
job is triggered. Even before this job concludes, the source playback becomes
available. The playbackUrl
field in the asset gets populated when the
playback is ready, and the sourcePlayback
field is set to true.
Get your clip!
A clip generated in Livepeer is the same as any other Livepeer asset. You are able to get the playback URLs in your asset object, or fetching them from the Playback Info API, providing the playbackId of the output asset representing the clip.
Was this page helpful?