Skip to content

Commit

Permalink
Merge pull request #11 from daystram/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
daystram authored Feb 6, 2021
2 parents f786f0b + 7a07c33 commit 6d774b7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ With DASH streaming, videos uploaded to __cast__ are first re-encoded by the Tra
### RTMP
RTMP streaming allows the users to stream live to their viewers via a direct uplink to __cast__'s servers. Users can use clients such as [OBS Studio](https://obsproject.com/) or [Streamlabs](https://streamlabs.com/).

### GPU Hardware Acceleration
Uploaded videos are ingested by __cast__'s transcoding nodes (`cast-is`) powered with NVIDIA CUDA GPU hardware acceleration. These transcoders are highly scalable and can be deployed with a high number of replica either on- or off-premise.

With GPU acceleration, `h264_nvenc` encoder is used. On environments without GPU, `cast-is` can also be started to use CPU encoding only using `libx264` encoder.

## Services
The application comes in three parts:

Expand All @@ -32,6 +37,15 @@ The application comes in three parts:
|Transcoder|`cast-is`|[Go](https://golang.org/), [FFMpeg](https://ffmpeg.org/), [RabbitMQ](https://www.rabbitmq.com/), S3|
|Front-end|`cast-fe`|JavaScript, [ReactJS](https://beego.me/)|

## Test Stream
You can use FFmpeg to create a test livestream. Use the following command:

```shell
$ ffmpeg -f lavfi -re -i testsrc2=s=1920x1080:r=60,format=yuv420p -f lavfi -i sine=f=440:b=4 -ac 2 -c:a pcm_s16le -c:v libx264 -f flv rtmp://cast.daystram.com/live/STREAM_KEY
```

This will create a sample 1080p 60 FPS stream with a 440 Hz sine wave sound. Ensure the stream key is provided correctly and stream window has been opened in the Dashboard.

## Deploy
`cast-be`, `cast-is`, and `cast-fe` are containerized and pushed to [Docker Hub](https://hub.docker.com/r/daystram/cast). They are tagged based on their application name and version, e.g. `daystram/cast:be` or `daystram/cast:be-v2.0.1`.

Expand Down Expand Up @@ -142,10 +156,11 @@ services:
This image is built on top of [NVIDIA's CUDA images](https://hub.docker.com/r/nvidia/cuda/) to enable FFmpeg harware acceleration on supported hosts. MP4Box is built from source, as seen on the [Dockerfile](https://github.com/daystram/cast/blob/master/cast-is/ingest-base.Dockerfile).

### MongoDB Indexes
For features to work properly, some indexes needs to be created in the MongoDB instance. Use the following command in `mongo` CLI to create indexes for `video` collection:
For features to work properly, some indexes needs to be created in the MongoDB instance. Use the following command in `mongo` CLI to create indexes for the collated `video` collection:

```
use MONGODB_NAME;
db.createCollection("video", {collation: {locale: "en", strength: 2}})
db.video.createIndex({title: "text", description: "text"}, {collation: {locale: "simple"}});
db.video.createIndex({hash: "hashed"});
```
Expand Down
2 changes: 1 addition & 1 deletion cast-be/handlers/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (m *module) ConnectChatWS(ctx *context.Context, hash string, userID ...stri
return
}
}
go m.ChatReaderWorker(ws, hash, user, video.Type == constants.VideoTypeLive && video.Author.ID != user.ID)
go m.ChatReaderWorker(ws, hash, user, video.Type == constants.VideoTypeLive)
return
}

Expand Down
5 changes: 4 additions & 1 deletion cast-be/models/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,10 @@ func (o *videoOrm) IncrementViews(hash string, decrement ...bool) error {
if len(decrement) > 0 && decrement[0] {
delta = -1
}
return o.collection.FindOneAndUpdate(context.Background(), bson.M{"hash": hash}, bson.M{"$inc": bson.M{"views": delta}}).Err()
if err := o.collection.FindOneAndUpdate(context.Background(), bson.M{"hash": hash}, bson.M{"$inc": bson.M{"views": delta}}).Err(); err != nil {
return err
}
return o.collection.FindOneAndUpdate(context.Background(), bson.M{"hash": hash}, bson.M{"$max": bson.M{"views": 0}}).Err()
}

func (o *videoOrm) SetLive(authorID string, pending, live bool) (err error) {
Expand Down
2 changes: 1 addition & 1 deletion cast-fe/src/components/HybridPlayer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ class HybridPlayer extends React.Component {
src: this.props.url,
type: this.props.live ? "video/x-flv" : "application/dash+xml",
});
this.player.load();
this.player.autoplay(this.props.live);
if (this.props.live) this.player.play();
this.player.poster(this.props.thumbnail);
this.player.load();
}

render() {
Expand Down

0 comments on commit 6d774b7

Please sign in to comment.