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
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.
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.