GithubHelp home page GithubHelp logo

debarshi121 / hls-transcoding-nodejs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from theserverfault/hls-transcoding-nodejs

0.0 0.0 0.0 310 KB

This is a sample example repository to implement video transcoding for buffered bandwidth based streaming videos in Nodejs using Apple HLS + m3u8 to stream over HTTP.

Shell 36.62% JavaScript 57.18% Dockerfile 6.20%

hls-transcoding-nodejs's Introduction

HLS m3u8 streaming in NodeJS with ffmpeg and S3 Hosting

HLS stands for HTTP Live Streaming. It is an HTTP-based adaptive bitrate streaming communications protocol developed by Apple. It allows content to be delivered over HTTP-based CDNs using extended M3U playlists. To learn more about HLS, consider visting Wikipedia.

This is an automated example implementation of HLS in NodeJS using ffmpeg.

Process

Accepting the video file.

Express server accepts the video and save it temporarily on the server. Few checks are made like checking the video format and mime-types. Garbage files are truncated.

Renditions

Server triggers a shell script which handles the video for different renditions by keeping the aspect ratio of the video. The various renditions are:

  • 640x360 resolution with 800k bitrate and 96k audio-birate --> 360p
  • 842x480 resolution with 1400k bitrate and 128k audio-birate --> 480p
  • 1280x720 resolution with 2800k bitrate and 128k audio-birate --> 720p
  • 1920x1080 resolution with 5000k bitrate and 192k audio-birate --> 1080p

Though, these are pretty basic renditions. The renditions are static for now and could be dynamic based on initial video quality.

Segments

The video is divided into 4 seconds segments intervals which will be loaded for each buffering units and the durations must be calculated on mean size of videos being uploaded because it cannot be too small or too large. Too short segment size will lead to too many segments to manage and hence larger buffer lookups. Too large segment size will fail for the smaller videos as they will always be loaded with single segment. The standard option is to have very small segment size for smaller videos. Whereas, the segment size of 4-6 seconds fits for all video types.

Bitrate-Ratio

The bitrate ratio defines the maximum accepted birate fluctuations which is kept to 1.07.

Rate Monitor Buffer Ratio

Maximum buffer size between bitrate conformance checks is set to 1.5 by default.

Generating HLS VOD in ts and m3v8 playlist format

Using ffmpeg to trigger shell command to generate HLS VOD streams for the incoming video. Consider visiting ffmpeg webiste for details about the CMD tools and API.

The logs for shell command are handled via spawn and logged via basic stdout as of now. For production, we can use netcat to communicate messages/status via TCP/UDP connection. We can utilize sockets connects on shell to let applications communicate for logs and statuses so that errors/success messages could be tracked.

Following is the link to netcat cheatsheet: netcat cheatsheet

The script will generate the sequence for video with the following formats. Here, .qt file the uploaded file and rest of the file are different renditions generated for streaming over HTTP. Now, we do not need original file. We just have to upload the Renditions alon with .m3u8 playlist files.

Triggering the webhook for upload to S3

Now in the last step, We will upload all generated renditions to S3. We don't have to upload original file but we can for the backup purpose. Now, the single file playlist.m3u8 will be sufficient to stream the video on any supporting device that support HLS streaming. The most common example are VLC media Player, WMV player, Android player, HTML5 Web player etc.

TODO

  1. Messaging between shell and backend via netcat UDP connections.
  2. Alerts and Upload status management.
  3. Dynamic Renditions based on original video resolutions.
  4. Dynamic segment size, bitrateratio and buffer ratio.
  5. Advanced logging and log tracking.
  6. Advanced error handling and fault taulrance.
  7. Handling for production scaling with load balance test.

Support and Help

Reach out ot me at [email protected]

PRs are welcome.

References

hls-transcoding-nodejs's People

Contributors

ops-gaurav avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.