Giter Club home page Giter Club logo

audioconcat's Introduction

audioconcat Build Status NPM

Tiny node.js module to concat multiple audio files using ffmpeg

audioconcat provides a programmatic interface to do basically the same as calling ffmpeg via CLI like:

ffmpeg -i "concat:audio1.mp3|audio2.mp3" -acodec copy out.mp3

Requirements

  • ffmpeg with additional compilation flags --enable-libmp3lame

You can download static builds of ffmpeg from here.

If you want to use audioconcat in Heroku, you could use the ffmpeg2 buildpack

Install

npm install audioconcat

Usage

var audioconcat = require('audioconcat')

var songs = [
  'beatles.mp3',
  'greenday.mp3',
  'u2.mp3'
]

audioconcat(songs)
  .concat('all.mp3')
  .on('start', function (command) {
    console.log('ffmpeg process started:', command)
  })
  .on('error', function (err, stdout, stderr) {
    console.error('Error:', err)
    console.error('ffmpeg stderr:', stderr)
  })
  .on('end', function (output) {
    console.error('Audio created in:', output)
  })

Take a look to the programmatic API for more details

API

audioconcat(images, [ options ])

Return: audioconcat

audioconcat constructor. You should pass an array<string> with the desired audio files, and optionally passing the video render options object per each image.

Supported audio formats: mp3, acc, ogg (based on your ffmpeg compilation)

audioconcat#concat(output)

Concat files and generate the output audio to the given file path.

audioconcat#options(options)

Add custom options to ffmpeg

audioconcat.VERSION

Type: string

Current package semantic version

audioconcat.ffmpeg

Type: function

fluent-ffmpeg API constructor

License

MIT © Tomas Aparicio

audioconcat's People

Contributors

h2non avatar jbredice avatar mrboombastic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

audioconcat's Issues

Concatenating wave files in Cloud Functions environment only produces first file

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.

Cancat same file to create loop

I've been working on an Electron project and am using fluent-ffmpeg. I need to be able to create an output file that is x number of copies of a loop file. I'm able to accomplish what I need in the Mac version but Windows is killing me. Searching for an alternative way to tap into ffmpeg to accomplish this in Windows.

I was hoping I could do something like this...

ffmpeg -i "concat:audio-1.mp3|audio-1.mp3" -acodec copy out.mp3

... and let it concat the input file on to itself. On the command line it results in the original file length so it's ignoring anything that refers back to itself. Is there a way using audioconcat to accomplish this?

What I'm currently doing using fluent-ffmpeg is:

// variables declared earlier in the script
proc.videoFilter('-lavfi');
if(process.platform == 'win32') {
  proc.videoFilter(`amovie=${audioFile}:aloop=${data.numLoops}`);
} else {
  proc.addOption('-filter_complex', `amovie=${data.filepath}:loop=${data.numLoops}`);
}

Like I said, it works on Mac but not in Windows. It doesn't throw an error, just copies the input file to the output file. Using...

proc.addOption('-filter_complex', `amovie=${data.filepath}:loop=${data.numLoops}`);

...causes an error in Windows.

error when attempting concat

I received the following error when trying to concat 2 files:
Input #0, matroska,webm, from 'concat:60b87d7632e1c624fcd09ce1.mp3|60b87d7932e1c624fcd09ce3.mp3':
Metadata:
encoder : Chrome
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0(eng): Audio: opus, 48000 Hz, mono, fltp (default)
[mp3 @ 0000025dbb9f5780] Invalid audio stream. Exactly one MP3 audio stream is required.
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Last message repeated 1 times

TypeError: audioconcat(...).output is not a function

Hi @h2non , the example in the docs seems to contain errors.

var videoshow = require('audioconcat')

var songs = [
  'beatles.mp3',
  'greenday.mp3',
  'u2.mp3'
]

