Error: Output stream closed when trying to stream to express server using ffmpeg

Viewed 259

I'm getting to stream ytdl audio to my express server using ffmpeg but I'm always getting "Output stream closed"

there's my code

const express = require('express')
const ffmpeg = require('fluent-ffmpeg')
const ytdl = require('ytdl-core')

const app = express()

app.set('/:id', async (req, res) => {
    res.set('Content-Type', 'audio/mp3')

    ffmpeg(await ytdl(req.params.id, { format: 'audioonly', quality: 'highestaudio' }))
        .toFormat('mp3')
        .pipe(res, { end: true })
})
1 Answers

In my case, I had the timeout problem:

    Error: Output stream closed
    at Timeout._onTimeout (C:\MYPATH\node_modules\fluent-ffmpeg\lib\processor.js:491:25)

I accessed the fluent-ffmpeg processor.js file and the following function appeared:

    setTimeout(function() {
      emitEnd(new Error('Output stream closed'));
      ffmpegProc.kill();
    }, 20);

I commented out the whole function. I don't know if it's the best solution, but it worked great for me.

Related