• Stars
    star
    499
  • Rank 88,341 (Top 2 %)
  • Language
    TypeScript
  • Created about 4 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The repo for https://stream.new

Mux Logo

stream.new

Stars Badge Forks Badge Pull Requests Badge Issues Badge GitHub contributors

An open-source example application that allows users to record and upload videos using Mux

View Demo Β· Report a Bug Β· Request Features

Table of Contents

  1. About The Project
  2. Getting Started
  3. Videos to Test in Development

About The Project

Components:

Mux:

  • Direct uploads - this is an API for uploading video files from a client to create Mux Assets
  • Webhook signature verification - webhook signature verification to make sure Mux webhooks are coming from a trusted source
  • HLS.js - for doing HLS video playback of videos
  • Mux Data - for tracking video quality metrics.

Slackbot moderator. This examples allows you to configure a SLACK_WEBHOOK_ASSET_READY. When a new Mux asset is ready, an Incoming Webhook for slack will be sent. This is an example of how you might integrate a Slack channel that can be used to moderate content. The Slack message contains the asset ID, playback ID and a storyboard of thumbnails from the video.

Slackbot message

NextJS:

  • SWR β€” dynamically changing the refreshInterval depending on if the client should be polling for updates or not
  • /pages/api routes β€” a couple endpoints for making authenticated requests to the Mux API.
  • Dynamic routes using getStaticPaths and fallback: true, as well as dynamic API routes.

This app was created with the NextJS with-mux-video example as a starting point.

Getting Started

Step 1. Create an account in Mux

All you need to set this up is a Mux account. You can sign up for free and pricing is pay-as-you-go. There are no upfront charges, you get billed monthly only for what you use.

Without entering a credit card on your Mux account all videos are in β€œtest mode” which means they are watermarked and clipped to 10 seconds. If you enter a credit card all limitations are lifted and you get $20 of free credit. The free credit should be plenty for you to test out and play around with everything before you are charged.

Step 2. Set up environment variables

Copy the .env.local.example file in this directory to .env.local (which will be ignored by Git):

cp .env.local.example .env.local

Then, go to the settings page in your Mux dashboard, get a new API Access Token that allows for "Full Access" against Mux Video and set each variable in .env.local:

  • MUX_TOKEN_ID should be the TOKEN ID of your new token
  • MUX_TOKEN_SECRET should be TOKEN SECRET
  • MUX_WEBHOOK_SIGNATURE_SECRET (optional) - the webhook signing secret if you set up webhooks (see below)
  • SLACK_WEBHOOK_ASSET_READY (optional) - the slack webhook URL that will be used for the Slackbot moderator feature (see below)
  • SLACK_MODERATOR_PASSWORD (optional) - this is the password when you want to take actions from the Slackbot moderator feature (see below)
  • NEXT_PUBLIC_MUX_ENV_KEY (optional) - this is the mux environment key for Mux Data integration

Step 3. Deploy on Vercel

You can deploy this app to the cloud with Vercel (Documentation).

To deploy on Vercel, you need to set the environment variables using Vercel CLI (Documentation).

Install the Vercel CLI, log in to your account from the CLI, and run the following commands to add the environment variables. Replace the values with the corresponding strings in .env.local:

vercel secrets add stream_new_token_id <MUX_TOKEN_ID>
vercel secrets add stream_new_token_secret <MUX_TOKEN_SECRET>

Then push the project to GitHub/GitLab/Bitbucket and import to Vercel to deploy.

Step 4 (optional) Slackbot Moderator

Slackbot message

This application uses a slackbot to send message to a slack channel every time a new asset is ready for playback. This requires a few steps for setup.

First, login to your Mux dashboard and in the left sidebar navigation find Settings > Webhooks. Create a new webhook and makes sure you are creating a webhook for the environment that matches the access token that you are using.

Mux Webhook Create

For local development you may want to use a tool like ngrok to receive webhooks on localhost. The route for the webhook handler is /api/webhooks/mux (defined in this NextJS app under ./pages/api/webhooks/mux).

Create a Slack 'Incoming Webhook'. Configure the channel you want to post to, the icon, etc.

Slack Incoming Webhook

When you're done with this, you should have a slack webhook URL that looks something like https://hooks.slack.com/services/....

