Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

express.js streaming issues #494

Open
echo66 opened this issue Jan 27, 2016 · 3 comments
Open

express.js streaming issues #494

echo66 opened this issue Jan 27, 2016 · 3 comments

Comments

@echo66
Copy link

echo66 commented Jan 27, 2016

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

@njoyard
Copy link
Member

njoyard commented Jan 29, 2016

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.

@echo66
Copy link
Author

echo66 commented Jan 29, 2016

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

@njoyard
Copy link
Member

njoyard commented Feb 2, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants