The playback of long videos (longer than 1h) stored in Web3 Storage can be slow due to the W3 Link issue tracked here (opens in a new tab).
Introduction
This guide will describe how to use the Livepeer transcode API to transcode and store video files in web3.storage (opens in a new tab).
There are code examples provided for reference.
UCAN Proof
This step assumes that you have w3 CLI (opens in a new tab) installed. Follow the Getting Started (opens in a new tab) instructions to create new space for storing data and register the space.
Get Livepeer Studio DID.
curl https://livepeer.studio/api/did
The response should contain the Livepeer Studio DID.
{
"did": "did:key:z6Mkn1f6JUmxJi8Ht53SzeK3LSWNn9DRPsSfFLoPJWHVTCaX"
}
Create a UCAN delegation.
w3 delegation create <livepeer-studio-did-key> | base64
This returns the base64-encoded delegation proof which authorizes the Livepeer Studio DID to store data to your space. Note that the proof should not contain any whitespaces.
Upload Video to web3.storage
Make sure you have a video file uploaded to web3.storage. You can do upload a file using the w3 up
command by following these instructions (opens in a new tab).
Transcode with Livepeer
This step assumes that you have already created a Livepeer Studio account (opens in a new tab) and an API key (opens in a new tab).
Submit the following request:
curl --location --request POST 'https://livepeer.studio/api/transcode' \
--header 'Authorization: Bearer $API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"input":{
"url":"$INPUT_VIDEO_URL"
},
"storage":{
"type":"web3.storage",
"credentials":{
"proof":"$DELEGATION_PROOF"
}
},
"outputs":{
"hls":{
"path":"/"
},
"mp4":{
"path":"/"
}
},
"profiles":[
{
"name":"480p",
"bitrate":1000000,
"fps":30,
"width":854,
"height":480
},
{
"name":"360p",
"bitrate":500000,
"fps":30,
"width":640,
"height":360
}
]
}'
$API_KEY
should be your Livepeer Studio API key$DELEGATION_PROOF
should be the delegation proof you created usingw3
input.url
should be the URL of the video you would like to transcodeoutputs.hls.path
will be the relative path that the HLS playlist and mpegts segments will be found in when transcoding is completeoutputs.mp4.path
will be the path that the MP4 video files will be found in when transcoding is completeprofiles
is an optional parameter to specify the desired properties of transcoded video
Use the task ID in the response to query for the transcoding task status. Once the task is complete, you’ll see the output directory IPFS URL in the /api/task
response in the output.transcodeFile.baseUrl
field.
{
"id": "...",
"type": "transcode-file",
"output": {
"transcodeFile": {
"baseUrl": "ipfs://bafybeiakkypfc7uzk6jnk6pg3f2fwumkahrmgbii7cigyyc7oejjo3ff4e",
"hls": {
"path": "/index.m3u8"
},
"mp4": [
{ "path": "/static360p0.mp4" },
{ "path": "/static720p0.mp4" },
{ "path": "/static1080p0.mp4" }
]
}
},
...
}
For more information about transcode API usage refer to the docs.