// instrument by jscoverage, do not modifly this file
(function () {
  var BASE;
  if (typeof global === 'object') {
    BASE = global;
  } else if (typeof window === 'object') {
    BASE = window;
  } else {
    throw new Error('[jscoverage] unknow ENV!');
  }
  if (!BASE._$jscoverage) {
    BASE._$jscoverage = {};
    BASE._$jscoverage_cond = {};
    BASE._$jscoverage_done = function (file, line, express) {
      if (arguments.length === 2) {
        BASE._$jscoverage[file][line] ++;
      } else {
        BASE._$jscoverage_cond[file][line] ++;
        return express;
      }
    };
    BASE._$jscoverage_init = function (base, file, lines) {
      var tmp = [];
      for (var i = 0; i < lines.length; i ++) {
        tmp[lines[i]] = 0;
      }
      base[file] = tmp;
    };
  }
})();
_$jscoverage_init(_$jscoverage, "lib/options/output.js",[4,11,23,25,27,29,32,33,34,36,37,38,41,43,44,45,47,48,49,52,53,57,64,65,66,69,71,75,89,91,92,106,109,110,124,128,129,142,143,144,157,159,160]);
_$jscoverage_init(_$jscoverage_cond, "lib/options/output.js",[27,27,32,32,33,33,36,41,41,47,47,52,69]);
_$jscoverage["lib/options/output.js"].source = ["/*jshint node:true*/","'use strict';","","var utils = require('../utils');","","","/*"," *! Output-related methods"," */","","module.exports = function(proto) {","  /**","   * Add output","   *","   * @method FfmpegCommand#output","   * @category Output","   * @aliases addOutput","   *","   * @param {String|Writable} target target file path or writable stream","   * @param {Object} [pipeopts={}] pipe options (only applies to streams)","   * @return FfmpegCommand","   */","  proto.addOutput =","  proto.output = function(target, pipeopts) {","    var isFile = false;","","    if (!target && this._currentOutput) {","      // No target is only allowed when called from constructor","      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)) {","      // For backwards compatibility, set target for first output","      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) {","        // Call from constructor: remove target key","        delete this._currentOutput.target;","      }","    }","","    return this;","  };","","","  /**","   * Specify output seek time","   *","   * @method FfmpegCommand#seek","   * @category Input","   * @aliases seekOutput","   *","   * @param {String|Number} seek seek time in seconds or as a '[hh:[mm:]]ss[.xxx]' string","   * @return FfmpegCommand","   */","  proto.seekOutput =","  proto.seek = function(seek) {","    this._currentOutput.options('-ss', seek);","    return this;","  };","","","  /**","   * Set output duration","   *","   * @method FfmpegCommand#duration","   * @category Output","   * @aliases withDuration,setDuration","   *","   * @param {String|Number} duration duration in seconds or as a '[[hh:]mm:]ss[.xxx]' string","   * @return FfmpegCommand","   */","  proto.withDuration =","  proto.setDuration =","  proto.duration = function(duration) {","    this._currentOutput.options('-t', duration);","    return this;","  };","","","  /**","   * Set output format","   *","   * @method FfmpegCommand#format","   * @category Output","   * @aliases toFormat,withOutputFormat,outputFormat","   *","   * @param {String} format output format name","   * @return FfmpegCommand","   */","  proto.toFormat =","  proto.withOutputFormat =","  proto.outputFormat =","  proto.format = function(format) {","    this._currentOutput.options('-f', format);","    return this;","  };","","","  /**","   * Add stream mapping to output","   *","   * @method FfmpegCommand#map","   * @category Output","   *","   * @param {String} spec stream specification string, with optional square brackets","   * @return FfmpegCommand","   */","  proto.map = function(spec) {","    this._currentOutput.options('-map', spec.replace(utils.streamRegexp, '[$1]'));","    return this;","  };","","","  /**","   * Run flvtool2/flvmeta on output","   *","   * @method FfmpegCommand#flvmeta","   * @category Output","   * @aliases updateFlvMetadata","   *","   * @return FfmpegCommand","   */","  proto.updateFlvMetadata =","  proto.flvmeta = function() {","    this._currentOutput.flags.flvmeta = true;","    return this;","  };","};",""];
"use strict";

_$jscoverage_done("lib/options/output.js", 4);
var utils = require("../utils");

