Clipping in Livepeer is currently possible, but not yet a well-packaged feature. In order to create a clip, you need to:
Make sure recording is turned on for the stream. Follow this API guide.
You can do this by changing the RTMP ingest URL to rtmp://{region}-rtmp.livepeer.com/live/{stream-key}
. For example: rtmp://nyc-rtmp.livepeer.com/live/3821-jkku-06da-w3nd
. Some available regions are: nyc
, lax
, mdw
, lon
, prg
.
Get current stession ID by calling GET https://livepeer.com/api/stream/{stream-id}/sessions?limit=1
.
You can get it using this URL pattern: https://{region}-cdn.livepeer.com/recordings/{session-id}/source.m3u8
You can take the last N segments from the playlist based on the segment lengths and the designed clip length, concatenate the segments into a single mp4 file. For example:
wget https://nyc-cdn.livepeer.com/recordings/{session-id}/source/0.ts
wget https://nyc-cdn.livepeer.com/recordings/{session-id}/source/1.ts
wget https://nyc-cdn.livepeer.com/recordings/{session-id}/source/2.ts
wget https://nyc-cdn.livepeer.com/recordings/{session-id}/source/3.ts
cat 0.ts 1.ts 2.ts 3.ts > clip.ts
ffmpeg -i clip.ts -acodec copy -vcodec copy clip.mp4
Alternatively, you can create a new m3u8
file that contain ONLY the segments you want. For example:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-TARGETDURATION:1
#EXTINF:1.000,
https://example.com/1.ts
#EXTINF:1.000,
https://example.com/2.ts
#EXTINF:1.000,
https://example.com/3.ts
#EXTINF:1.000,
https://example.com/4.ts
#EXT-X-ENDLIST