Permalink
Browse files

Inital commit...

  • Loading branch information...
1 parent 3fb5be4 commit 67aa5d853b013808d01a3354d72352fc7aa4b72a @TooTallNate committed Jan 26, 2011
Showing with 70 additions and 0 deletions.
  1. +10 −0 convertAndSegment.sh
  2. +48 −0 live-streaming.js
  3. +12 −0 package.json
View
@@ -0,0 +1,10 @@
+#!/usr/bin/env sh
+
+ffmpeg \
+ -f s16le -acodec pcm_s16le -ac 2 -ar 44100 -i - \
+ -f mpegts -acodec libmp3lame -ab "$1k" -ar 32000 -flags +loop+mv4 -cmp 256 \
+ -partitions +parti4x4+partp8x8+partb8x8 -subq 7 -trellis 1 -refs 5 -coder 0 \
+ -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt "$1k" \
+ -maxrate "$1k" -bufsize "$1k" -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 \
+ -level 30 -g 45 -async 2 - 2>/dev/null | \
+~/segmenter/segmenter - 10 "$1k" "$1k.m3u8" "" 5
View
@@ -0,0 +1,48 @@
+var fs = require('fs');
+var spawn = require('child_process').spawn;
+
+// Stdin is expecting raw PCM data of the format:
+var SAMPLE_SIZE = 16; // 16-bit samples, Little-Endian, Signed
+var CHANNELS = 2; // 2 channels (left and right)
+var SAMPLE_RATE = 44100;// 44,100 Hz sample rate.
+
+// If we're getting raw PCM data as expected, calculate the number of bytes
+// that need to be read for `1 Second` of audio data.
+var BLOCK_ALIGN = SAMPLE_SIZE / 8 * CHANNELS; // Number of 'Bytes per Sample'
+var BYTES_PER_SECOND = SAMPLE_RATE * BLOCK_ALIGN;
+
+// Each TS segment will be 10 seconds long
+var SEGMENT_LENGTH = 10; // in seconds
+var BYTES_PER_TEN_SECONDS = BYTES_PER_SECOND * SEGMENT_LENGTH;
+
+var SegmenterOnNewSegment = /segmenter: ([^,]+), ([^,]+)/;
+
+module.exports = function(config) {
+
+ var staticProvider = require('connect').staticProvider(config.mountPoint);
+ var currentSegment = 0;
+
+ var encoder = spawn(__dirname + "/convertAndSegment.sh", [
+ config.bitrate
+ ], {
+ cwd: config.streamDir,
+ customFds: [-1, process.stdout.fd, process.stdout.fd ]
+ });
+
+ config.pcmStream.on('data', function onData(chunk) {
+ encoder.stdin.write(chunk);
+ });
+
+ // The stack/connect handler. Should take care of serving the static TS and m3u8 files...
+ return function(req, res, next) {
+ next();
+ }
+}
+
+function pad(num, length) {
+ var str = String(num);
+ while(str.length < length) {
+ str = '0' + str;
+ }
+ return str;
+}
View
@@ -0,0 +1,12 @@
+{
+ "name": "live-streaming",
+ "description": "HTTP Live Streaming, connect\/stack layer.",
+ "version": "0.0.1",
+ "author": "Nathan Rajlich <nathan@tootallnate.net>",
+ "keywords": ["http", "live", "streaming", "apple", "iPhone", "iOS"],
+ "main": "./live-streaming.js",
+ "scripts": {
+ "preinstall": "make --directory=segmenter"
+ },
+ "engines": { "node": ">= 0.3.0" }
+}

0 comments on commit 67aa5d8

Please sign in to comment.