Giter Club home page Giter Club logo

livestreaming-js's Introduction

livestreaming-js

A complete system for producing and serving content conforming to the HTTP Live Streaming specification, built on Node.

Note that this project is currently in a prototype stage. In particular, improvements to error handling and testing should be made before using this in any serious capacity. Furthermore, to improve resilience to failure, queues should be used to pass messages between separate processes for each stage in the workflow.

Thanks

Special thanks to Carson McDonald for trailblazing and releasing HTTP Live Video Stream Segmenter and Distributor. Readers are encouraged to evaluate Carson's project, as it is more robust and more configurable than livestreaming-js.

Theory of Operations

The workflow implemented by this system looks (very crudely) like this:

system

In more detail:

Upload Server

Accepts a video file via HTTP POST and saves the file to disk.

Encoder

Encodes the file that was uploaded in the previous phase multiple times, each time at a different bitrate. The encoding is performed using FFmpeg, and a separate MPEG-2 Transport Stream (.ts file extension) is produced for each bitrate. The bitrates of the generated files can be modified by editing the enabled property in profiles.json.

Note that the default encoding options used for this phase produce video in H264 and that the output is optimized for iOS devices. The output can be tweaked by editing the command property in profiles.json.

Also note that FFmpeg will not necessarily work flawlessly with the default command and any arbitrary source video, although source videos that were recorded on the iPhone consistently behave well.

Segmenter

Splits all of the MPEG-2 Transport Streams produced in the previous phase into a series of shorter segments. (Each segment is 5 seconds long, by default, but this is configurable.)

For each input MPEG-2 Transport Stream (one per bitrate), the Segmenter also produces an index file (.m3u8 file extension) that contains a list of all of the .ts segments produced at this phase, and the URL at which each segment can be accessed.

Finally, once all segments have been generated and the index files have been written for each bitrate, a master index file is generated (also with a .m3u8 file extension). This file enables variable bitrate streaming, containing a list of each index file, an indication of the bitrate represented by each index file, and the URL that each index file can be accessed at.

All produced index files comply with the HTTP Live Streaming specification.

Content Server

Serves all of the index files and segment files produced in the previous phase via HTTP GET.

Client

Clients access the Content Server directly, downloading index files and segments over HTTP. It is the client's responsibility to buffer appropriately, to play segments in order without any gaps, and to use heuristics to decide the bitrate of the stream it should be playing back at this given instant (and also, when to switch streams).

Compatible clients (i.e., clients that that implement HTTP Live Streaming) include iOS v3.0+ devices (iPhone, iPod Touch, iPad, etc.), and desktops with QuickTime 10 (included with Mac OS X Snow Leopard).

Pre-requisites

livestreaming-js

Clone this project and initialize/ update the required git submodules:

git clone git://github.com/mjrusso/livestreaming-js.git
git submodule init
git submodule update

Node

This project has been tested against Node version 0.2.1.

To install this specific version of Node:

wget http://nodejs.org/dist/node-v0.2.1.tar.gz
tar xzvf node-v0.2.1.tar.gz
cd node-v0.2.1
./configure
make
make install

FFmpeg

Ensure that the following packages are installed before building FFmpeg:

- faac-devel
- faad2-devel
- lame-devel
- libbz2-dev
- x264-devel

When configuring FFMpeg, use the following flags:

configure --enable-gpl --enable-nonfree --enable-pthreads
          --enable-libfaac --enable-libfaad --enable-libmp3lame
          --enable-libx264

Segmenter

This project includes a stream segmenter, in source form.

Build the segmenter as follows:

cd segmenter/
make
cd ..

Usage

To run the server:

node src/app.js

When a file is uploaded, the processing chain (Encoder + Segmenter) will be immediately kicked off.

Once this processing is complete, and all segments and index files have been generated, the URL of the variable bitrate index file will be returned as the response body of the HTTP upload request.

When this URL is supplied to any compatible client, adaptive bitrate streaming will be performed via HTTP Live Streaming.

Defaults

By default, a server will be started at http://localhost:4444. (To change the defaults, edit the HOST_NAME and PORT variables in src/app.js.)

Assuming the default values:

  • an upload form will be rendered when visiting http://localhost:4444 directly via a browser
  • video uploads will be performed against http://localhost:4444/upload
  • segment files and index files will be served from http://localhost:4444/streams

livestreaming-js's People

Contributors

mjrusso avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

livestreaming-js's Issues

Can't compile segmenter.c in ubuntu 15.10

Output from make:

