|
|
|
'use strict'; |
|
|
|
var path = require('path'); |
|
var util = require('util'); |
|
var EventEmitter = require('events').EventEmitter; |
|
|
|
var utils = require('./utils'); |
|
var ARGLISTS = ['_global', '_audio', '_audioFilters', '_video', '_videoFilters', '_sizeFilters', '_complexFilters']; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function FfmpegCommand(input, options) { |
|
|
|
if (!(this instanceof FfmpegCommand)) { |
|
return new FfmpegCommand(input, options); |
|
} |
|
|
|
EventEmitter.call(this); |
|
|
|
if (typeof input === 'object' && !('readable' in input)) { |
|
|
|
options = input; |
|
} else { |
|
|
|
options = options || {}; |
|
options.source = input; |
|
} |
|
|
|
|
|
this._inputs = []; |
|
if (options.source) { |
|
this.input(options.source); |
|
} |
|
|
|
|
|
this._outputs = []; |
|
this.output(); |
|
|
|
|
|
var self = this; |
|
['_global', '_complexFilters'].forEach(function(prop) { |
|
self[prop] = utils.args(); |
|
}); |
|
|
|
|
|
options.stdoutLines = 'stdoutLines' in options ? options.stdoutLines : 100; |
|
options.presets = options.presets || options.preset || path.join(__dirname, 'presets'); |
|
options.niceness = options.niceness || options.priority || 0; |
|
|
|
|
|
this.options = options; |
|
|
|
|
|
this.logger = options.logger || { |
|
debug: function() {}, |
|
info: function() {}, |
|
warn: function() {}, |
|
error: function() {} |
|
}; |
|
} |
|
util.inherits(FfmpegCommand, EventEmitter); |
|
module.exports = FfmpegCommand; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FfmpegCommand.prototype.clone = function() { |
|
var clone = new FfmpegCommand(); |
|
var self = this; |
|
|
|
|
|
clone.options = this.options; |
|
clone.logger = this.logger; |
|
|
|
|
|
clone._inputs = this._inputs.map(function(input) { |
|
return { |
|
source: input.source, |
|
options: input.options.clone() |
|
}; |
|
}); |
|
|
|
|
|
if ('target' in this._outputs[0]) { |
|
|
|
clone._outputs = []; |
|
clone.output(); |
|
} else { |
|
|
|
clone._outputs = [ |
|
clone._currentOutput = { |
|
flags: {} |
|
} |
|
]; |
|
|
|
['audio', 'audioFilters', 'video', 'videoFilters', 'sizeFilters', 'options'].forEach(function(key) { |
|
clone._currentOutput[key] = self._currentOutput[key].clone(); |
|
}); |
|
|
|
if (this._currentOutput.sizeData) { |
|
clone._currentOutput.sizeData = {}; |
|
utils.copy(this._currentOutput.sizeData, clone._currentOutput.sizeData); |
|
} |
|
|
|
utils.copy(this._currentOutput.flags, clone._currentOutput.flags); |
|
} |
|
|
|
|
|
['_global', '_complexFilters'].forEach(function(prop) { |
|
clone[prop] = self[prop].clone(); |
|
}); |
|
|
|
return clone; |
|
}; |
|
|
|
|
|
|
|
|
|
require('./options/inputs')(FfmpegCommand.prototype); |
|
require('./options/audio')(FfmpegCommand.prototype); |
|
require('./options/video')(FfmpegCommand.prototype); |
|
require('./options/videosize')(FfmpegCommand.prototype); |
|
require('./options/output')(FfmpegCommand.prototype); |
|
require('./options/custom')(FfmpegCommand.prototype); |
|
require('./options/misc')(FfmpegCommand.prototype); |
|
|
|
|
|
|
|
|
|
require('./processor')(FfmpegCommand.prototype); |
|
|
|
|
|
|
|
|
|
require('./capabilities')(FfmpegCommand.prototype); |
|
|
|
FfmpegCommand.setFfmpegPath = function(path) { |
|
(new FfmpegCommand()).setFfmpegPath(path); |
|
}; |
|
|
|
FfmpegCommand.setFfprobePath = function(path) { |
|
(new FfmpegCommand()).setFfprobePath(path); |
|
}; |
|
|
|
FfmpegCommand.setFlvtoolPath = function(path) { |
|
(new FfmpegCommand()).setFlvtoolPath(path); |
|
}; |
|
|
|
FfmpegCommand.availableFilters = |
|
FfmpegCommand.getAvailableFilters = function(callback) { |
|
(new FfmpegCommand()).availableFilters(callback); |
|
}; |
|
|
|
FfmpegCommand.availableCodecs = |
|
FfmpegCommand.getAvailableCodecs = function(callback) { |
|
(new FfmpegCommand()).availableCodecs(callback); |
|
}; |
|
|
|
FfmpegCommand.availableFormats = |
|
FfmpegCommand.getAvailableFormats = function(callback) { |
|
(new FfmpegCommand()).availableFormats(callback); |
|
}; |
|
|
|
FfmpegCommand.availableEncoders = |
|
FfmpegCommand.getAvailableEncoders = function(callback) { |
|
(new FfmpegCommand()).availableEncoders(callback); |
|
}; |
|
|
|
|
|
|
|
|
|
require('./ffprobe')(FfmpegCommand.prototype); |
|
|
|
FfmpegCommand.ffprobe = function(file) { |
|
var instance = new FfmpegCommand(file); |
|
instance.ffprobe.apply(instance, Array.prototype.slice.call(arguments, 1)); |
|
}; |
|
|
|
|
|
|
|
require('./recipes')(FfmpegCommand.prototype); |
|
|