Video streaming with ffmpeg and videojs

Written by

In this tutorial, we will set up an RTMP server and stream a movie trailer locally using ffmpeg to stream an MP4 file. Then, we will use VLC to connect to the stream and watch the trailer.

Prerequisites:

Run the RTMP server locally

docker pull alfg/nginx-rtmp
docker run -it -p 1935:1935 -p 8080:80 --rm alfg/nginx-rtmp

References:

Send video stream to RTMP server to tmp://127.0.0.1:1935/stream/<anything>

# Send data to streaming server
ffmpeg -re -i video.mp4 -r 30 -c:v libx264 -x264-params keyint=60:scenecut=0 -preset fast -b:v 5M -maxrate 6M -bufsize 3M -threads 4 -f flv rtmp://127.0.0.1:1935/stream/app

Test the stream with VLC Media Player

File -> Open network and paste this url rtmp://127.0.0.1:1935/stream/app

During my research, I discovered that RTMP cannot be read directly from HTML. For that reason, we need to use HLS to read the stream from html. HLS stands for HTTP Live Streaming.

You can access an example page directly from this link http://localhost:8080/players/hls_hlsjs.html