How To Serve Large Files With Node.js

Here we go: Simple HTTP Server built with node.js to serve/ stream large files.

var libpath = require('path');
var http = require('http');
var fs = require('fs');
var url = require('url');
var bind_port = 8001;
var path = "/path/to/your/base_directory/";
 
http.createServer(function (request, response) {
 var uri = url.parse(request.url).pathname;
 var filename = libpath.join(path, uri);
 
 libpath.exists(filename, function (exists) {
 if (!exists) {
   console.log('404 File Not Found: ' + filename);
   response.writeHead(404, {
     "Content-Type": "text/plain"
   });
   response.write("404 Not Found\n");
   response.end();
   return;
 } else{
   console.log('Starting download: ' + filename);
   var stream = fs.createReadStream(filename, { bufferSize: 64 * 1024 });
   stream.pipe(response);
  }
 });
 
}).listen(bind_port);
console.log('Download Server listening on Port' + bind_port);
view raw index.js This Gist brought to you by GitHub.

Try it

node index.js
wget http://{your-server}/foobar.file

This assumes that you have a file called foobar.file in /path/to/your/base_directory/

Set up a live stream and support thousands of users with Wowza – The Basics

Honestly, a single Server setup is fine for most live streaming use cases. For instance, if you use Wowza’s prebuild AMIs you can expect to get 150 Mbs, 250 Mbs and 350 Mbs out of a an EC2 server instance (small, large or xlarge). This should give you enough cpu, ram and most important bandwidth to serve roughly 150, 250 or 350 concurrent clients (1 stream at apx. 800Kbits).

But what if you need to support more clients? With Wowza and EC2 it’s really easy to set up a live video streaming event for thousands and thousands of users.

Continue reading

1. Live Video Starchat für Musical Freunde mit Tetje Mierendorf

Wie bereits angekündigt ging letzte Woche der erste Musical Freunde Starchat auf Sendung für welchen wir ein entsprechendes Video Modul auf Basis des Wowza Media Servers, Ruby on Rails sowie Flash entwickelt haben. Die Sendung wurde serverseitig mitgeschnitten und ist seit heute auch auf Musical Freunde zu sehen.

Continue reading

A Journey for Water – Von Hamburg nach Indien

Der Schweizer, Sören Wolf, läuft ab dem 1. April über 8000 Kilometer von Hamburg nach Inden für sauberes Trinkwasser: Viva con Aqua!

Alle Spenden, die er sammelt, fließen nach Mosambik und Indien, in die von Viva con Agua unterstützten Wasserprojekte von Helvetas und der Welthungerhilfe. Zudem will Sören die von Viva con Agua unterstützten Trinkwasserprojekte besuchen und arbeitet unterwegs im Rahmen des WWOOOF-Programms. Die Reise finanziert er selbst. Continue reading

Wir freuen uns die Pano GmbH mit neuem Internetauftritt begrüßen zu dürfen

Wir freuen uns den neuen Firmenauftritt der Pano GmbH in Itzehoe realisiert zu haben. Das Layout für die neuen Seiten kommt von Wolfgang Gilde (strategie/ design/ kommunikation); wir übernahmen dabei die technische Realisierung. Im Frühling 2011 hatten wir bereits einen kurzen Messefilm aus Produktfotos erfolgreich produziert.


Continue reading

Simplify NetConnection through Firewalls

Due to security issues some firewalls restrict traffic through non-standard ports. By default Wowza Media Server binds to port 1935. You can easily setup additional ports by editing Vhost.conf in your installation configuration directory. I usually set up port 80, 443 and 1935. Be sure that no other services bind to these ports already.

[…]
<HostPort>
 <ProcessorCount>4</ProcessorCount>
 <IpAddress>*</IpAddress>
 <!-- Separate multiple ports with commas -->
 <!-- 80: HTTP, RTMPT -->
 <!-- 554: RTSP -->
 <Port>1935,443,80</Port>
</HostPort> 
[…]

NetConnectionSmart is a NetConnection replacement for Flash which simplifies connecting to Wowza by trying different ports.

Publish Video as Live Stream to Wowza with ffmpeg

It’s pretty easy to stream a video to Wowza Media Server via the RTMP protocol:

$~ ffmpeg -i bunny.mp4 -re -acodec copy -vcodec copy -f flv rtmp://localhost/live/myStream

That’s it. Adjust encoding settings according to your needs. FFmpeg currently only supports streaming via rtmp within a flv container. Here’s some sample code to play this live stream with Flash Player or Adobe Air.

package{
 
  import flash.display.Sprite;
  import flash.events.NetStatusEvent;
  import flash.media.Video;
 
  import flash.net.NetConnection;
  import flash.net.NetStream;
  import flash.events.Event;
 
  [SWF(backgroundColor="0x000000", width="640", height="360")]
  public class BasicVideoPlayer extends Sprite{
 
    private var _nc:NetConnection;
    private var _ns:NetStream;
    private var _video:Video;
    private var _container:Sprite;
 
    public var streamingApp:String = "rtmp://localhost/live";
    public var playPath:String = "myStream";
 
    public function BasicVideoPlayer(){
      init();
    }
 
    private function init():void{
      _nc = new NetConnection();
      _nc.client = this;
      _nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
      _nc.connect(streamingApp);
 
      _video = new Video(640,360);
      _video.smoothing = true;
      _container = new Sprite();
      addChild(_container);
      _container.addChild(_video);
 
    }
 
    private function connectStream():void{
      _ns = new NetStream(_nc);
      _ns.play(playPath, -1);
      _ns.bufferTime = 1;
      _video.attachNetStream(_ns);
    }
 
    /* NetStatus Handling */
    private function netStatusHandler(e:NetStatusEvent):void{
      trace(e.info.code);
      switch (e.info.code){
        case "NetConnection.Connect.Success":
          connectStream();
          break;
        case "NetStream.Play.StreamNotFound":
          trace("Stream not found: ");
          break;
      }
    }
 
  }
}