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.Create a stream
Follow our previous guide on creating a stream to get a stream key to provide to the creator on your platform. You can then start a Livestream and note down theplaybackId.
Call the Clip API
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.
api/clip API using the following request parameters:
UNIX timestamp (in milliseconds) of clip’s start 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
Tip: HLS players typically provide a Program-Date-Time for each segment when
parsing an HLS manifest. You can utilize these Program-Date-Times to create a
clipping user interface (UI) and generate the correct timestamps.
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:
clipLength to enable the clipping button,
alongside the clip callbacks. These are called when the user initiates a clip
with the built-in Player clip button. The asset ID can then be used to poll the
API and get updates on the processing status.
Monitor the clip’s status
After calling the clip API, Livepeer generates an asset. You’ll receive the asset’s details in the response.- using the
/api/asset/$ASSET_IDAPI
asset.status field is ready.
- using webhooks
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 API:
Tip: 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 of any other Livepeer asset. You are able to get the playback URLs in your asset object, or fetching them from the/api/playback/$PLAYBACK_ID API, providing the playbackId of the output asset
representing the clip.