123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- '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);
|