Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Queuing functionality & mp3+aac profile #3

Merged
merged 1 commit into from

2 participants

Taner Topal Sean Caetano Martin
Taner Topal

No description provided.

Sean Caetano Martin xonecas merged commit c5b0260 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 25, 2012
  1. Added queueing functionalty.

    Taner Topal authored
This page is out of date. Refresh to see the latest.
Showing with 84 additions and 15 deletions.
  1. +84 −15 ffmpeg-node.js
99 ffmpeg-node.js
View
@@ -1,11 +1,37 @@
/**
- * Module to drive ffmpeg video enconding library with shortcuts
+ * Module to drive ffmpeg video enconding library with shortcuts
* for web video. Requires a ffmpeg compiled with support for mp4/ogg/webm.
*/
var path = require('path'),
- spawn = require('child_process').spawn;
+ spawn = require('child_process').spawn,
+ that = this,
+ queue = [],
+ maxActive = 5, // Maximum of active FFMpeg jobs
+ active = 0;
+
+
+// The queue is limited to a max. of 5 active ffmpeg processes.
+
+
+function push (job) {
+ queue.push(job);
+ if(active < maxActive) {
+ next();
+ }
+}
+
+function next () {
+ if(queue.length > 0 && active < maxActive) {
+ console.log(queue[0]);
+ that.exec(queue[0].params, queue[0].callback);
+ active++;
+ queue.shift();
+ }
+}
+
+
/**
* Description:
@@ -19,10 +45,11 @@ var path = require('path'),
*/
exports.exec = function (params, callback) {
-
+ console.log(params, callback);
+
if (params instanceof Array && params.length > 2) {
- var stderr = '', stdout = '',
+ var stderr = '', stdout = '',
ffmpeg = spawn('ffmpeg', params);
ffmpeg.stderr.on('data', function (err) {
@@ -35,11 +62,13 @@ exports.exec = function (params, callback) {
ffmpeg.on('exit', function (code) {
callback(stderr, stdout, code);
+ active--;
+ next();
});
}
-}
+};
/**
@@ -48,7 +77,7 @@ exports.exec = function (params, callback) {
* avoid code repetition.
*
* Parameters:
- * type - one of 'mp4', 'ogg', 'webm' as a string.
+ * type - one of 'mp4', 'ogg', 'webm', 'mp3', 'm4a' as a string.
* file - path/to/the/inputFile.ext as a string.
* params - an array of ffmpeg options to be added to the predefined ones (optional).
* output - path/to/the/outputFile.ext as a string (optional).
@@ -56,9 +85,10 @@ exports.exec = function (params, callback) {
* function (stderr, stdout, exitCode) { ... }
*/
+
exports.convert = function (/* overloaded */) {
- var type = arguments[0], file = arguments[1],
+ var type = arguments[0], file = arguments[1],
params = [], output = '', callback = false;
if (arguments.length === 3) {
@@ -105,7 +135,7 @@ exports.convert = function (/* overloaded */) {
'-i', file,
'-acodec', 'libfaac',
'-ab', '128k',
- '-ar', '41000',
+ '-ar', '44100',
'-vcodec', 'libx264',
'-vpre', 'slow',
'-vpre', 'baseline',
@@ -119,7 +149,7 @@ exports.convert = function (/* overloaded */) {
'-i', file,
'-acodec', 'libvorbis',
'-ab', '128k',
- '-ar', '41000',
+ '-ar', '44100',
'-vcodec', 'libtheora',
'-r', '25',
'-y', output
@@ -131,18 +161,39 @@ exports.convert = function (/* overloaded */) {
'-i', file,
'-acodec', 'libvorbis',
'-ab', '128k',
- '-ar', '41000',
+ '-ar', '44100',
'-vcodec', 'libvpx',
'-b', '614400',
'-aspect', '16:9',
'-y', output
].concat(params);
break;
+
+ case 'mp3':
+ params = [
+ '-i', file,
+ '-acodec', 'libmp3lame',
+ '-ab', '128k',
+ '-ar', '44100',
+ '-y', output
+ ].concat(params);
+ break;
+
+ case 'm4a':
+ params = [
+ '-i', file,
+ '-acodec', 'aac',
+ '-ab', '64k',
+ '-ar', '44100',
+ '-y', output
+ ].concat(params);
+ break;
}
- this.exec(params, callback);
+
+ push({params: params, callback: callback});
-}
+};
/**
* Description:
@@ -164,7 +215,7 @@ exports.mp4 = function (/* overloaded */) {
this.convert.apply(this, arguments);
-}
+};
exports.ogg = function (/* overloaded */) {
@@ -173,7 +224,7 @@ exports.ogg = function (/* overloaded */) {
this.convert.apply(this, arguments);
-}
+};
exports.webm = function (/* overloaded */) {
@@ -182,5 +233,23 @@ exports.webm = function (/* overloaded */) {
this.convert.apply(this, arguments);
-}
+};
+
+exports.mp3 = function (/* overloaded */) {
+
+ var unshift = Array.prototype.unshift;
+ unshift.call(arguments, 'mp3');
+
+ this.convert.apply(this, arguments);
+
+};
+
+exports.m4a = function (/* overloaded */) {
+
+ var unshift = Array.prototype.unshift;
+ unshift.call(arguments, 'm4a');
+
+ this.convert.apply(this, arguments);
+
+};
Something went wrong with that request. Please try again.