Node-fluent-ffmpeg: express.js streaming issues

Created on 27 Jan 2016  路  3Comments  路  Source: fluent-ffmpeg/node-fluent-ffmpeg

Greetings!

I have the following code to cut remote mp3 files:

var express = require('express');
var ffmpeg = require('fluent-ffmpeg');
var app = express();

app.get ('/', function(req,res) {
  res.writeHead(200, {
    'Content-Type': 'audio/mpeg',
  });
  console.log(req.query.path.replace(/ /g, '%20'));
  ffmpeg(req.query.path.replace(/ /g, '%20'))
      .on('error', function(err) {
            console.log('Processing error! ' + err);
      })
      .format('mp3')
      .audioCodec('copy')
      .seekInput(req.query.start).duration(req.query.duration)
      .pipe(res, {end:true});

 });

var server = app.listen(2000);

The code seems to do the trick but, for remote files (i.e.: not in the server disk), I get the following error:

Processing error! Error: Output stream closed

Won't fix / Not a bug

Most helpful comment

Actually that's more an exception. Whether it qualifies as an error is entirely your interpretation :D
But more seriously, there's no way to distinguish between "legit" stream closes and other actual errors. That's just how ffmpeg reports them.

All 3 comments

The error message is correct, in that this happens when the browser closes the connection.

This is probably because most browsers make _two_ requests for some filetypes: a first one to get a slice of the beginning of the file to determine its format/codec, and then a chunked request to actually stream the file.

According to your description, it is an "error" and not an error. Am I correct? :P

Actually that's more an exception. Whether it qualifies as an error is entirely your interpretation :D
But more seriously, there's no way to distinguish between "legit" stream closes and other actual errors. That's just how ffmpeg reports them.

Was this page helpful?
0 / 5 - 0 ratings