Skip to main content

Upload a video asset

This guide provides you the instructions to upload a video from the Livepeer Studio Dashboard or through the Livepeer API. You should be familiar with Assets and Tasks and have a Livepeer dev environment setup.

The Livepeer API allows you to send video files to Livepeer and get them ready for optimized playback. Videos can be provided either by you (static content) or your users, given your application offers an interface for them to do so.

You should be familiar with Assets and Tasks and have generated a Livepeer Studio API key.

Caveats

  • Files are currently limited to 1GB in size. Any files greater than that will likely error out during the upload or processing steps.
  • Only MP4 files encoded with H.264 and AAC are supported

Uploading via URL

When using the upload via URL method:

  • Provide the name of the asset
  • Provide the URL of the asset that should be imported

Step 1: Upload asset by URL

To upload the asset to the Livepeer network, you'll need to make a POST request and include the URL of the asset to be uploaded.

const uploadAssetURL = await fetch("https://livepeer.studio/api/asset/import", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.API_TOKEN}`,
"Content-Type": "application/json",
},
data: JSON.stringify({
url: "$EXTERNAL_URL"
name: "Example name",
}),
});

Step 2: Check the upload status

After uploading your asset, get the asset.id from the response object of the POST request. The asset.id represents the status of your upload.

When asset.status: "ready" is returned in the response, the asset has finished uploading and will be ready for playback. If asset.status: "waiting" is returned in the response, the asset is not available yet and you should make the API call again until asset.status: "ready".

const getAsset = await fetch("https://livepeer.studio/api/asset/{id}", {
method: "GET",
headers: {
Authorization: `Bearer ${process.env.API_TOKEN}`,
"Content-Type": "application/json",
},
});

Uploading Locally

Step 1: Generate upload URL

To upload the asset to the Livepeer network locally, you'll need to make a POST request to generate an upload URL.

const uploadAsset = await fetch("https://livepeer.studio/api/asset/request-upload", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.API_TOKEN}`,
"Content-Type": "application/json",
},
data: JSON.stringify({
name: "Example name",
}),
});

Step 2: Upload your video to the URL

Get the "url": "https://origin.livepeer.studio/api/assets/…" from the response object. Using the URL generated, upload your video with a PUT request.

const uploadAsset = await fetch("${url}", {
method: "PUT",
headers: {
Authorization: `Bearer ${process.env.LP_API_KEY}`
"Content-Type": "video/mp4"
},
data: fs.createReadStream(path)
});

Step 3: Check the upload status

After uploading your asset, get the asset.id from the response object of the POST request. The asset.id represents the status of your upload.

When asset.status: "ready" is returned in the response, the asset has finished uploading and will be ready for playback. If asset.status: "waiting" is returned in the response, the asset is not available yet and you should make the API call again until asset.status: "ready".

const getAsset = await fetch("https://livepeer.studio/api/asset/{id}", {
method: "GET",
headers: {
Authorization: `Bearer ${process.env.LP_API_KEY}`,
},
});