| |
| 'use strict'; |
|
|
| var utils = require('../utils'); |
|
|
|
|
| |
| |
| |
|
|
| module.exports = function(proto) { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| proto.addOutput = |
| proto.output = function(target, pipeopts) { |
| var isFile = false; |
|
|
| if (!target && this._currentOutput) { |
| |
| throw new Error('Invalid output'); |
| } |
|
|
| if (target && typeof target !== 'string') { |
| if (!('writable' in target) || !(target.writable)) { |
| throw new Error('Invalid output'); |
| } |
| } else if (typeof target === 'string') { |
| var protocol = target.match(/^([a-z]{2,}):/i); |
| isFile = !protocol || protocol[0] === 'file'; |
| } |
|
|
| if (target && !('target' in this._currentOutput)) { |
| |
| this._currentOutput.target = target; |
| this._currentOutput.isFile = isFile; |
| this._currentOutput.pipeopts = pipeopts || {}; |
| } else { |
| if (target && typeof target !== 'string') { |
| var hasOutputStream = this._outputs.some(function(output) { |
| return typeof output.target !== 'string'; |
| }); |
|
|
| if (hasOutputStream) { |
| throw new Error('Only one output stream is supported'); |
| } |
| } |
|
|
| this._outputs.push(this._currentOutput = { |
| target: target, |
| isFile: isFile, |
| flags: {}, |
| pipeopts: pipeopts || {} |
| }); |
|
|
| var self = this; |
| ['audio', 'audioFilters', 'video', 'videoFilters', 'sizeFilters', 'options'].forEach(function(key) { |
| self._currentOutput[key] = utils.args(); |
| }); |
|
|
| if (!target) { |
| |
| delete this._currentOutput.target; |
| } |
| } |
|
|
| return this; |
| }; |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| proto.seekOutput = |
| proto.seek = function(seek) { |
| this._currentOutput.options('-ss', seek); |
| return this; |
| }; |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| proto.withDuration = |
| proto.setDuration = |
| proto.duration = function(duration) { |
| this._currentOutput.options('-t', duration); |
| return this; |
| }; |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| proto.toFormat = |
| proto.withOutputFormat = |
| proto.outputFormat = |
| proto.format = function(format) { |
| this._currentOutput.options('-f', format); |
| return this; |
| }; |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| proto.map = function(spec) { |
| this._currentOutput.options('-map', spec.replace(utils.streamRegexp, '[$1]')); |
| return this; |
| }; |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| proto.updateFlvMetadata = |
| proto.flvmeta = function() { |
| this._currentOutput.flags.flvmeta = true; |
| return this; |
| }; |
| }; |
|
|