/web-video-player-hls-go

A simple browser-based streaming video system running HLS.js for the web player & a Go-based web server with HTTP Live Streaming

Primary LanguageGo

Web video player using HLS.js & Go

Forked from the original repo by bosor, who forked a rad tutorial by Rohit Mundra. The original concept demonstrates how to build a browser-based streaming video player using HTTP Live Streaming, using a Go-based web server on the back-end and a web client using the HLS.js library.


This is a simple evolution of my previous repo that deals with managing encoding media files and then serving them over HLS. This repo handles video content and uses a web front-end instead of a third-party to test the output.

Technologies used:


How to run this demo

  • See how to encode MP4 files into HLS segments using ffmpeg. The segments will be served as streaming chunks to the web client instead of forcing the browser to load the entire file all at once before playback, and also keeping the source data from prying eyes.
  • Start the web server using go run main.go or go build -o server main.go and then ./server (or ./server.exe if you're on Windows).
  • Launch http://localhost:8000/ in your browser (the video should auto-play).

Now for added fun, launch Chrome's Developer Tools (Ctrl+Shift+I) and watch the streaming chunks progressively load in the Network tab as your video advances in 10-second segments. COOL!

HLS segments load progressively as your video advances


Dockerize the web app

Run the following command at a terminal to build the system as a Docker image

  • Build the image: docker build -t go-hls-streaming .
  • Run the image: docker run --name go-hls-streaming -d -p 8000:8000 go-hls-streaming
  • Verify the server is running: curl -i localhost:8000/media/1/stream/

TODOs:

  • Adaptive streaming - automatically adjust playback quality levels based on network fidelity
  • Support livestreams - this one's slightly more involved...