Open EivydasV opened 1 year ago
I can see that there is timeout in node_modules setTimeout(function() { emitEnd(new Error('Output stream closed')); ffmpegProc.kill(); }, 20); });
. I changed timeout to 1000
and now it works, however this solution is not ideal at all, because you need to edit node_modules, which is no no
Ever since I've switched the Docker image from mhart/alpine-node:10
to node:16-alpine
(that probably affects the ffmpeg
version as well), this issue is also present here. Seeing the activity in this project, I've worked around this issue using a temporary file - downloading the file, feeding it to ffmpeg
, and deleting it.
I also got to the same code as you did, but didn't manage to find a proper fix for it. Adding more delay seems like an ugly workaround.
@mariyan-borisov I did the same workaround as you. First upload file to local storage (without using stream as output) and when processing is finished then I start upload to aws s3. I do not like this workaround either it should work with streams, but it does not. Library maintainer also do not care, library last time was updated 5 years ago. I very doubt it that he will fix this issue now. This is basically dead library. Unfortunately I did'n manage to find any replacement for this library :(
I ran into this as well with AWS SDK v3 (AWS SDK v2 does not seem to be affected).
As a workaround, I'm calling the ffmpeg
binary directly (as fluent-ffmpeg appears to be unmaintained), which works for simple cases e.g.:
const { spawn } = require('child_process')
const { Upload } = require('@aws-sdk/lib-storage')
const ffmpeg = spawn('ffmpeg', ['-i', 'input.mp4', 'pipe:1'])
const upload = new Upload({
params: {
Body: ffmpeg.stdout
}
})
I had some luck with telling fluent-ffmepg not to close the output stream and then manually calling .end() on the output stream when the ffmpeg command is ended. Something like:
const outputStream = new PassThrough();
ffmpeg(input)
.noVideo()
.outputFormat('wav')
.output(outputStream, { end: false })
.on('end', () => {
outputStream.end();
})
.run();
const upload = new Upload({
params: {
Body: outputStream
}
})
The terminateTimeout option (PR https://github.com/fluent-ffmpeg/node-fluent-ffmpeg/pull/1292) could solve this issue.
Version information
Code to reproduce
When I run this I am getting
Error: Output stream closed
(fromfluent-ffmpeg
), error occurs afterend
event is emitted. Looks like that Passthrough closes stream before is finished (I am using@aws-sdk/client-s3
)