fluent-ffmpeg / node-fluent-ffmpeg

A fluent API to FFMPEG (http://www.ffmpeg.org)
MIT License
7.64k stars 874 forks source link

"end" event is not being emitted on large videos being streamed to google cloud storage #1156

Open Zelfapp opened 2 years ago

Zelfapp commented 2 years ago

Version information

Code to reproduce

await ffmpeg(tmpFile)
  .withOutputOption('-f mp4')
  // List of presets https://trac.ffmpeg.org/wiki/Encode/H.264
  // The slower, the better the compression.
  .withOutputOption('-preset medium')
  .withOutputOption('-movflags frag_keyframe+empty_moov')
  .withOutputOption('-max_muxing_queue_size 9999')
  // Compressing at typical 23 quality to reduce file sizes with compromising quality.
  .withOutputOption('-crf 23')
  .withVideoCodec('libx264')
  .withAudioCodec('aac')
  .withSize('1280x720')
  .withAspectRatio('16:9')
  .on('start', cmdLine => {
    if (debug) {
      functions.logger.info('Started ffmpeg', cmdLine)
    }
  })
  .on('end', () => {
    if (debug) {
      functions.logger.info('Transcoding succeeded!')
    }
    resolve(true)
  })
  .on('error', (err: Error, stdout, stderr) => {
    if (debug && stdout && stdout !== undefined) {
      functions.logger.error('stdout', stdout)
    }
    if (debug && stderr && stderr !== undefined) {
      functions.logger.error('stderr', stderr)
    }
    reject(Error(err.message))
  })
  .pipe(remoteWriteStream, { end: true })

Expected results

end should be called when the ffmpeg is finished and the video has been piped. I'm using google cloud storage and I can see the transcoded video is fully complete, but end is only called on short videos, not large videos.

Observed results

end is only called on smaller size videos. On larger videos, around 1GB, end is not called so I'm unable to resolve() the promise waiting for fluent-ffmpeg to throw the end event.

Is there something in my code here that I can adjust to make sure 'end' is called if there is no error? start calls just find and no error is emitted, just end is never called on large videos.