All Projects → t-mullen → Hls Server

t-mullen / Hls Server

Licence: mit
Middleware for serving HTTP Live Streaming (HLS) compatible media streams.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Hls Server

Nginx Vod Module
NGINX-based MP4 Repackager
Stars: ✭ 1,378 (+843.84%)
Mutual labels:  video-streaming, hls
Python Ffmpeg Video Streaming
📼 Package media content for online streaming(DASH and HLS) using FFmpeg
Stars: ✭ 269 (+84.25%)
Mutual labels:  video-streaming, hls
browserLiveStream
Use webcam, browser and Node to stream live video. From api.video (https://api.video)
Stars: ✭ 141 (-3.42%)
Mutual labels:  hls, video-streaming
shaka-php
🎞 Shaka PHP is a library that uses Shaka Packager for DASH and HLS packaging and encryption, supporting Common Encryption for Widevine and other DRM Systems.
Stars: ✭ 63 (-56.85%)
Mutual labels:  hls, video-streaming
Free Hls Live
Free live streaming with Free-HLS (Free HLS 直播姬)
Stars: ✭ 47 (-67.81%)
Mutual labels:  video-streaming, hls
shaka-player-react
A simple React component wrapper for shaka-player
Stars: ✭ 79 (-45.89%)
Mutual labels:  hls, video-streaming
api.video-go-client
The official Go client library for api.video
Stars: ✭ 16 (-89.04%)
Mutual labels:  hls, video-streaming
Ott Packager
OTT/ABR streaming encoder (H264/HEVC) and packager for DASH and HLS
Stars: ✭ 148 (+1.37%)
Mutual labels:  video-streaming, hls
Shaka Player
JavaScript player library / DASH & HLS client / MSE-EME player
Stars: ✭ 5,386 (+3589.04%)
Mutual labels:  video-streaming, hls
Awesome Video
A curated list of awesome streaming video tools, frameworks, libraries, and learning resources.
Stars: ✭ 397 (+171.92%)
Mutual labels:  video-streaming, hls
Php Ffmpeg Video Streaming
📼 Package media content for online streaming(DASH and HLS) using FFmpeg
Stars: ✭ 246 (+68.49%)
Mutual labels:  video-streaming, hls
Srs
SRS is a simple, high efficiency and realtime video server, supports RTMP, WebRTC, HLS, HTTP-FLV, SRT and GB28181.
Stars: ✭ 16,734 (+11361.64%)
Mutual labels:  hls, video-streaming
Jmuxer
jMuxer - a simple javascript mp4 muxer that works in both browser and node environment.
Stars: ✭ 222 (+52.05%)
Mutual labels:  video-streaming, hls
Docker Streaming Server
Live streaming server
Stars: ✭ 141 (-3.42%)
Mutual labels:  video-streaming, hls
Shaka Player Embedded
Shaka Player in a C++ Framework
Stars: ✭ 153 (+4.79%)
Mutual labels:  video-streaming, hls
RokuKast
A Chrome extension to stream web videos to Roku devices.
Stars: ✭ 63 (-56.85%)
Mutual labels:  hls, video-streaming
Rtsp Stream
Out of box solution for RTSP - HLS live stream transcoding. Makes RTSP easy to play in browsers.
Stars: ✭ 349 (+139.04%)
Mutual labels:  video-streaming, hls
Hls.js
HLS.js is a JavaScript library that plays HLS in browsers with support for MSE.
Stars: ✭ 10,791 (+7291.1%)
Mutual labels:  video-streaming, hls
Vidgear
A High-performance cross-platform Video Processing Python framework powerpacked with unique trailblazing features 🔥
Stars: ✭ 2,048 (+1302.74%)
Mutual labels:  hls, video-streaming
Vime
Customizable, extensible, accessible and framework agnostic media player. Modern alternative to Video.js and Plyr. Supports HTML5, HLS, Dash, YouTube, Vimeo, Dailymotion...
Stars: ✭ 1,928 (+1220.55%)
Mutual labels:  hls

hls-server

JavaScript Style Guide Travis

Simple HTTP middleware for serving HTTP Live Streaming (HLS) compatible media streams.

Usage

First you need a compatible media stream (see Producing Streams).

Fast way:

require('hls-server')(8000)

Detailed way:

var HLSServer = require('hls-server')
var http = require('http')

var server = http.createServer()
var hls = new HLSServer(server, {
  path: '/streams',     // Base URI to output HLS streams
  dir: 'public/videos'  // Directory that input files are stored
})
server.listen(8000)

Producing Streams

HLS can only stream files that have been properly encoded and segmented. FFMPEG is great for this.
Here is how to do it with node-fluent-ffmpeg.

var ffmpeg = require('fluent-ffmpeg')

function callback() { // do something when encoding is done }

// Below is FFMPEG converting MP4 to HLS with reasonable options.
// https://www.ffmpeg.org/ffmpeg-formats.html#hls-2
fmpeg('input.mp4', { timeout: 432000 }).addOptions([
    '-profile:v baseline', // baseline profile (level 3.0) for H264 video codec
    '-level 3.0', 
    '-s 640x360',          // 640px width, 360px height output video dimensions
    '-start_number 0',     // start the first .ts segment at index 0
    '-hls_time 10',        // 10 second segment duration
    '-hls_list_size 0',    // Maxmimum number of playlist entries (0 means all entries/infinite)
    '-f hls'               // HLS format
  ]).output('public/videos/output.m3u8').on('end', callback).run()

To create segments from an existing RTMP stream, use the following node-fluent-ffmpeg command. You can expect several seconds of latency, depending on hardware.

var ffmpeg = require('fluent-ffmpeg')

// host, port and path to the RTMP stream
var host = 'localhost'
var port = '1935'
var path = '/live/test'

function callback() { // do something when stream ends and encoding finshes }

fmpeg('rtmp://'+host+':'+port+path, { timeout: 432000 }).addOptions([
    '-c:v libx264',
    '-c:a aac',
    '-ac 1',
    '-strict -2',
    '-crf 18',
    '-profile:v baseline',
    '-maxrate 400k',
    '-bufsize 1835k',
    '-pix_fmt yuv420p',
    '-hls_time 10',
    '-hls_list_size 6',
    '-hls_wrap 10',
    '-start_number 1'
  ]).output('public/videos/output.m3u8').on('end', callback).run()

Using In-Memory Streams

By default, this module assumes files are kept in a directory on the local filesystem. If you want to stream files from another source (or don't want to relate URL paths to filesystem paths), you can specify a provider in the options like so:

var hls = new HLSServer(server, {
  provider: {
    exists: function (req, callback) { // check if a file exists (always called before the below methods)
      callback(null, true)                 // File exists and is ready to start streaming
      callback(new Error("Server Error!")) // 500 error
      callback(null, false)                // 404 error
    },
    getManifestStream: function (req, callback) { // return the correct .m3u8 file
      // "req" is the http request
      // "callback" must be called with error-first arguments
      callback(null, myNodeStream)
      // or
      callback(new Error("Server error!"), null)
    },
    getSegmentStream: function (req, callback) { // return the correct .ts file
      callback(null, myNodeStream)
    }
  }
})

See src/fsProvider.js for the default provider using the local filesystem.

CLI Tool

This package includes a CLI tool that can be installed globally with npm install -g hls-server.

To use, navigate to the directory where your .ts files are stored and run hlsserver in a command prompt. This will start a server on port 8000. (Use hlsserver --help to see additional options.)

The CLI tool will efficiently make use of multiple processors via the cluster module and can be used as an example of how to use the base module in the same way.

Notes

To publish from an RTMP client like OBS, use a RTMP server like rtmp-server-nodejs to echo the stream (direct streaming from that module is being worked on).

NOTE: Transcoding live streams is very CPU-intensive. Most consumer hardware won't be able to handle transcoding more than a few streams.

Sponsors

Support this project by becoming a sponsor. Your logo will appear here with a link to your website. [Become a sponsor]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].