Set the optional environment variables either directly in the vercel UI or by updating vercel.json and setting them as secrets for your organization. The optional environment variables are:

  • MUX_WEBHOOK_SIGNATURE_SECRET - This is a security mechanism that checks the webhook signature header when the request hits your server so that your server can verify that the webhook came from Mux. Read more about webhook signature verification. Note that in ./pages/api/webhooks/mux the code will only verify the signature if you have set a signature secret variable, so this step is optional.
  • SLACK_WEBHOOK_ASSET_READY - This is the https://hooks.slack.com/services/.... URL when you created the Slack Incoming Webhook.
  • SLACK_MODERATOR_PASSWORD - This is the password that will be used to authorize deleting assets from the slack moderator (The button with the red text "DELETE (cannot be undone)")
  • NEXT_PUBLIC_MUX_ENV_KEY - This is the env key to use with Mux Data. Note this is different than your API key and this environment key can be found on your environment page in the Mux dashboard
  • TELEMETRY_ENDPOINT - This is an endpoint where instrumented telemetry data is sent. As of this update, the only place we collect/send telemetry data is around upload performance in order to test different configurations of UpChunk, but there may be more in the future.

After all of this is set up the flow will be:

  1. Asset is uploaded
  2. Mux sends a webhook to your server (NextJS API function)
  3. (optional) Your server verifies the webhook signature
  4. If the webhook matches video.asset.ready then your server will post a message to your slack channel that has the Mux Asset ID, the Mux Playback ID, and a thumbnail of the video.

Step 5 (optional) Add automatic content analysis to Slackbot Moderator (Google Vision API)

stream.new can automatically moderate content with the help of Google's Cloud vision API.

Follow these steps to help moderate uploaded content:

  • GOOGLE_APPLICATION_CREDENTIALS - This is a base64 encoded JSON representation of your Google service account credentials. Follow instructions below.
  1. First, you will need to set up a google developer account at cloud.google.com.
  2. Create a project
  3. Create a service account for your project and enable the "Cloud Vision API" for your project

Export a Google Service Account authentication file in JSON format. If you have a file that is like this:

service_account.json

{
  "type": "service_account",
  "project_id": "",
  "private_key_id": "",
  "private_key": "-----BEGIN PRIVATE KEY-----\",
  "client_email": "",
  "client_id": "",
  "auth_uri": "",
  "token_uri": "",
  "auth_provider_x509_cert_url": "",
  "client_x509_cert_url": ""
}

Get the base64 encoded string of this JSON file like so:

cat service-account.json | base64

^ This command will output one long string. This string is what you will use for the ENV var GOOGLE_APPLICATION_CREDENTIALS.

When the Slackbot Moderator message gets posted to slack, it will now include a "Moderation score (Google)" with 2 dimensions:

  • "adult"
  • "suggestive"
  • "violent"

Each dimension will have a score from 1-5. You should interpret these scores in terms of likelihood that the video contains this type of content. This is based on Google Vision's Likelihood score

  • 1: very unlikely
  • 2: unlikely
  • 3: possible
  • 4: likely
  • 5: very likely
Slackbot Moderation Message

Step 6 (optional) Add automatic content analysis to Slackbot Moderator (Hive AI)

stream.new can automatically moderate content with the help of Hive AI.

Follow these steps to help moderate uploaded content:

  • HIVE_AI_KEY - This is a base64 encoded JSON representation of your Google service account credentials. Follow instructions below.
  1. First, you will need to set up an account at thehive.ai.
  2. Create a project
  3. Get the API key for your prject

When the Slackbot Moderator message gets posted to slack, it will now include a section titled "Moderation score (hive)" with 2 dimensions:

  • "adult"
  • "suggestive"

Each dimension will have a score from 0-1 with a precision of 6 decimal places. These numbers come from the "Classification API" that Hive AI provides. Details here.

Slackbot Moderation Message

Hidden playback features via query params:

  • time: will start the video at a specific timestamp in seconds, for example ?time=10 will start at 10 seconds like this
  • color: a hex value without the # character will theme the Mux Player with the primaryColor. It's important to omit the # for example ?color=f97316 like this

Videos to test in development:

