Skip to content

Commit

Permalink
README: Add codelang blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
hjpotter92 committed Jun 1, 2023
1 parent 20aa13b commit beebca3
Showing 1 changed file with 68 additions and 67 deletions.
135 changes: 68 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[![Build Status](https://circleci.com/gh/livepeer/lpms.svg?style=shield&circle-token=e33534f6f4e2a6af19bb1596d7b72767a246cbab)](https://circleci.com/gh/livepeer/lpms/tree/master)
![Build status](https://github.com/livepeer/lpms/actions/workflows/linux.yml/badge.svg?branch=master)

# LPMS - Livepeer Media Server

LPMS is a media server that can run independently, or on top of the [Livepeer](https://livepeer.org)
LPMS is a media server that can run independently, or on top of the [Livepeer](https://livepeer.org)
network. It allows you to manipulate / broadcast a live video stream. Currently, LPMS supports RTMP
as input format and RTMP/HLS as output formats.

LPMS can be integrated into another service, or run as a standalone service. To try LPMS as a
LPMS can be integrated into another service, or run as a standalone service. To try LPMS as a
standalone service, simply get the package:
```
go get -d github.com/livepeer/lpms/cmd/example
```

Go to the lpms root directory at `$GOPATH/src/github.com/livepeer/lpms`. If needed, install the required dependencies; see the Requirements section below. Then build the sample app and run it:

```
```sh
go build cmd/example/main.go
./example
```
Expand Down Expand Up @@ -53,7 +53,7 @@ I0324 09:44:14.639429 80673 listener.go:42] Got RTMP Stream: test
LPMS exposes a few different methods for customization. As an example, take a look at `cmd/main.go`.

To create a new LPMS server:
```
```go
// Specify ports you want the server to run on, and the working directory for
// temporary files. See `core/lpms.go` for a full list of LPMSOpts
opts := lpms.LPMSOpts {
Expand All @@ -65,70 +65,71 @@ lpms := lpms.New(&opts)
```

To handle RTMP publish:
```
lpms.HandleRTMPPublish(
//getStreamID
func(url *url.URL) (strmID string) {
return getStreamIDFromPath(reqPath)
},
//getStream
func(url *url.URL, rtmpStrm stream.RTMPVideoStream) (err error) {
return nil
},
//finishStream
func(url *url.URL, rtmpStrm stream.RTMPVideoStream) (err error) {
return nil
})
```go
lpms.HandleRTMPPublish(
//getStreamID
func(url *url.URL) (strmID string) {
return getStreamIDFromPath(reqPath)
},
//getStream
func(url *url.URL, rtmpStrm stream.RTMPVideoStream) (err error) {
return nil
},
//finishStream
func(url *url.URL, rtmpStrm stream.RTMPVideoStream) (err error) {
return nil
})
```

To handle RTMP playback:
```
lpms.HandleRTMPPlay(
//getStream
func(ctx context.Context, reqPath string, dst av.MuxCloser) error {
glog.Infof("Got req: ", reqPath)
streamID := getStreamIDFromPath(reqPath)
src := streamDB.db[streamID]
if src != nil {
src.ReadRTMPFromStream(ctx, dst)
} else {
glog.Error("Cannot find stream for ", streamID)
return stream.ErrNotFound
}
return nil
})

```go
lpms.HandleRTMPPlay(
//getStream
func(ctx context.Context, reqPath string, dst av.MuxCloser) error {
glog.Infof("Got req: ", reqPath)
streamID := getStreamIDFromPath(reqPath)
src := streamDB.db[streamID]
if src != nil {
src.ReadRTMPFromStream(ctx, dst)
} else {
glog.Error("Cannot find stream for ", streamID)
return stream.ErrNotFound
}
return nil
})
```

To handle HLS playback:
```
lpms.HandleHLSPlay(
//getHLSBuffer
func(reqPath string) (*stream.HLSBuffer, error) {
streamID := getHLSStreamIDFromPath(reqPath)
buffer := bufferDB.db[streamID]
s := streamDB.db[streamID]
if s == nil {
return nil, stream.ErrNotFound
}

if buffer == nil {
//Create the buffer and start copying the stream into the buffer
buffer = stream.NewHLSBuffer()
bufferDB.db[streamID] = buffer
//Subscribe to the stream
sub := stream.NewStreamSubscriber(s)
go sub.StartHLSWorker(context.Background())
err := sub.SubscribeHLS(streamID, buffer)
if err != nil {
return nil, stream.ErrStreamSubscriber
}
```go
lpms.HandleHLSPlay(
//getHLSBuffer
func(reqPath string) (*stream.HLSBuffer, error) {
streamID := getHLSStreamIDFromPath(reqPath)
buffer := bufferDB.db[streamID]
s := streamDB.db[streamID]

if s == nil {
return nil, stream.ErrNotFound
}

if buffer == nil {
//Create the buffer and start copying the stream into the buffer
buffer = stream.NewHLSBuffer()
bufferDB.db[streamID] = buffer

//Subscribe to the stream
sub := stream.NewStreamSubscriber(s)
go sub.StartHLSWorker(context.Background())
err := sub.SubscribeHLS(streamID, buffer)
if err != nil {
return nil, stream.ErrStreamSubscriber
}
}

return buffer, nil
})
return buffer, nil
})
```

### GPU Support
Expand All @@ -140,14 +141,14 @@ this.

To execute the nvidia tests within the `ffmpeg` directory, run this command:

```
```sh
go test --tags=nvidia -run Nvidia

```

To run the tests on a particular GPU, use the GPU_DEVICE environment variable:

```
```sh
# Runs on GPU number 3
GPU_DEVICE=3 go test --tags=nvidia -run Nvidia
```
Expand All @@ -158,25 +159,25 @@ that can be used as a reference to the LPMS GPU transcoding API. The sample
program can select GPU or software processing via CLI flags. Run the sample
program via:

```
```sh
# software processing
go run cmd/transcoding/transcoding.go transcoder/test.ts P144p30fps16x9,P240p30fps16x9 sw

# nvidia processing, GPU number 2
go run cmd/transcoding/transcoding.go transcoder/test.ts P144p30fps16x9,P240p30fps16x9 nv 2
```

### Testing GPU transcoding with failed segments from Livepeer production environment
### Testing GPU transcoding with failed segments from Livepeer production environment
To test transcoding of segments failed on production in Nvidia environment:
1. Install Livepeer from sources by following the [installation guide](https://docs.livepeer.org/guides/orchestrating/install-go-livepeer#build-from-source)
2. Install [Google Cloud SDK](https://cloud.google.com/sdk/docs/install-sdk)
3. Make sure you have access to the bucket with the segments
4. Download the segments:
```
4. Download the segments:
```sh
gsutil cp -r gs://livepeer-production-failed-transcodes /home/livepeer-production-failed-transcodes
```
5. Run the test
```
```sh
cd transcoder
FAILCASE_PATH="/home/livepeer-production-failed-transcodes" go test --tags=nvidia -timeout 6h -run TestNvidia_CheckFailCase
```
Expand Down

0 comments on commit beebca3

Please sign in to comment.