import { Livepeer } from "livepeer";
import { Profile, TranscodeProfileEncoder, TranscodeProfileProfile, Type } from "livepeer/models/components";
const livepeer = new Livepeer({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await livepeer.stream.create({
name: "test_stream",
pull: {
source: "https://myservice.com/live/stream.flv",
headers: {
"Authorization": "Bearer 123",
},
location: {
lat: 39.739,
lon: -104.988,
},
},
playbackPolicy: {
type: Type.Webhook,
webhookId: "1bde4o2i6xycudoy",
webhookContext: {
"streamerId": "my-custom-id",
},
refreshInterval: 600,
},
profiles: [
{
width: 1280,
name: "720p",
height: 720,
bitrate: 3000000,
fps: 30,
fpsDen: 1,
quality: 23,
gop: "2",
profile: Profile.H264Baseline,
},
],
record: false,
recordingSpec: {
profiles: [
{
width: 1280,
name: "720p",
height: 720,
bitrate: 3000000,
quality: 23,
fps: 30,
fpsDen: 1,
gop: "2",
profile: TranscodeProfileProfile.H264Baseline,
encoder: TranscodeProfileEncoder.H264,
},
{
width: 1280,
name: "720p",
height: 720,
bitrate: 3000000,
quality: 23,
fps: 30,
fpsDen: 1,
gop: "2",
profile: TranscodeProfileProfile.H264Baseline,
encoder: TranscodeProfileEncoder.H264,
},
],
},
multistream: {
targets: [
{
profile: "720p0",
videoOnly: false,
id: "PUSH123",
spec: {
name: "My target",
url: "rtmps://live.my-service.tv/channel/secretKey",
},
},
],
},
});
// Handle the result
console.log(result);
}
run();{
"name": "test_stream",
"id": "de7818e7-610a-4057-8f6f-b785dc1e6f88",
"kind": "stream",
"creatorId": {
"type": "unverified",
"value": "user123"
},
"userTags": {},
"lastSeen": 1587667174725,
"sourceSegments": 1,
"transcodedSegments": 2,
"sourceSegmentsDuration": 1,
"transcodedSegmentsDuration": 2,
"sourceBytes": 1,
"transcodedBytes": 2,
"ingestRate": 1,
"outgoingRate": 2,
"isActive": true,
"isHealthy": "<unknown>",
"issues": "<unknown>",
"createdByTokenName": "abc-123-xyz-456",
"createdAt": 1587667174725,
"parentId": "de7818e7-610a-4057-8f6f-b785dc1e6f88",
"streamKey": "hgebdhhigq",
"pull": {
"source": "https://myservice.com/live/stream.flv",
"headers": {
"Authorization": "Bearer 123"
},
"isMobile": 0,
"location": {
"lat": 39.739,
"lon": -104.988
}
},
"playbackId": "eaw4nk06ts2d0mzb",
"playbackPolicy": {
"type": "webhook",
"webhookId": "1bde4o2i6xycudoy",
"webhookContext": {
"streamerId": "my-custom-id"
},
"refreshInterval": 600,
"allowedOrigins": [
"<string>"
]
},
"profiles": [
{
"name": "240p0",
"fps": 0,
"bitrate": 250000,
"width": 426,
"height": 240
},
{
"name": "360p0",
"fps": 0,
"bitrate": 800000,
"width": 640,
"height": 360
},
{
"name": "480p0",
"fps": 0,
"bitrate": 1600000,
"width": 854,
"height": 480
},
{
"name": "720p0",
"fps": 0,
"bitrate": 3000000,
"width": 1280,
"height": 720
}
],
"projectId": "aac12556-4d65-4d34-9fb6-d1f0985eb0a9",
"record": false,
"recordingSpec": {
"profiles": [
{
"bitrate": 3000000,
"width": 1280,
"name": "720p",
"height": 720,
"quality": 23,
"fps": 30,
"fpsDen": 1,
"gop": 2,
"profile": "H264Baseline",
"encoder": "H.264"
}
]
},
"multistream": {
"targets": [
{
"id": "PUSH123",
"profile": "720p"
}
]
},
"suspended": true,
"lastTerminatedAt": 1713281212993,
"userId": "we7818e7-610a-4057-8f6f-b785dc1e6f88",
"renditions": {}
}Créer une nouvelle diffusion en direct
import { Livepeer } from "livepeer";
import { Profile, TranscodeProfileEncoder, TranscodeProfileProfile, Type } from "livepeer/models/components";
const livepeer = new Livepeer({
apiKey: "<YOUR_BEARER_TOKEN_HERE>",
});
async function run() {
const result = await livepeer.stream.create({
name: "test_stream",
pull: {
source: "https://myservice.com/live/stream.flv",
headers: {
"Authorization": "Bearer 123",
},
location: {
lat: 39.739,
lon: -104.988,
},
},
playbackPolicy: {
type: Type.Webhook,
webhookId: "1bde4o2i6xycudoy",
webhookContext: {
"streamerId": "my-custom-id",
},
refreshInterval: 600,
},
profiles: [
{
width: 1280,
name: "720p",
height: 720,
bitrate: 3000000,
fps: 30,
fpsDen: 1,
quality: 23,
gop: "2",
profile: Profile.H264Baseline,
},
],
record: false,
recordingSpec: {
profiles: [
{
width: 1280,
name: "720p",
height: 720,
bitrate: 3000000,
quality: 23,
fps: 30,
fpsDen: 1,
gop: "2",
profile: TranscodeProfileProfile.H264Baseline,
encoder: TranscodeProfileEncoder.H264,
},
{
width: 1280,
name: "720p",
height: 720,
bitrate: 3000000,
quality: 23,
fps: 30,
fpsDen: 1,
gop: "2",
profile: TranscodeProfileProfile.H264Baseline,
encoder: TranscodeProfileEncoder.H264,
},
],
},
multistream: {
targets: [
{
profile: "720p0",
videoOnly: false,
id: "PUSH123",
spec: {
name: "My target",
url: "rtmps://live.my-service.tv/channel/secretKey",
},
},
],
},
});
// Handle the result
console.log(result);
}
run();{
"name": "test_stream",
"id": "de7818e7-610a-4057-8f6f-b785dc1e6f88",
"kind": "stream",
"creatorId": {
"type": "unverified",
"value": "user123"
},
"userTags": {},
"lastSeen": 1587667174725,
"sourceSegments": 1,
"transcodedSegments": 2,
"sourceSegmentsDuration": 1,
"transcodedSegmentsDuration": 2,
"sourceBytes": 1,
"transcodedBytes": 2,
"ingestRate": 1,
"outgoingRate": 2,
"isActive": true,
"isHealthy": "<unknown>",
"issues": "<unknown>",
"createdByTokenName": "abc-123-xyz-456",
"createdAt": 1587667174725,
"parentId": "de7818e7-610a-4057-8f6f-b785dc1e6f88",
"streamKey": "hgebdhhigq",
"pull": {
"source": "https://myservice.com/live/stream.flv",
"headers": {
"Authorization": "Bearer 123"
},
"isMobile": 0,
"location": {
"lat": 39.739,
"lon": -104.988
}
},
"playbackId": "eaw4nk06ts2d0mzb",
"playbackPolicy": {
"type": "webhook",
"webhookId": "1bde4o2i6xycudoy",
"webhookContext": {
"streamerId": "my-custom-id"
},
"refreshInterval": 600,
"allowedOrigins": [
"<string>"
]
},
"profiles": [
{
"name": "240p0",
"fps": 0,
"bitrate": 250000,
"width": 426,
"height": 240
},
{
"name": "360p0",
"fps": 0,
"bitrate": 800000,
"width": 640,
"height": 360
},
{
"name": "480p0",
"fps": 0,
"bitrate": 1600000,
"width": 854,
"height": 480
},
{
"name": "720p0",
"fps": 0,
"bitrate": 3000000,
"width": 1280,
"height": 720
}
],
"projectId": "aac12556-4d65-4d34-9fb6-d1f0985eb0a9",
"record": false,
"recordingSpec": {
"profiles": [
{
"bitrate": 3000000,
"width": 1280,
"name": "720p",
"height": 720,
"quality": 23,
"fps": 30,
"fpsDen": 1,
"gop": 2,
"profile": "H264Baseline",
"encoder": "H.264"
}
]
},
"multistream": {
"targets": [
{
"id": "PUSH123",
"profile": "720p"
}
]
},
"suspended": true,
"lastTerminatedAt": 1713281212993,
"userId": "we7818e7-610a-4057-8f6f-b785dc1e6f88",
"renditions": {}
}Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Afficher attributs enfants
Whether the playback policy for an asset or stream is public or signed
Afficher attributs enfants
Afficher attributs enfants
Afficher attributs enfants
Success
"test_stream"
"de7818e7-610a-4057-8f6f-b785dc1e6f88"
"stream"
Afficher attributs enfants
User input tags associated with the stream
Afficher attributs enfants
1587667174725
1
2
Duration of all the source segments, sec
1
Duration of all the transcoded segments, sec
2
1
2
Rate at which sourceBytes increases (bytes/second)
1
Rate at which transcodedBytes increases (bytes/second)
2
If currently active
true
Name of the token used to create this object
"abc-123-xyz-456"
Timestamp (in milliseconds) at which stream object was created
1587667174725
Points to parent stream object
"de7818e7-610a-4057-8f6f-b785dc1e6f88"
Used to form RTMP ingest URL
"hgebdhhigq"
Configuration for a stream that should be actively pulled from an external source, rather than pushed to Livepeer. If specified, the stream will not have a streamKey.
Afficher attributs enfants
The playback ID to use with the Playback Info endpoint to retrieve playback URLs.
"eaw4nk06ts2d0mzb"
Whether the playback policy for an asset or stream is public or signed
Afficher attributs enfants
Profiles to transcode the stream into. If not specified, a default set of profiles will be used with 240p, 360p, 480p and 720p resolutions. Keep in mind that the source rendition is always kept.
Afficher attributs enfants
The ID of the project
"aac12556-4d65-4d34-9fb6-d1f0985eb0a9"
Should this stream be recorded? Uses default settings. For more customization, create and configure an object store.
false
Configuration for recording the stream. This can only be set if
record is true.
Afficher attributs enfants
Afficher attributs enfants
If currently suspended
Timestamp (in milliseconds) when the stream was last terminated
1713281212993
"we7818e7-610a-4057-8f6f-b785dc1e6f88"
Cette page vous a-t-elle été utile ?