_$jscoverage_done("lib/options/output.js", 11);
module.exports = function(proto) {
    _$jscoverage_done("lib/options/output.js", 23);
    proto.addOutput = proto.output = function(target, pipeopts) {
        _$jscoverage_done("lib/options/output.js", 25);
        var isFile = false;
        _$jscoverage_done("lib/options/output.js", 27);
        if (_$jscoverage_done("lib/options/output.js", 27, !target) && _$jscoverage_done("lib/options/output.js", 27, this._currentOutput)) {
            _$jscoverage_done("lib/options/output.js", 29);
            throw new Error("Invalid output");
        }
        _$jscoverage_done("lib/options/output.js", 32);
        if (_$jscoverage_done("lib/options/output.js", 32, target) && _$jscoverage_done("lib/options/output.js", 32, typeof target !== "string")) {
            _$jscoverage_done("lib/options/output.js", 33);
            if (_$jscoverage_done("lib/options/output.js", 33, !("writable" in target)) || _$jscoverage_done("lib/options/output.js", 33, !target.writable)) {
                _$jscoverage_done("lib/options/output.js", 34);
                throw new Error("Invalid output");
            }
        } else {
            _$jscoverage_done("lib/options/output.js", 36);
            if (_$jscoverage_done("lib/options/output.js", 36, typeof target === "string")) {
                _$jscoverage_done("lib/options/output.js", 37);
                var protocol = target.match(/^([a-z]{2,}):/i);
                _$jscoverage_done("lib/options/output.js", 38);
                isFile = !protocol || protocol[0] === "file";
            }
        }
        _$jscoverage_done("lib/options/output.js", 41);
        if (_$jscoverage_done("lib/options/output.js", 41, target) && _$jscoverage_done("lib/options/output.js", 41, !("target" in this._currentOutput))) {
            _$jscoverage_done("lib/options/output.js", 43);
            this._currentOutput.target = target;
            _$jscoverage_done("lib/options/output.js", 44);
            this._currentOutput.isFile = isFile;
            _$jscoverage_done("lib/options/output.js", 45);
            this._currentOutput.pipeopts = pipeopts || {};
        } else {
            _$jscoverage_done("lib/options/output.js", 47);
            if (_$jscoverage_done("lib/options/output.js", 47, target) && _$jscoverage_done("lib/options/output.js", 47, typeof target !== "string")) {
                _$jscoverage_done("lib/options/output.js", 48);
                var hasOutputStream = this._outputs.some(function(output) {
                    _$jscoverage_done("lib/options/output.js", 49);
                    return typeof output.target !== "string";
                });
                _$jscoverage_done("lib/options/output.js", 52);
                if (_$jscoverage_done("lib/options/output.js", 52, hasOutputStream)) {
                    _$jscoverage_done("lib/options/output.js", 53);
                    throw new Error("Only one output stream is supported");
                }
            }
            _$jscoverage_done("lib/options/output.js", 57);
            this._outputs.push(this._currentOutput = {
                target: target,
                isFile: isFile,
                flags: {},
                pipeopts: pipeopts || {}
            });
            _$jscoverage_done("lib/options/output.js", 64);
            var self = this;
            _$jscoverage_done("lib/options/output.js", 65);
            [ "audio", "audioFilters", "video", "videoFilters", "sizeFilters", "options" ].forEach(function(key) {
                _$jscoverage_done("lib/options/output.js", 66);
                self._currentOutput[key] = utils.args();
            });
            _$jscoverage_done("lib/options/output.js", 69);
            if (_$jscoverage_done("lib/options/output.js", 69, !target)) {
                _$jscoverage_done("lib/options/output.js", 71);
                delete this._currentOutput.target;
            }
        }
        _$jscoverage_done("lib/options/output.js", 75);
        return this;
    };
    _$jscoverage_done("lib/options/output.js", 89);
    proto.seekOutput = proto.seek = function(seek) {
        _$jscoverage_done("lib/options/output.js", 91);
        this._currentOutput.options("-ss", seek);
        _$jscoverage_done("lib/options/output.js", 92);
        return this;
    };
    _$jscoverage_done("lib/options/output.js", 106);
    proto.withDuration = proto.setDuration = proto.duration = function(duration) {
        _$jscoverage_done("lib/options/output.js", 109);
        this._currentOutput.options("-t", duration);
        _$jscoverage_done("lib/options/output.js", 110);
        return this;
    };
    _$jscoverage_done("lib/options/output.js", 124);
    proto.toFormat = proto.withOutputFormat = proto.outputFormat = proto.format = function(format) {
        _$jscoverage_done("lib/options/output.js", 128);
        this._currentOutput.options("-f", format);
        _$jscoverage_done("lib/options/output.js", 129);
        return this;
    };
    _$jscoverage_done("lib/options/output.js", 142);
    proto.map = function(spec) {
        _$jscoverage_done("lib/options/output.js", 143);
        this._currentOutput.options("-map", spec.replace(utils.streamRegexp, "[$1]"));
        _$jscoverage_done("lib/options/output.js", 144);
        return this;
    };
    _$jscoverage_done("lib/options/output.js", 157);
    proto.updateFlvMetadata = proto.flvmeta = function() {
        _$jscoverage_done("lib/options/output.js", 159);
        this._currentOutput.flags.flvmeta = true;
        _$jscoverage_done("lib/options/output.js", 160);
        return this;
    };
};