audioconcat(songs)
  .output('all.mp3')
  .on('start', function (command) {
    console.log('ffmpeg process started:', command)
  })
  .on('error', function (err, stdout, stderr) {
    console.error('Error:', err)
    console.error('ffmpeg stderr:', stderr)
  })
  .on('end', function (output) {
    console.error('Audio created in:', output)
  });
  1. audioconcat is undefined - I think this is just a typo on the first line.
  2. the method output is not available, when I took a look at the code I noticed that the output is checked for in the options.

Is there any limit on number of files?

Hi. Is there any limit on number of files being combined?
I usually get E2BIG error when combining 100 files using SOX and I am looking to combine thousands of audio files in one go. Appreciate your help.

Make new npm release to fix npm audit severity vulnerabilities

Hi,
the currently released version of [email protected] on npm uses lodash.merge@^3.0.0, which is marked by npm audit as possible high security risk. I have seen, you already updated the package.json with the new version of lodash.merge, which is fine with npm audit.
It would be nice, if you could release a new version of audioconcat, to get rid of this warning.

Thank you in advance!

Concat cutting audio length

I have 2 audio files: audio1.ogg and audio2.ogg and then I run

audioconcat(songArr)
    .concat(storyName + '.ogg')
    .on('start', function (command) {
      console.log('ffmpeg process started:', command)
    })
    .on('error', function (err, stdout, stderr) {
      console.error('Error:', err)
      console.error('ffmpeg stderr:', stderr)
      res.send({message: "Error"});
    })
    .on('end', function (output) {
      console.error('Audio created in:', output)
      makeVid(body, res);
    })

songArr has both audios in there and in the log I can see

ffmpeg process started: ffmpeg -i concat:audio1.ogg|audio2.ogg -y -acodec copy storyName.ogg

However when I play the finished audio, the second audio has been cut in half from about 16 seconds to just 8.

audioconcat version: ^0.1.3
node version: 6.10.2
npm version: 3.10.10
ffmpeg version 3.4.1

ffmpeg invalid audio stream

this is my code :
` var audioconcat = require("audioconcat");

var songs = ["mp3/0.mp3", "mp3/1.mp3", "mp3/2.mp3"];

audioconcat(songs)
.concat("all.mp3")
.on("start", function (command) {
console.log("ffmpeg process started:", command);
})
.on("error", function (err, stdout, stderr) {
console.error("Error:", err);
console.error("ffmpeg stderr:", stderr);
})
.on("end", function (output) {
console.error("Audio created in:", output);
}); this is the error: ffmpeg stderr: ffmpeg version N-100082-g81503ac58a Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 9.3-win32 (GCC) 20200320
configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --disable-w32threads --enable-pthreads --enable-iconv --enable-zlib --enable-libxml2 --enable-libfreetype --enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-opencl --enable-libvmaf --disable-vulkan --enable-libvorbis --enable-amf --enable-libaom --enable-avisynth --enable-libdav1d --enable-libdavs2 --enable-ffnvcodec --enable-cuda-llvm --disable-libglslang --enable-libass --enable-libbluray --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvpx --enable-libwebp --enable-libmfx --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librav1e --enable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --enable-libvidstab --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-libs=-lgomp
libavutil 56. 61.100 / 56. 61.100
libavcodec 58.114.100 / 58.114.100
libavformat 58. 64.100 / 58. 64.100
libavdevice 58. 11.103 / 58. 11.103
libavfilter 7. 91.100 / 7. 91.100
libswscale 5. 8.100 / 5. 8.100
libswresample 3. 8.100 / 3. 8.100
libpostproc 55. 8.100 / 55. 8.100
Guessed Channel Layout for Input Stream #0.0 : mono
Input #0, wav, from 'concat:0.mp3|mp3/1.mp3|mp3/2.mp3':
Duration: 00:00:04.87, bitrate: 835 kb/s
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 22050 Hz, mono, s16, 352 kb/s
[mp3 @ 00000258a936be00] Invalid audio stream. Exactly one MP3 audio stream is required.
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:0 --
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Last message repeated 1 times i already changed mp3/0.mp3 to -> ./mp3/0.mp3 and /mp3/0.mp3 . I also moved the file and tried 0.mp3 `. Still the same error.
thx for any help

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.