import { Livepeer } from "livepeer";
import {
TranscodePayloadSchemasStorageType,
TranscodeProfileEncoder,
TranscodeProfileProfile,
} from "livepeer/models/components";
const livepeer = new Livepeer({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await livepeer.transcode.create({
input: {
url: "https://s3.amazonaws.com/bucket/file.mp4",
},
storage: {
type: TranscodePayloadSchemasStorageType.Web3Storage,
credentials: {
proof: "EaJlcm9vdHOAZ3ZlcnNpb24BmgIBcRIg2uxHpcPYSWNtifMKFkPC7IEDvFDCxCd3ADViv0coV7SnYXNYRO2hA0AnblHEW38s3lSlcwaDjPn",
},
},
outputs: {
hls: {
path: "/samplevideo/hls",
},
mp4: {
path: "/samplevideo/mp4",
},
fmp4: {
path: "/samplevideo/fmp4",
},
},
profiles: [
{
width: 1280,
name: "720p",
height: 720,
bitrate: 3000000,
quality: 23,
fps: 30,
fpsDen: 1,
gop: "2",
profile: TranscodeProfileProfile.H264Baseline,
encoder: TranscodeProfileEncoder.H264,
},
],
});
// Handle the result
console.log(result);
}
run();
{
"id": "09F8B46C-61A0-4254-9875-F71F4C605BC7",
"type": "upload",
"createdAt": 1587667174725,
"scheduledAt": 1587667174725,
"inputAssetId": "09F8B46C-61A0-4254-9875-F71F4C605BC7",
"outputAssetId": "09F8B46C-61A0-4254-9875-F71F4C605BC7",
"projectId": "09F8B46C-61A0-4254-9875-F71F4C605BC7",
"requesterId": "09F8B46C-61A0-4254-9875-F71F4C605BC7",
"params": {
"upload": {
"url": "https://cdn.livepeer.com/ABC123/filename.mp4",
"encryption": {},
"c2pa": true,
"profiles": [
{
"width": 1280,
"name": "720p",
"height": 720,
"bitrate": 3000000,
"quality": 23,
"fps": 30,
"fpsDen": 1,
"gop": 2,
"profile": "H264Baseline",
"encoder": "H.264"
}
],
"targetSegmentSizeSecs": 6
},
"export": {
"custom": {
"url": "https://s3.amazonaws.com/my-bucket/path/filename.mp4?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=LLMMB",
"method": "POST",
"headers": {}
}
},
"exportData": {
"content": {
"data": "Hello, World!"
},
"ipfs": {
"$ref": "<any>",
"pinata": {}
},
"type": "text/plain",
"id": "09F8B46C-61A0-4254-9875-F71F4C605BC7"
},
"transcode-file": {
"input": {
"url": "https://cdn.livepeer.com/ABC123/filename.mp4"
},
"storage": {
"url": "s3+https://accessKeyId:secretAccessKey@s3Endpoint/bucket"
},
"outputs": {
"hls": {
"path": "/samplevideo/hls"
},
"mp4": {
"path": "/samplevideo/mp4"
}
},
"profiles": [
{
"width": 1280,
"name": "720p",
"height": 720,
"bitrate": 3000000,
"quality": 23,
"fps": 30,
"fpsDen": 1,
"gop": 2,
"profile": "H264Baseline",
"encoder": "H.264"
}
],
"targetSegmentSizeSecs": 10,
"creatorId": {
"type": "unverified",
"value": "<string>"
},
"c2pa": false
},
"clip": {
"url": "https://asset-cdn.lp-playback.monster/hls/1bde4o2i6xycudoy/static360p0.mp4",
"clipStrategy": {
"startTime": 1587667174725,
"endTime": 1587667174725,
"playbackId": "eaw4nk06ts2d0mzb"
},
"catalystPipelineStrategy": "catalyst_ffmpeg",
"sessionId": "d32ae9e6-c459-4931-9898-e86e2f5e7e16",
"inputId": "09F8B46C-61A0-4254-9875-F71F4C605BC7"
}
},
"status": {
"phase": "pending",
"updatedAt": 1587667174725,
"progress": 0.5,
"errorMessage": "Failed to upload file",
"retries": 3
},
"output": {
"upload": {
"assetSpec": {
"id": "09F8B46C-61A0-4254-9875-F71F4C605BC7",
"type": "video",
"playbackId": "eaw4nk06ts2d0mzb",
"userId": "66E2161C-7670-4D05-B71D-DA2D6979556F",
"playbackUrl": "https://livepeercdn.com/asset/ea03f37e-f861-4cdd-b495-0e60b6d753ad/index.m3u8",
"downloadUrl": "https://livepeercdn.com/asset/eaw4nk06ts2d0mzb/video/download.mp4",
"playbackPolicy": {
"type": "webhook",
"webhookId": "1bde4o2i6xycudoy",
"webhookContext": {
"streamerId": "my-custom-id"
},
"refreshInterval": 600,
"allowedOrigins": [
"<string>"
]
},
"source": {
"type": "url",
"url": "<string>",
"gatewayUrl": "<string>",
"encryption": {}
},
"creatorId": {
"type": "unverified",
"value": "user123"
},
"profiles": [
{
"width": 1280,
"name": "720p",
"height": 720,
"bitrate": 3000000,
"quality": 23,
"fps": 30,
"fpsDen": 1,
"gop": 2,
"profile": "H264Baseline",
"encoder": "H.264"
}
],
"storage": {
"ipfs": {
"spec": {},
"$ref": "<any>",
"nftMetadata": {
"cid": "<string>",
"url": "<string>",
"gatewayUrl": "<string>"
},
"updatedAt": 1587667174725
},
"status": {
"phase": "ready",
"progress": 0.5,
"errorMessage": "Failed to update storage",
"tasks": {
"pending": "09F8B46C-61A0-4254-9875-F71F4C605BC7",
"last": "09F8B46C-61A0-4254-9875-F71F4C605BC7",
"failed": "09F8B46C-61A0-4254-9875-F71F4C605BC7"
}
}
},
"status": {
"phase": "uploading",
"updatedAt": 1587667174725,
"progress": 123,
"errorMessage": "<string>"
},
"name": "filename.mp4",
"projectId": "aac12556-4d65-4d34-9fb6-d1f0985eb0a9",
"createdAt": 1587667174725,
"createdByTokenName": "<string>",
"size": 84934509,
"hash": [
{
"hash": "9b560b28b85378a5004117539196ab24e21bbd75b0e9eb1a8bc7c5fd80dc5b57",
"algorithm": "sha256"
}
],
"videoSpec": {
"format": "mp4",
"duration": 23.8328,
"bitrate": 1000000,
"tracks": [
{
"type": "video",
"codec": "aac",
"startTime": 23.8238,
"duration": 23.8238,
"bitrate": 1000000,
"width": 1920,
"height": 1080,
"pixelFormat": "yuv420p",
"fps": 30,
"channels": 2,
"sampleRate": 44100,
"bitDepth": 16
}
]
}
}
},
"export": {
"ipfs": {
"videoFileCid": "Qmabc123xyz341",
"videoFileUrl": "ipfs://Qmabc123xyz341",
"videoFileGatewayUrl": "https://gateway.ipfs.io/ipfs/Qmabc123xyz341",
"nftMetadataCid": "Qmabc123xyz341",
"nftMetadataUrl": "ipfs://Qmabc123xyz341",
"nftMetadataGatewayUrl": "https://gateway.ipfs.io/ipfs/Qmabc123xyz341"
}
},
"exportData": {
"ipfs": {
"cid": "Qmabc123xyz341"
}
}
}
}
POST /transcode
transcodes a video file and uploads the results to the
specified storage service.
Transcoding is asynchronous so you will need to check the status of the
task in order to determine when transcoding is complete. The id
field
in the response is the unique ID for the transcoding Task
. The task
status can be queried using the GET tasks
endpoint:
When status.phase
is completed
, transcoding will be complete and
the results will be stored in the storage service and the specified
output location.
The results will be available under params.outputs.hls.path
and
params.outputs.mp4.path
in the specified storage service.
This endpoint currently supports the following inputs:
{
"url": "https://www.example.com/video.mp4"
}
Name | Type | Description |
---|---|---|
url | string | A public HTTP URL for the video file. |
Note: For IPFS HTTP gateway URLs, the API currently only supports “path
style” URLs and does not support “subdomain style” URLs. The API will
support both styles of URLs in a future update.
S3 API Compatible Service
S3 credentials can be used to authenticate with a S3 API compatible
service to read a video file.
{
"type": "s3",
"endpoint": "https://gateway.storjshare.io",
"credentials": {
"accessKeyId": "$ACCESS_KEY_ID",
"secretAccessKey": "$SECRET_ACCESS_KEY"
},
"bucket": "inbucket",
"path": "/video/source.mp4"
}
This endpoint currently supports the following storage services:
{
"type": "s3",
"endpoint": "https://gateway.storjshare.io",
"credentials": {
"accessKeyId": "$ACCESS_KEY_ID",
"secretAccessKey": "$SECRET_ACCESS_KEY"
},
"bucket": "mybucket"
}
Web3 Storage
{
"type": "web3.storage",
"credentials": {
"proof": "$UCAN_DELEGATION_PROOF",
}
}
This endpoint currently supports the following output types:
HLS
{
"hls": {
"path": "/samplevideo/hls"
}
}
MP4
{
"mp4": {
"path": "/samplevideo/mp4"
}
}
import { Livepeer } from "livepeer";
import {
TranscodePayloadSchemasStorageType,
TranscodeProfileEncoder,
TranscodeProfileProfile,
} from "livepeer/models/components";
const livepeer = new Livepeer({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await livepeer.transcode.create({
input: {
url: "https://s3.amazonaws.com/bucket/file.mp4",
},
storage: {
type: TranscodePayloadSchemasStorageType.Web3Storage,
credentials: {
proof: "EaJlcm9vdHOAZ3ZlcnNpb24BmgIBcRIg2uxHpcPYSWNtifMKFkPC7IEDvFDCxCd3ADViv0coV7SnYXNYRO2hA0AnblHEW38s3lSlcwaDjPn",
},
},
outputs: {
hls: {
path: "/samplevideo/hls",
},
mp4: {
path: "/samplevideo/mp4",
},
fmp4: {
path: "/samplevideo/fmp4",
},
},
profiles: [
{
width: 1280,
name: "720p",
height: 720,
bitrate: 3000000,
quality: 23,
fps: 30,
fpsDen: 1,
gop: "2",
profile: TranscodeProfileProfile.H264Baseline,
encoder: TranscodeProfileEncoder.H264,
},
],
});
// Handle the result
console.log(result);
}
run();
{
"id": "09F8B46C-61A0-4254-9875-F71F4C605BC7",
"type": "upload",
"createdAt": 1587667174725,
"scheduledAt": 1587667174725,
"inputAssetId": "09F8B46C-61A0-4254-9875-F71F4C605BC7",
"outputAssetId": "09F8B46C-61A0-4254-9875-F71F4C605BC7",
"projectId": "09F8B46C-61A0-4254-9875-F71F4C605BC7",
"requesterId": "09F8B46C-61A0-4254-9875-F71F4C605BC7",
"params": {
"upload": {
"url": "https://cdn.livepeer.com/ABC123/filename.mp4",
"encryption": {},
"c2pa": true,
"profiles": [
{
"width": 1280,
"name": "720p",
"height": 720,
"bitrate": 3000000,
"quality": 23,
"fps": 30,
"fpsDen": 1,
"gop": 2,
"profile": "H264Baseline",
"encoder": "H.264"
}
],
"targetSegmentSizeSecs": 6
},
"export": {
"custom": {
"url": "https://s3.amazonaws.com/my-bucket/path/filename.mp4?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=LLMMB",
"method": "POST",
"headers": {}
}
},
"exportData": {
"content": {
"data": "Hello, World!"
},
"ipfs": {
"$ref": "<any>",
"pinata": {}
},
"type": "text/plain",
"id": "09F8B46C-61A0-4254-9875-F71F4C605BC7"
},
"transcode-file": {
"input": {
"url": "https://cdn.livepeer.com/ABC123/filename.mp4"
},
"storage": {
"url": "s3+https://accessKeyId:secretAccessKey@s3Endpoint/bucket"
},
"outputs": {
"hls": {
"path": "/samplevideo/hls"
},
"mp4": {
"path": "/samplevideo/mp4"
}
},
"profiles": [
{
"width": 1280,
"name": "720p",
"height": 720,
"bitrate": 3000000,
"quality": 23,
"fps": 30,
"fpsDen": 1,
"gop": 2,
"profile": "H264Baseline",
"encoder": "H.264"
}
],
"targetSegmentSizeSecs": 10,
"creatorId": {
"type": "unverified",
"value": "<string>"
},
"c2pa": false
},
"clip": {
"url": "https://asset-cdn.lp-playback.monster/hls/1bde4o2i6xycudoy/static360p0.mp4",
"clipStrategy": {
"startTime": 1587667174725,
"endTime": 1587667174725,
"playbackId": "eaw4nk06ts2d0mzb"
},
"catalystPipelineStrategy": "catalyst_ffmpeg",
"sessionId": "d32ae9e6-c459-4931-9898-e86e2f5e7e16",
"inputId": "09F8B46C-61A0-4254-9875-F71F4C605BC7"
}
},
"status": {
"phase": "pending",
"updatedAt": 1587667174725,
"progress": 0.5,
"errorMessage": "Failed to upload file",
"retries": 3
},
"output": {
"upload": {
"assetSpec": {
"id": "09F8B46C-61A0-4254-9875-F71F4C605BC7",
"type": "video",
"playbackId": "eaw4nk06ts2d0mzb",
"userId": "66E2161C-7670-4D05-B71D-DA2D6979556F",
"playbackUrl": "https://livepeercdn.com/asset/ea03f37e-f861-4cdd-b495-0e60b6d753ad/index.m3u8",
"downloadUrl": "https://livepeercdn.com/asset/eaw4nk06ts2d0mzb/video/download.mp4",
"playbackPolicy": {
"type": "webhook",
"webhookId": "1bde4o2i6xycudoy",
"webhookContext": {
"streamerId": "my-custom-id"
},
"refreshInterval": 600,
"allowedOrigins": [
"<string>"
]
},
"source": {
"type": "url",
"url": "<string>",
"gatewayUrl": "<string>",
"encryption": {}
},
"creatorId": {
"type": "unverified",
"value": "user123"
},
"profiles": [
{
"width": 1280,
"name": "720p",
"height": 720,
"bitrate": 3000000,
"quality": 23,
"fps": 30,
"fpsDen": 1,
"gop": 2,
"profile": "H264Baseline",
"encoder": "H.264"
}
],
"storage": {
"ipfs": {
"spec": {},
"$ref": "<any>",
"nftMetadata": {
"cid": "<string>",
"url": "<string>",
"gatewayUrl": "<string>"
},
"updatedAt": 1587667174725
},
"status": {
"phase": "ready",
"progress": 0.5,
"errorMessage": "Failed to update storage",
"tasks": {
"pending": "09F8B46C-61A0-4254-9875-F71F4C605BC7",
"last": "09F8B46C-61A0-4254-9875-F71F4C605BC7",
"failed": "09F8B46C-61A0-4254-9875-F71F4C605BC7"
}
}
},
"status": {
"phase": "uploading",
"updatedAt": 1587667174725,
"progress": 123,
"errorMessage": "<string>"
},
"name": "filename.mp4",
"projectId": "aac12556-4d65-4d34-9fb6-d1f0985eb0a9",
"createdAt": 1587667174725,
"createdByTokenName": "<string>",
"size": 84934509,
"hash": [
{
"hash": "9b560b28b85378a5004117539196ab24e21bbd75b0e9eb1a8bc7c5fd80dc5b57",
"algorithm": "sha256"
}
],
"videoSpec": {
"format": "mp4",
"duration": 23.8328,
"bitrate": 1000000,
"tracks": [
{
"type": "video",
"codec": "aac",
"startTime": 23.8238,
"duration": 23.8238,
"bitrate": 1000000,
"width": 1920,
"height": 1080,
"pixelFormat": "yuv420p",
"fps": 30,
"channels": 2,
"sampleRate": 44100,
"bitDepth": 16
}
]
}
}
},
"export": {
"ipfs": {
"videoFileCid": "Qmabc123xyz341",
"videoFileUrl": "ipfs://Qmabc123xyz341",
"videoFileGatewayUrl": "https://gateway.ipfs.io/ipfs/Qmabc123xyz341",
"nftMetadataCid": "Qmabc123xyz341",
"nftMetadataUrl": "ipfs://Qmabc123xyz341",
"nftMetadataGatewayUrl": "https://gateway.ipfs.io/ipfs/Qmabc123xyz341"
}
},
"exportData": {
"ipfs": {
"cid": "Qmabc123xyz341"
}
}
}
}
Bearer authentication header of the form Bearer <token>
, where <token>
is your auth token.
Success
The response is of type object
.
Was this page helpful?