h2non / audioconcat

Tiny node.js module to concat multiple audio files using ffmpeg
45 stars 12 forks source link

Concatenating wave files in Cloud Functions environment only produces first file #15

Open Fleker opened 1 year ago

Fleker commented 1 year ago

I've been trying to use this library in a Google Cloud Function environment. I had a bunch of wave files stored in Google Cloud Storage and I load them into the tmp directory.

Concat (3) - /tmp/aedfa598.wav,/tmp/acde2b3f.wav,/tmp/752b43db.wav

When I pass the array of three filenames into the audioconcat function, the function does execute as expected. However, the output, which I upload from tmp to Cloud Storage, only seems to handle the first file. The subsequent ones are ignored. The output file is the same size and length of my original file.

I don't know if this is an issue with wave files in particular, with the Cloud Functions environment, or perhaps an outdated library. Could you clarify how I may be able to debug this in greater detail?

async function concatAudio(concats: string[], finalFile: string) {
    return new Promise((res, rej) => {
      console.log(`Concat (${concats.length}) - ${concats.join(',')}`)
      audioconcat(concats).concat(finalFile)
      .on('start', () => { console.log('Starting final concat of', finalFile) })
      .on('error', (err: string) => { rej(err) })
      .on('end', (output: string) => {
        console.log('Finished final concat of', finalFile);
        res(finalFile)
      })
    })
  }

This function logs everything as expected and I do reach the end and the promise resolves. However this finalFile is only the first file I pass in.

Fleker commented 1 year ago

Okay this seems to work if I go use fluent-ffmpeg directly:

  async function concatAudioWithFluent(concats: string[], finalFile: string) {
    return new Promise((res, rej) => {
      console.log(`Concat (${concats.length}) - ${concats.join(',')}`)
      const cmd = ffmpeg()
      concats.forEach(c => cmd.input(c) )
      cmd.on('end', () => {
        res('ok')
      })
      .on('error', (err: any) => {
        console.error(err.message)
        rej(err.message)
      })
      .mergeToFile(finalFile, os.tmpdir())
    })
  }
Stephen-Hamilton-C commented 1 year ago

Having the same issue here. The function you provided works, as long as I use @ffmpeg-installer/ffmpeg and @ffprobe-installer/ffprobe.