(Stream)
Operations related to livestream api
- Create - Create a stream
- GetAll - Retrieve streams
- Get - Retrieve a stream
- Update - Update a stream
- Delete - Delete a stream
- Terminate - Terminates a live stream
- StartPull - Start ingest for a pull stream
- CreateClip - Create a clip
- GetClips - Retrieve clips of a livestream
- AddMultistreamTarget - Add a multistream target
- RemoveMultistreamTarget - Remove a multistream target
The only parameter you are required to set is the name of your stream,
but we also highly recommend that you define transcoding profiles
parameter that suits your specific broadcasting configuration.
If you do not define transcoding rendition profiles when creating the
stream, a default set of profiles will be used. These profiles include
240p, 360p, 480p and 720p.
The playback policy is set to public by default for new streams. It can
also be added upon the creation of a new stream by adding
"playbackPolicy": {"type": "jwt"}
package main
import(
livepeergo "github.com/livepeer/livepeer-go"
"context"
"github.com/livepeer/livepeer-go/models/components"
"log"
)
func main() {
s := livepeergo.New(
livepeergo.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
ctx := context.Background()
res, err := s.Stream.Create(ctx, components.NewStreamPayload{
Name: "test_stream",
Pull: &components.Pull{
Source: "https://myservice.com/live/stream.flv",
Headers: map[string]string{
"Authorization": "Bearer 123",
},
Location: &components.Location{
Lat: 39.739,
Lon: -104.988,
},
},
PlaybackPolicy: &components.PlaybackPolicy{
Type: components.TypeWebhook,
WebhookID: livepeergo.String("1bde4o2i6xycudoy"),
WebhookContext: map[string]any{
"streamerId": "my-custom-id",
},
RefreshInterval: livepeergo.Float64(600),
},
Profiles: []components.FfmpegProfile{
components.FfmpegProfile{
Width: 1280,
Name: "720p",
Height: 720,
Bitrate: 3000000,
Fps: 30,
FpsDen: livepeergo.Int64(1),
Quality: livepeergo.Int64(23),
Gop: livepeergo.String("2"),
Profile: components.ProfileH264Baseline.ToPointer(),
},
},
Record: livepeergo.Bool(false),
RecordingSpec: &components.NewStreamPayloadRecordingSpec{
Profiles: []components.TranscodeProfile{
components.TranscodeProfile{
Width: livepeergo.Int64(1280),
Name: livepeergo.String("720p"),
Height: livepeergo.Int64(720),
Bitrate: 3000000,
Quality: livepeergo.Int64(23),
Fps: livepeergo.Int64(30),
FpsDen: livepeergo.Int64(1),
Gop: livepeergo.String("2"),
Profile: components.TranscodeProfileProfileH264Baseline.ToPointer(),
Encoder: components.TranscodeProfileEncoderH264.ToPointer(),
},
},
},
Multistream: &components.Multistream{
Targets: []components.Target{
components.Target{
Profile: "720p",
VideoOnly: livepeergo.Bool(false),
ID: livepeergo.String("PUSH123"),
Spec: &components.TargetSpec{
Name: livepeergo.String("My target"),
URL: "rtmps://live.my-service.tv/channel/secretKey",
},
},
},
},
})
if err != nil {
log.Fatal(err)
}
if res.Stream != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
request |
components.NewStreamPayload | ✔️ | The request object to use for the request. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CreateStreamResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.SDKError | 4xx-5xx | / |
Retrieve streams
package main
import(
livepeergo "github.com/livepeer/livepeer-go"
"context"
"log"
)
func main() {
s := livepeergo.New(
livepeergo.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
ctx := context.Background()
res, err := s.Stream.GetAll(ctx, nil)
if err != nil {
log.Fatal(err)
}
if res.Data != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
streamsonly |
*string | ➖ | N/A |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.GetStreamsResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.SDKError | 4xx-5xx | / |
Retrieve a stream
package main
import(
livepeergo "github.com/livepeer/livepeer-go"
"context"
"log"
)
func main() {
s := livepeergo.New(
livepeergo.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
ctx := context.Background()
res, err := s.Stream.Get(ctx, "<id>")
if err != nil {
log.Fatal(err)
}
if res.Stream != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
id |
string | ✔️ | ID of the stream |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.GetStreamResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.SDKError | 4xx-5xx | / |
Update a stream
package main
import(
livepeergo "github.com/livepeer/livepeer-go"
"context"
"github.com/livepeer/livepeer-go/models/components"
"log"
)
func main() {
s := livepeergo.New(
livepeergo.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
ctx := context.Background()
res, err := s.Stream.Update(ctx, "<id>", components.StreamPatchPayload{
Record: livepeergo.Bool(false),
Multistream: &components.Multistream{
Targets: []components.Target{
components.Target{
Profile: "720p",
VideoOnly: livepeergo.Bool(false),
ID: livepeergo.String("PUSH123"),
Spec: &components.TargetSpec{
Name: livepeergo.String("My target"),
URL: "rtmps://live.my-service.tv/channel/secretKey",
},
},
},
},
PlaybackPolicy: &components.PlaybackPolicy{
Type: components.TypeWebhook,
WebhookID: livepeergo.String("1bde4o2i6xycudoy"),
WebhookContext: map[string]any{
"streamerId": "my-custom-id",
},
RefreshInterval: livepeergo.Float64(600),
},
Profiles: []components.FfmpegProfile{
components.FfmpegProfile{
Width: 1280,
Name: "720p",
Height: 720,
Bitrate: 3000000,
Fps: 30,
FpsDen: livepeergo.Int64(1),
Quality: livepeergo.Int64(23),
Gop: livepeergo.String("2"),
Profile: components.ProfileH264Baseline.ToPointer(),
},
},
RecordingSpec: &components.RecordingSpec{
Profiles: []components.TranscodeProfile{
components.TranscodeProfile{
Width: livepeergo.Int64(1280),
Name: livepeergo.String("720p"),
Height: livepeergo.Int64(720),
Bitrate: 3000000,
Quality: livepeergo.Int64(23),
Fps: livepeergo.Int64(30),
FpsDen: livepeergo.Int64(1),
Gop: livepeergo.String("2"),
Profile: components.TranscodeProfileProfileH264Baseline.ToPointer(),
Encoder: components.TranscodeProfileEncoderH264.ToPointer(),
},
},
},
})
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
id |
string | ✔️ | ID of the stream |
streamPatchPayload |
components.StreamPatchPayload | ✔️ | N/A |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.UpdateStreamResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.SDKError | 4xx-5xx | / |
This will also suspend any active stream sessions, so make sure to wait until the stream has finished. To explicitly interrupt an active session, consider instead updating the suspended field in the stream using the PATCH stream API.
package main
import(
livepeergo "github.com/livepeer/livepeer-go"
"context"
"log"
)
func main() {
s := livepeergo.New(
livepeergo.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
ctx := context.Background()
res, err := s.Stream.Delete(ctx, "<id>")
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
id |
string | ✔️ | ID of the stream |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.DeleteStreamResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.SDKError | 4xx-5xx | / |
DELETE /stream/{id}/terminate
can be used to terminate an ongoing
session on a live stream. Unlike suspending the stream, it allows the
streamer to restart streaming even immediately, but it will force
terminate the current session and stop the recording.
A 204 No Content status response indicates the stream was successfully
terminated.
package main
import(
livepeergo "github.com/livepeer/livepeer-go"
"context"
"log"
)
func main() {
s := livepeergo.New(
livepeergo.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
ctx := context.Background()
res, err := s.Stream.Terminate(ctx, "<id>")
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
id |
string | ✔️ | ID of the stream |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.TerminateStreamResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.SDKError | 4xx-5xx | / |
POST /stream/{id}/start-pull
can be used to start ingest for a stream
configured with a pull source. If the stream has recording configured,
it will also start recording.
A 204 No Content status response indicates the stream was successfully
started.
package main
import(
livepeergo "github.com/livepeer/livepeer-go"
"context"
"log"
)
func main() {
s := livepeergo.New(
livepeergo.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
ctx := context.Background()
res, err := s.Stream.StartPull(ctx, "<id>")
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
id |
string | ✔️ | ID of the stream |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.StartPullStreamResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.SDKError | 4xx-5xx | / |
Create a clip
package main
import(
livepeergo "github.com/livepeer/livepeer-go"
"context"
"github.com/livepeer/livepeer-go/models/components"
"log"
)
func main() {
s := livepeergo.New(
livepeergo.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
ctx := context.Background()
res, err := s.Stream.CreateClip(ctx, components.ClipPayload{
PlaybackID: "eaw4nk06ts2d0mzb",
StartTime: 1587667174725,
EndTime: livepeergo.Float64(1587667174725),
Name: livepeergo.String("My Clip"),
SessionID: livepeergo.String("de7818e7-610a-4057-8f6f-b785dc1e6f88"),
})
if err != nil {
log.Fatal(err)
}
if res.Data != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
request |
components.ClipPayload | ✔️ | The request object to use for the request. |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.CreateClipResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.SDKError | 4xx-5xx | / |
Retrieve clips of a livestream
package main
import(
livepeergo "github.com/livepeer/livepeer-go"
"context"
"log"
)
func main() {
s := livepeergo.New(
livepeergo.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
ctx := context.Background()
res, err := s.Stream.GetClips(ctx, "<id>")
if err != nil {
log.Fatal(err)
}
if res.Data != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
id |
string | ✔️ | ID of the parent stream or playbackId of parent stream |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.GetClipsResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.SDKError | 4xx-5xx | / |
Add a multistream target
package main
import(
livepeergo "github.com/livepeer/livepeer-go"
"context"
"github.com/livepeer/livepeer-go/models/components"
"log"
)
func main() {
s := livepeergo.New(
livepeergo.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
ctx := context.Background()
res, err := s.Stream.AddMultistreamTarget(ctx, "<id>", components.TargetAddPayload{
Profile: "720p0",
VideoOnly: livepeergo.Bool(false),
ID: livepeergo.String("PUSH123"),
Spec: &components.TargetAddPayloadSpec{
Name: livepeergo.String("My target"),
URL: "rtmps://live.my-service.tv/channel/secretKey",
},
})
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
id |
string | ✔️ | ID of the parent stream |
targetAddPayload |
components.TargetAddPayload | ✔️ | N/A |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.AddMultistreamTargetResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.SDKError | 4xx-5xx | / |
Remove a multistream target
package main
import(
livepeergo "github.com/livepeer/livepeer-go"
"context"
"log"
)
func main() {
s := livepeergo.New(
livepeergo.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
)
ctx := context.Background()
res, err := s.Stream.RemoveMultistreamTarget(ctx, "<id>", "<value>")
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
Parameter | Type | Required | Description |
---|---|---|---|
ctx |
context.Context | ✔️ | The context to use for the request. |
id |
string | ✔️ | ID of the parent stream |
targetID |
string | ✔️ | ID of the multistream target |
opts |
[]operations.Option | ➖ | The options for this request. |
*operations.RemoveMultistreamTargetResponse, error
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.SDKError | 4xx-5xx | / |