When developing, if you make any changes to the video player, make sure it works and looks good with videos of various dimensions:

Horizontal

Vertical

Super vertical

Also be sure to check: Safari, Mobile Safari, Chrome, Firefox because they all behave a little differently.

More Repositories

1

media-chrome

Custom elements (web components) for making audio and video player controls that look great in your website or app.
TypeScript
1,215
star
2

next-video

The easiest way to add video in your Nextjs app.
TypeScript
757
star
3

upchunk

Uploads Chunks! Takes big files, splits them up, then uploads each one with care (and PUT requests).
TypeScript
335
star
4

meet

A meeting app built on Mux Real-Time Video.
TypeScript
278
star
5

elements

Custom elements for working with media in the browser that Just Workβ„’
TypeScript
235
star
6

certificate-expiry-monitor

Utility that exposes the expiry of TLS certificates as Prometheus metrics
Go
160
star
7

mux-node-sdk

Official Mux API wrapper for Node projects, supporting both Mux Data and Mux Video.
TypeScript
152
star
8

video-course-starter-kit

A starter template to help create a video course with Mux + Next.js
TypeScript
131
star
9

player.style

A fresh collection of media player themes for every use case!
HTML
125
star
10

examples

Example playground!
TypeScript
110
star
11

mux-go

Official Mux API wrapper for golang projects, supporting both Mux Data and Mux Video.
Go
89
star
12

webrtc-rebroadcaster

A "simple" webrtc rebroadcaster using FFmpeg
C++
88
star
13

mux-elixir

Official Mux API wrapper for Elixir projects, supporting both Mux Data and Mux Video.
Elixir
77
star
14

chromium_broadcast_demo

A simple demo showing how to use chromium as a WebRTC rendering engine
HTML
67
star
15

hlstools

Tools for analyzing and processing hls streams
C++
65
star
16

mux-ruby

Official Mux API wrapper for ruby projects, supporting both Mux Data and Mux Video.
Ruby
50
star
17

mux-python

Official Mux API wrapper for python projects, supporting both Mux Data and Mux Video.
Python
47
star
18

mux-stats-sdk-avplayer

Mux integration with `AVPlayer` for iOS Native Applications
Objective-C
43
star
19

mux-php

Official Mux API wrapper for PHP projects, supporting both Mux Data and Mux Video.
PHP
38
star
20

hls-video-element

A custom element (web component) for playing HTTP Live Streaming (HLS) videos.
JavaScript
38
star
21

youtube-video-element

A custom element (web component) for the YouTube player.
JavaScript
33
star
22

videojs-mux-kit

JavaScript
33
star
23

vmaf_analyzer

Estimates the average delivered VMAF for hls manifests
Go
32
star
24

example-ios-live-streaming

An example app for live streaming from an iOS device using the Mux live streaming service.
Swift
30
star
25

castable-video

Cast your video element to the big screen with ease!
JavaScript
25
star
26

strapi-plugin-mux-video-uploader

A Strapi plugin for managing uploads to Mux.
TypeScript
23
star
27

example-android-live-streaming

C++
23
star
28

videojs-super-resolution

Super Resolution for Video JS
JavaScript
21
star
29

truckload

Migrate your videos to any supported service
TypeScript
19
star
30

mux-stats-sdk-exoplayer

Monitors an ExoPlayer instance and reports player analytics to Mux Data
Java
19
star
31

mux-stats-sdk-react-native-video

JavaScript
17
star
32

stats-sdk-objc

Mux Stats SDK for iOS and tvOS
Objective-C
16
star
33

media-playlist

A custom element for playing through a set of audio and video elements.
JavaScript
15
star
34

bot-watcher

Example of using headless Chrome to test different aspects of a player
JavaScript
15
star
35

blurhash

Using woltapp/blurhash to make nice placeholders for Mux videos. Works nicely with Mux Player.
TypeScript
14
star
36

media-elements

A collection of HTMLMediaElement compatible elements and add-ons
JavaScript
13
star
37

cli

Command Mux from the command line like a boss.
TypeScript
11
star
38

media-group

πŸ‘―β€β™€οΈ mediagroup / MediaController which can be used to sync and control multiple audio / video elements
TypeScript
11
star
39

media-offset

