{"id":13767115,"url":"https://github.com/t-mullen/hls-server","last_synced_at":"2025-04-07T07:08:44.321Z","repository":{"id":41493429,"uuid":"86136627","full_name":"t-mullen/hls-server","owner":"t-mullen","description":"Middleware for serving HTTP Live Streaming (HLS) compatible media streams. ","archived":false,"fork":false,"pushed_at":"2024-01-10T19:34:15.000Z","size":13734,"stargazers_count":259,"open_issues_count":3,"forks_count":56,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-31T05:06:47.626Z","etag":null,"topics":["hls","hls-live-streaming","video-streaming"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/t-mullen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"t-mullen","patreon":"tmullen"}},"created_at":"2017-03-25T06:10:16.000Z","updated_at":"2025-03-27T14:11:23.000Z","dependencies_parsed_at":"2024-04-09T18:55:19.467Z","dependency_job_id":"f1f51119-4a00-48c0-9bc5-621b4eb46341","html_url":"https://github.com/t-mullen/hls-server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t-mullen%2Fhls-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t-mullen%2Fhls-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t-mullen%2Fhls-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/t-mullen%2Fhls-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/t-mullen","download_url":"https://codeload.github.com/t-mullen/hls-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247608151,"owners_count":20965952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hls","hls-live-streaming","video-streaming"],"created_at":"2024-08-03T16:01:04.836Z","updated_at":"2025-04-07T07:08:44.291Z","avatar_url":"https://github.com/t-mullen.png","language":"JavaScript","funding_links":["https://github.com/sponsors/t-mullen","https://patreon.com/tmullen"],"categories":["HarmonyOS","Infrastructure \u0026 Delivery"],"sub_categories":["Windows Manager","VOD Streaming Servers"],"readme":"# hls-server\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n[![Travis](https://travis-ci.org/t-mullen/hls-server.svg?branch=master)](https://travis-ci.org/t-mullen/hls-server)\n\nSimple HTTP middleware for serving HTTP Live Streaming (HLS) compatible media streams.  \n\n## Usage\nFirst you need a compatible media stream (see [Producing Streams](#producing-streams)).\n\nFast way:\n```javascript\nrequire('hls-server')(8000)\n```\n\nDetailed way:\n```javascript\nvar HLSServer = require('hls-server')\nvar http = require('http')\n\nvar server = http.createServer()\nvar hls = new HLSServer(server, {\n  path: '/streams',     // Base URI to output HLS streams\n  dir: 'public/videos'  // Directory that input files are stored\n})\nserver.listen(8000)\n```\n\n### Producing Streams\nHLS can only stream files that have been properly encoded and segmented. FFMPEG is great for this.  \nHere is how to do it with [node-fluent-ffmpeg](https://github.com/fluent-ffmpeg/node-fluent-ffmpeg).\n\n```javascript\nvar ffmpeg = require('fluent-ffmpeg')\n\nfunction callback() { // do something when encoding is done }\n\n// Below is FFMPEG converting MP4 to HLS with reasonable options.\n// https://www.ffmpeg.org/ffmpeg-formats.html#hls-2\nfmpeg('input.mp4', { timeout: 432000 }).addOptions([\n    '-profile:v baseline', // baseline profile (level 3.0) for H264 video codec\n    '-level 3.0', \n    '-s 640x360',          // 640px width, 360px height output video dimensions\n    '-start_number 0',     // start the first .ts segment at index 0\n    '-hls_time 10',        // 10 second segment duration\n    '-hls_list_size 0',    // Maxmimum number of playlist entries (0 means all entries/infinite)\n    '-f hls'               // HLS format\n  ]).output('public/videos/output.m3u8').on('end', callback).run()\n```\n\nTo create segments from an existing RTMP stream, use the following [node-fluent-ffmpeg](https://github.com/fluent-ffmpeg/node-fluent-ffmpeg) command. You can expect several seconds of latency, depending on hardware.\n\n```javascript\nvar ffmpeg = require('fluent-ffmpeg')\n\n// host, port and path to the RTMP stream\nvar host = 'localhost'\nvar port = '1935'\nvar path = '/live/test'\n\nfunction callback() { // do something when stream ends and encoding finshes }\n\nfmpeg('rtmp://'+host+':'+port+path, { timeout: 432000 }).addOptions([\n    '-c:v libx264',\n    '-c:a aac',\n    '-ac 1',\n    '-strict -2',\n    '-crf 18',\n    '-profile:v baseline',\n    '-maxrate 400k',\n    '-bufsize 1835k',\n    '-pix_fmt yuv420p',\n    '-hls_time 10',\n    '-hls_list_size 6',\n    '-hls_wrap 10',\n    '-start_number 1'\n  ]).output('public/videos/output.m3u8').on('end', callback).run()\n```\n\n## Using In-Memory Streams\nBy 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:\n\n```javascript\nvar hls = new HLSServer(server, {\n  provider: {\n    exists: function (req, callback) { // check if a file exists (always called before the below methods)\n      callback(null, true)                 // File exists and is ready to start streaming\n      callback(new Error(\"Server Error!\")) // 500 error\n      callback(null, false)                // 404 error\n    },\n    getManifestStream: function (req, callback) { // return the correct .m3u8 file\n      // \"req\" is the http request\n      // \"callback\" must be called with error-first arguments\n      callback(null, myNodeStream)\n      // or\n      callback(new Error(\"Server error!\"), null)\n    },\n    getSegmentStream: function (req, callback) { // return the correct .ts file\n      callback(null, myNodeStream)\n    }\n  }\n})\n```\n\nSee `src/fsProvider.js` for the default provider using the local filesystem.\n\n## CLI Tool\n\nThis package includes a CLI tool that can be installed globally with `npm install -g hls-server`.\n\nTo 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.)\n\nThe 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.\n\n## Notes\n\nTo publish from an RTMP client like OBS, use a RTMP server like [rtmp-server-nodejs](https://github.com/RationalCoding/rtmp-server-nodejs) to echo the stream (direct streaming from that module is being worked on).\n\n*NOTE: Transcoding live streams is very CPU-intensive. Most consumer hardware won't be able to handle transcoding more than a few streams.*\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ft-mullen%2Fhls-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ft-mullen%2Fhls-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ft-mullen%2Fhls-server/lists"}