From 63998d515a06b403f2212f338d1c87a07815539a Mon Sep 17 00:00:00 2001 From: Tomas Aparicio Date: Sun, 14 Jun 2015 21:24:15 +0100 Subject: [PATCH] feat: add files --- .editorconfig | 20 +++++++++++++ .gitignore | 4 +++ .travis.yml | 5 ++++ README.md | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ index.js | 38 +++++++++++++++++++++++++ package.json | 34 ++++++++++++++++++++++ 6 files changed, 180 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 README.md create mode 100644 index.js create mode 100644 package.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..69e01bc --- /dev/null +++ b/.editorconfig @@ -0,0 +1,20 @@ +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +end_of_line = lf +trim_trailing_whitespace = true +insert_final_newline = true + +[Makefile] +charset = utf-8 +indent_style = tabs +indent_size = 2 +end_of_line = lf +trim_trailing_whitespace = true +insert_final_newline = true + +[*.sh] +insert_final_newline = false diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4941b5e --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules +.DS_Store +npm-debug.log +test/.tmp diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..61094f0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: node_js +node_js: + - "0.10" + - "0.12" +script: npm test diff --git a/README.md b/README.md new file mode 100644 index 0000000..fdf366e --- /dev/null +++ b/README.md @@ -0,0 +1,79 @@ +# audioconcat [![Build Status](https://api.travis-ci.org/h2non/audioconcat.svg?branch=master)][travis] [![Code Climate](https://codeclimate.com/github/h2non/audioconcat/badges/gpa.svg)](https://codeclimate.com/github/h2non/audioconcat) [![NPM](https://img.shields.io/npm/v/audioconcat.svg)][npm] [![Dependency Status](https://gemnasium.com/h2non/audioconcat.svg)][gemnasium] + +Tiny [node.js](http://nodejs.org) module to concat multiple audio files using ffmpeg + +## Requirements + +- **[ffmpeg](http://ffmpeg.org)** with additional compilation flags `--enable-libass --enable-libmp3lame` + +You can download static builds of ffmpeg from [here](http://johnvansickle.com/ffmpeg/). + +If you want to use `audioconcat` in Heroku, you could use the [ffmpeg2](https://github.com/h2non/heroku-buildpack-ffmpeg2) buildpack + +## Install + +```bash +npm install audioconcat +``` + +## Usage + +```js +var videoshow = require('audioconcat') + +var songs = [ + 'beatles.mp3', + 'greenday.mp3', + 'u2.mp3' +] + +audioconcat(songs) + .save('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](#api) for more details + +## API + +### audioconcat(images, [ options ]) +Return: `audioconcat` + +audioconcat constructor. You should pass an `array` 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#options(arguments) + +Add multiple output options as command-line flags to pass to `ffmpeg`. +The argument must be an `array` + +### audioconcat.VERSION +Type: `string` + +Current package semantic version + +### audioconcat.ffmpeg +Type: `function` + +[fluent-ffmpeg](https://github.com/fluent-ffmpeg/node-fluent-ffmpeg) API constructor + +## License + +[MIT](http://opensource.org/licenses/MIT) © Tomas Aparicio + +[travis]: http://travis-ci.org/h2non/audioconcat +[gemnasium]: https://gemnasium.com/h2non/audioconcat +[npm]: http://npmjs.org/package/audioconcat +[ffmpeg-api]: https://github.com/fluent-ffmpeg/node-fluent-ffmpeg#creating-an-ffmpeg-command +[ffmpeg-colors]: https://www.ffmpeg.org/ffmpeg-utils.html#Color diff --git a/index.js b/index.js new file mode 100644 index 0000000..888cc81 --- /dev/null +++ b/index.js @@ -0,0 +1,38 @@ +var merge = require('lodash.merge') +var ffmpeg = require('fluent-ffmpeg') + +module.exports = function audioconcat(inputs, opts) { + return new Audioconcat(inputs, opts) +} + +function Audioconcat(inputs) { + this.inputs = inputs || [] + this.opts = opts || {} +} + +Audioconcat.prototype.options = function (opts) { + merge(this.opts, opts) + return this +} + +Audioconcat.prototype.concat = function (file) { + if (file) { + this.opts.output = file + } + return concat(this.inputs, this.opts) +} + +function concat(inputs, opts) { + var first = inputs.slice(0, 1).shift() + var output = this.opts.output + var filter = 'concat:' + inputs.join('|') + + var renderer = ffmpeg(first) + .filter(filer) + + if (opts.output) { + renderer.save(opts.output) + } + + return renderer +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..c9d21d4 --- /dev/null +++ b/package.json @@ -0,0 +1,34 @@ +{ + "name": "audioconcat", + "version": "0.1.0", + "description": "Concat multiple audio files into a unique one (uses ffmpeg)", + "repository": "h2non/audioconcat", + "author": "Tomas Aparicio", + "license": "MIT", + "main": "lib", + "directories": { + "lib": "./lib" + }, + "scripts": { + "test": "./node_modules/.bin/mocha" + }, + "keywords": [ + "audio", + "mp3", + "acc", + "join", + "concat", + "merge", + "song", + "ffmpeg" + ], + "dependencies": { + "fluent-ffmpeg": "^2.0.0", + "lodash.merge": "^3.0.0" + }, + "devDependencies": { + "chai": "^1.10.0", + "mocha": "^2.0.1", + "rimraf": "^2.2.8" + } +}