0

I am trying to stream multiple video files in a single request with a node.js application written in coffescript. Here is my code:

express = require 'express'

app = express.createServer(
  express.compiler(src: __dirname + '/client', enable: ['coffeescript']),
  #express.static(__dirname + '/client'),
  express.errorHandler dumpExceptions: true, showStack: true
)

app.get('/video/:number', (req, res) ->
  console.log 'sending'
  res.sendfile("sample#{req.params.number}.webm")
)

port = 3000
app.listen port

So far I manage to send a single file and I can point to any video file which name is formatted like sample<number>.webm. My goal is to be able to send all files inside a folder with that same name format but with a single request, meaning that when the users point the browser to http://localhost:3000 for example, videos would be shown as if they were one single video.

Esteban Angee
  • 548
  • 1
  • 7
  • 19

2 Answers2

2

You can't just concatenate WebM files, so you will have to either:

  1. Build one big file by concatenating all the videos,
  2. Run them through a pipeline which concatenates the videos, or
  3. Send a list of video names and sequentially poll the videos in javascript.

I'd pick number 3, it seems simple and bandwidth frugal.

Linus Thiel
  • 38,647
  • 9
  • 109
  • 104
  • The first two options can't really be achieved instantaneously as it's supposed to be done on a get request. Videos concatenation (e.g. with something like `ffmpeg`) would take some decent time, so concatenated videos should be already precached. So basically there's only a third option or an option of creating a quite more complex system of preparing concatenated videos on upload. – Nikita Volkov Apr 03 '12 at 23:26
  • @NikitaVolkov I already tried having a player with playlist support and fetching the playlist with an ajax request but the approach was discarded because videos did not play fluently; it was obvious that there were multiple files which is not the idea. Thanks for your ansmer – Esteban Angee Apr 04 '12 at 02:33
  • @NikitaVolkov: While I would recommend not concatenating the videos, I'm certain you could start an ffmpeg pipeline and start serving the file immediately. Node is pretty good for stuff like that. – Linus Thiel Apr 11 '12 at 11:11
0

Why not zip all the video files on server side and send back a zip archive.. something like this..

Zip archives in node.js

Community
  • 1
  • 1
  • Zipping the files on server side, send them to the client and unzip them would result in extra processing time and larger bandwidth use so it is not a possibility for this particular case. Thanks for your answer – Esteban Angee Apr 04 '12 at 02:39