βœ‚οΈ Configures a media element to lock playback to a defined segment of the media
JavaScript
11
star
40

trivia.dev

IT'S TRIVIA! FOR DEVS! GO!
JavaScript
10
star
41

chromium_livestreamer

Take web pages and turn them into a live streams
Shell
8
star
42

custom-media-element

A custom element for extending the native media elements (<audio> or <video>)
JavaScript
8
star
43

chunked-transfer-demo

Webserver that demonstrates delivery of HLS media with HTTP chunked transfer encoding
Go
7
star
44

custom-video-element

A custom element for extending the native video element.
JavaScript
7
star
45

mux-csharp

C#
7
star
46

hls-subtitles-vexillographer

A simple proxy service which changes subtitles flags in HLS manifests.
Ruby
6
star
47

swift-upload-sdk

Mux's Video Upload SDK for iOS. The Swift equivalent of UpChunk.
Swift
6
star
48

shaka-video-element

A custom element (web component) for Shaka Player.
JavaScript
6
star
49

mux-player-swift

Use Mux Player Swift to stream and monitor video from Mux with AVKit and AVFoundation
Swift
6
star
50

android-upload-sdk

Mux's Video Upload SDK for Android. The Android equivalent of UpChunk.
Kotlin
5
star
51

chromecast-mux

JavaScript
5
star
52

roku-mux

Brightscript
5
star
53

mux-stats-sdk-media3

Mux Data SDK for AndroidX Media3
Kotlin
5
star
54

web-player-framework

JavaScript
5
star
55

mux-studio-demo

TypeScript
4
star
56

jamstack-conf-2020-workshop

JavaScript
4
star
57

next-video-site

TypeScript
4
star
58

mux-stats-google-ima

Swift
4
star
59

mux-protobuf

Mux Protobuf definition files
3
star
60

mux-android-distribution

A Gradle Plugin for distributing android builds, with support for Artifactory
Groovy
3
star
61

mux-player-android

Java
3
star
62

packaging_examples

Samples files packaged by mux
3
star
63

spaces-livekit-broadcast-layouts

TypeScript
3
star
64

mux-stats-sdk-theoplayer-ios

Mux Data Integration for THEOplayer's iOS SDK
Swift
2
star
65

meetup_colorspace_demo

HTML
2
star
66

mux-stats-sdk-theoplayer-android

Java
2
star
67

protogen

Protobuf Specification Generator written in Go
Go
2
star
68

media-tracks

Polyfill audio and video tracks with renditions.
TypeScript
2
star
69

video-archivist

A helpful Github bot that listens for links to videos in new issues, then asks maintainers if they want to archive it so it doesn't ever go away.
TypeScript
2
star
70

mux-java

Java
2
star
71

blurup

Generate a blurry image placeholder for a Mux video.
HTML
2
star
72

nextjs-backend-example

JavaScript
2
star
73

kaper

Kapacitor client written in Elixir.
Elixir
1
star
74

mux-stats-sdk-mediaplayer

Java
1
star
75

stackpath-urlauth

Golang library to sign Stackpath CDN URLs
Go
1
star
76

stats-sdk-exoplayer

Mux Stats SDK for ExoPlayer
Java
1
star
77

media-woofer

Kick up the bass on your media element!
JavaScript
1
star
78

webos-mux

LG WebOS
JavaScript
1
star
79

mux-docs

Docs for Mux SDKs and APIs
1
star
80

mux-delete-all-assets

Python
1
star
81

mipp

mipp - Pixel processing in JavaScript
C++
1
star
82

.github

Mux's shared templates and workflows.
1
star
83

stats-sdk-android

Core library for our Data SDKs for Android
Kotlin
1
star
84

tizen-mux

JavaScript
1
star
85

mux-stats-sdk-kaltura-android

A library for integration Mux Data with the Kaltura Playkit on Android
Java
1
star
86

blur-up-thumbs

HTML
1
star
87

simple-local-video-test-server

Uses a simple static server to host media files (with expected mimetype mappings).
HTML
1
star
88

templates

Repository of useful templates for use with Mux products
1
star
89

mux-stats-sdk-jwplayer-ios

Mux Data Integration for JWPlayer's iOS SDK
Objective-C
1
star