Skip to content

Instantly share code, notes, and snippets.

View irvanherz's full-sized avatar
😀

Muhammad Irvan Hermawan irvanherz

😀
View GitHub Profile
@julianfresco
julianfresco / my.controller.js
Last active March 30, 2023 17:45
Restricted access HLS video streaming with node.js and express.js router
'use strict';
var fs = require('fs');
var config = require('../../config'); // developer-defined configs (Ex: config.video.localPath = "server/storage/")
/** Serves HLS videos to user */
exports.serveHLSVideo = function(req, res){
var appRoot = (__dirname + '/../../../'),
filePath = appRoot + config.video.localPath + req.params[0];
@mharsch
mharsch / gist:5188206
Last active February 8, 2024 02:43
serve HLS (HTTP Live Streaming) content from node.js

HLS streaming from node

Provided that you already have a file or stream segmenter generating your .m3u8 playlist and .ts segment files (such as the ffmpeg 'hls' muxer), this little node server will serve up those files to an HLS compatible client (e.g. Safari). If you're using node for your streaming app already, this obviates the need to serve the HLS stream from a separate web server.

loosely based on https://gist.github.com/bnerd/2011232

// loosely based on https://gist.github.com/bnerd/2011232
// requires node.js >= v0.10.0
// assumes that HLS segmenter filename base is 'out'
// and that the HLS playlist and .ts files are in the current directory