$ make
gcc -Wall -g segmenter.c -o segmenter -lavformat -lavcodec -lavutil -lbz2 -lm -lz -lfaac -lmp3lame -lx264 -lfaad -lpthread
segmenter.c: In function ‘add_output_stream’:
segmenter.c:28:21: warning: implicit declaration of function ‘av_new_stream’ [-Wimplicit-function-declaration]
output_stream = av_new_stream(output_format_context, 0);
^
segmenter.c:28:19: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
output_stream = av_new_stream(output_format_context, 0);
^
segmenter.c:53:14: error: ‘CODEC_TYPE_AUDIO’ undeclared (first use in this function)
case CODEC_TYPE_AUDIO:
^
segmenter.c:53:14: note: each undeclared identifier is reported only once for each function it appears in
segmenter.c:65:14: error: ‘CODEC_TYPE_VIDEO’ undeclared (first use in this function)
case CODEC_TYPE_VIDEO:
^
segmenter.c: In function ‘main’:
segmenter.c:231:11: warning: implicit declaration of function ‘av_open_input_file’ [-Wimplicit-function-declaration]
ret = av_open_input_file(&ic, input, ifmt, 0, NULL);
^
segmenter.c:237:9: warning: implicit declaration of function ‘av_find_stream_info’ [-Wimplicit-function-declaration]
if (av_find_stream_info(ic) < 0) {
^
segmenter.c:242:12: warning: implicit declaration of function ‘guess_format’ [-Wimplicit-function-declaration]
ofmt = guess_format("mpegts", NULL, NULL);
^
segmenter.c:242:10: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
ofmt = guess_format("mpegts", NULL, NULL);
^
segmenter.c:260:18: error: ‘CODEC_TYPE_VIDEO’ undeclared (first use in this function)
case CODEC_TYPE_VIDEO:
^
segmenter.c:265:18: error: ‘CODEC_TYPE_AUDIO’ undeclared (first use in this function)
case CODEC_TYPE_AUDIO:
^
segmenter.c:276:9: warning: implicit declaration of function ‘av_set_parameters’ [-Wimplicit-function-declaration]
if (av_set_parameters(oc, NULL) < 0) {
^
segmenter.c:281:5: warning: implicit declaration of function ‘dump_format’ [-Wimplicit-function-declaration]
dump_format(oc, 0, output_prefix, 1);
^
segmenter.c:288:9: warning: implicit declaration of function ‘avcodec_open’ [-Wimplicit-function-declaration]
if (avcodec_open(video_st->codec, codec) < 0) {
^
segmenter.c:293:9: warning: implicit declaration of function ‘url_fopen’ [-Wimplicit-function-declaration]
if (url_fopen(&oc->pb, output_filename, URL_WRONLY) < 0) {
^
segmenter.c:293:45: error: ‘URL_WRONLY’ undeclared (first use in this function)
if (url_fopen(&oc->pb, output_filename, URL_WRONLY) < 0) {
^
segmenter.c:298:9: warning: implicit declaration of function ‘av_write_header’ [-Wimplicit-function-declaration]
if (av_write_header(oc)) {
^
segmenter.c:320:67: error: ‘PKT_FLAG_KEY’ undeclared (first use in this function)
if (packet.stream_index == video_index && (packet.flags & PKT_FLAG_KEY)) {
^
segmenter.c:321:13: warning: ‘pts’ is deprecated [-Wdeprecated-declarations]
segment_time = (double)video_st->pts.val * video_st->time_base.num / video_st->time_base.den;
^
In file included from segmenter.c:21:0:
/usr/include/x86_64-linux-gnu/libavformat/avformat.h:873:19: note: declared here
struct AVFrac pts;
^
segmenter.c:324:13: warning: ‘pts’ is deprecated [-Wdeprecated-declarations]
segment_time = (double)audio_st->pts.val * audio_st->time_base.num / audio_st->time_base.den;
^
In file included from segmenter.c:21:0:
/usr/include/x86_64-linux-gnu/libavformat/avformat.h:873:19: note: declared here
struct AVFrac pts;
^
segmenter.c:331:13: warning: implicit declaration of function ‘put_flush_packet’ [-Wimplicit-function-declaration]
put_flush_packet(oc->pb);
^
segmenter.c:332:13: warning: implicit declaration of function ‘url_fclose’ [-Wimplicit-function-declaration]
url_fclose(oc->pb);
^
Makefile:2: recipe for target 'all' failed
make: *** [all] Error 1

I previously installed libavutil-dev:amd64 (7:2.7.6-0ubuntu0.15.10.1)

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.