audioconcat icon indicating copy to clipboard operation
audioconcat copied to clipboard

Concatenating wave files in Cloud Functions environment only produces first file

Open Fleker opened this issue 1 year ago • 2 comments

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 avatar Mar 08 '23 02:03 Fleker

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())
    })
  }

Fleker avatar Mar 08 '23 05:03 Fleker

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

Stephen-Hamilton-C avatar Jul 21 '23 15:07 Stephen-Hamilton-C