// 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/videosize.js",[27,74,75,77,79,83,84,85,86,87,89,90,91,92,94,95,97,99,100,103,105,106,108,109,112,113,115,116,119,124,125,127,131,140,154,158,183,186,188,189,191,205,211,212,213,214,215,217,221,223,224,226,240,251,252,253,257,258,261,263,264,266]);
_$jscoverage_init(_$jscoverage_cond, "lib/options/videosize.js",[77,89,92,99,105,105,106,115,124,212,214,251,257]);
_$jscoverage["lib/options/videosize.js"].source = ["/*jshint node:true*/","'use strict';","","/*"," *! Size helpers"," */","","","/**"," * Return filters to pad video to width*height,"," *"," * @param {Number} width output width"," * @param {Number} height output height"," * @param {Number} aspect video aspect ratio (without padding)"," * @param {Number} color padding color"," * @return scale/pad filters"," * @private"," */","function getScalePadFilters(width, height, aspect, color) {","  /*","    let a be the input aspect ratio, A be the requested aspect ratio","","    if a > A, padding is done on top and bottom","    if a < A, padding is done on left and right","   */","","  return [","    /*","      In both cases, we first have to scale the input to match the requested size.","      When using computed width/height, we truncate them to multiples of 2","","        scale=","          w=if(gt(a, A), width, trunc(height*a/2)*2):","          h=if(lt(a, A), height, trunc(width/a/2)*2)","     */","","    'scale=\\'' +","      'w=if(gt(a,' + aspect + '),' + width + ',trunc(' + height + '*a/2)*2):' +","      'h=if(lt(a,' + aspect + '),' + height + ',trunc(' + width + '/a/2)*2)\\'',","","    /*","      Then we pad the scaled input to match the target size","","        pad=","          w=width:","          h=height:","          x=if(gt(a, A), 0, (width - iw)/2):","          y=if(lt(a, A), 0, (height - ih)/2)","","      (here iw and ih refer to the padding input, i.e the scaled output)","     */","","    'pad=\\'' +","      'w=' + width + ':' +","      'h=' + height + ':' +","      'x=if(gt(a,' + aspect + '),0,(' + width + '-iw)/2):' +","      'y=if(lt(a,' + aspect + '),0,(' + height + '-ih)/2):' +","      'color=' + color + '\\''","  ];","}","","","/**"," * Recompute size filters"," *"," * @param {Object} output"," * @param {String} key newly-added parameter name ('size', 'aspect' or 'pad')"," * @param {String} value newly-added parameter value"," * @return filter string array"," * @private"," */","function createSizeFilters(output, key, value) {","  // Store parameters","  var data = output.sizeData = output.sizeData || {};","  data[key] = value;","","  if (!('size' in data)) {","    // No size requested, keep original size","    return [];","  }","","  // Try to match the different size string formats","  var fixedSize = data.size.match(/([0-9]+)x([0-9]+)/);","  var fixedWidth = data.size.match(/([0-9]+)x\\?/);","  var fixedHeight = data.size.match(/\\?x([0-9]+)/);","  var percentRatio = data.size.match(/\\b([0-9]{1,3})%/);","  var width, height, aspect;","","  if (percentRatio) {","    var ratio = Number(percentRatio[1]) / 100;","    return ['scale=trunc(iw*' + ratio + '/2)*2:trunc(ih*' + ratio + '/2)*2'];","  } else if (fixedSize) {","    // Round target size to multiples of 2","    width = Math.round(Number(fixedSize[1]) / 2) * 2;","    height = Math.round(Number(fixedSize[2]) / 2) * 2;","","    aspect = width / height;","","    if (data.pad) {","      return getScalePadFilters(width, height, aspect, data.pad);","    } else {","      // No autopad requested, rescale to target size","      return ['scale=' + width + ':' + height];","    }","  } else if (fixedWidth || fixedHeight) {","    if ('aspect' in data) {","      // Specified aspect ratio","      width = fixedWidth ? fixedWidth[1] : Math.round(Number(fixedHeight[1]) * data.aspect);","      height = fixedHeight ? fixedHeight[1] : Math.round(Number(fixedWidth[1]) / data.aspect);","","      // Round to multiples of 2","      width = Math.round(width / 2) * 2;","      height = Math.round(height / 2) * 2;","","      if (data.pad) {","        return getScalePadFilters(width, height, data.aspect, data.pad);","      } else {","        // No autopad requested, rescale to target size","        return ['scale=' + width + ':' + height];","      }","    } else {","      // Keep input aspect ratio","","      if (fixedWidth) {","        return ['scale=' + (Math.round(Number(fixedWidth[1]) / 2) * 2) + ':trunc(ow/a/2)*2'];","      } else {","        return ['scale=trunc(oh*a/2)*2:' + (Math.round(Number(fixedHeight[1]) / 2) * 2)];","      }","    }","  } else {","    throw new Error('Invalid size specified: ' + data.size);","  }","}","","","/*"," *! Video size-related methods"," */","","module.exports = function(proto) {","  /**","   * Keep display aspect ratio","   *","   * This method is useful when converting an input with non-square pixels to an output format","   * that does not support non-square pixels.  It rescales the input so that the display aspect","   * ratio is the same.","   *","   * @method FfmpegCommand#keepDAR","   * @category Video size","   * @aliases keepPixelAspect,keepDisplayAspect,keepDisplayAspectRatio","   *","   * @return FfmpegCommand","   */","  proto.keepPixelAspect = // Only for compatibility, this is not about keeping _pixel_ aspect ratio","  proto.keepDisplayAspect =","  proto.keepDisplayAspectRatio =","  proto.keepDAR = function() {","    return this.videoFilters(","      'scale=\\'w=if(gt(sar,1),iw*sar,iw):h=if(lt(sar,1),ih/sar,ih)\\'',","      'setsar=1'","    );","  };","","","  /**","   * Set output size","   *","   * The 'size' parameter can have one of 4 forms:","   * - 'X%': rescale to xx % of the original size","   * - 'WxH': specify width and height","   * - 'Wx?': specify width and compute height from input aspect ratio","   * - '?xH': specify height and compute width from input aspect ratio","   *","   * Note: both dimensions will be truncated to multiples of 2.","   *","   * @method FfmpegCommand#size","   * @category Video size","   * @aliases withSize,setSize","   *","   * @param {String} size size string, eg. '33%', '320x240', '320x?', '?x240'","   * @return FfmpegCommand","   */","  proto.withSize =","  proto.setSize =","  proto.size = function(size) {","    var filters = createSizeFilters(this._currentOutput, 'size', size);","","    this._currentOutput.sizeFilters.clear();","    this._currentOutput.sizeFilters(filters);","","    return this;","  };","","","  /**","   * Set output aspect ratio","   *","   * @method FfmpegCommand#aspect","   * @category Video size","   * @aliases withAspect,withAspectRatio,setAspect,setAspectRatio,aspectRatio","   *","   * @param {String|Number} aspect aspect ratio (number or 'X:Y' string)","   * @return FfmpegCommand","   */","  proto.withAspect =","  proto.withAspectRatio =","  proto.setAspect =","  proto.setAspectRatio =","  proto.aspect =","  proto.aspectRatio = function(aspect) {","    var a = Number(aspect);","    if (isNaN(a)) {","      var match = aspect.match(/^(\\d+):(\\d+)$/);","      if (match) {","        a = Number(match[1]) / Number(match[2]);","      } else {","        throw new Error('Invalid aspect ratio: ' + aspect);","      }","    }","","    var filters = createSizeFilters(this._currentOutput, 'aspect', a);","","    this._currentOutput.sizeFilters.clear();","    this._currentOutput.sizeFilters(filters);","","    return this;","  };","","","  /**","   * Enable auto-padding the output","   *","   * @method FfmpegCommand#autopad","   * @category Video size","   * @aliases applyAutopadding,applyAutoPadding,applyAutopad,applyAutoPad,withAutopadding,withAutoPadding,withAutopad,withAutoPad,autoPad","   *","   * @param {Boolean} [pad=true] enable/disable auto-padding","   * @param {String} [color='black'] pad color","   */","  proto.applyAutopadding =","  proto.applyAutoPadding =","  proto.applyAutopad =","  proto.applyAutoPad =","  proto.withAutopadding =","  proto.withAutoPadding =","  proto.withAutopad =","  proto.withAutoPad =","  proto.autoPad =","  proto.autopad = function(pad, color) {","    // Allow autopad(color)","    if (typeof pad === 'string') {","      color = pad;","      pad = true;","    }","","    // Allow autopad() and autopad(undefined, color)","    if (typeof pad === 'undefined') {","      pad = true;","    }","","    var filters = createSizeFilters(this._currentOutput, 'pad', pad ? color || 'black' : false);","","    this._currentOutput.sizeFilters.clear();","    this._currentOutput.sizeFilters(filters);","","    return this;","  };","};",""];
"use strict";

function getScalePadFilters(width, height, aspect, color) {
    _$jscoverage_done("lib/options/videosize.js", 27);
    return [ "scale='" + "w=if(gt(a," + aspect + ")," + width + ",trunc(" + height + "*a/2)*2):" + "h=if(lt(a," + aspect + ")," + height + ",trunc(" + width + "/a/2)*2)'", "pad='" + "w=" + width + ":" + "h=" + height + ":" + "x=if(gt(a," + aspect + "),0,(" + width + "-iw)/2):" + "y=if(lt(a," + aspect + "),0,(" + height + "-ih)/2):" + "color=" + color + "'" ];
}

function createSizeFilters(output, key, value) {
    _$jscoverage_done("lib/options/videosize.js", 74);
    var data = output.sizeData = output.sizeData || {};
    _$jscoverage_done("lib/options/videosize.js", 75);
    data[key] = value;
    _$jscoverage_done("lib/options/videosize.js", 77);
    if (_$jscoverage_done("lib/options/videosize.js", 77, !("size" in data))) {
        _$jscoverage_done("lib/options/videosize.js", 79);
        return [];
    }
    _$jscoverage_done("lib/options/videosize.js", 83);
    var fixedSize = data.size.match(/([0-9]+)x([0-9]+)/);
    _$jscoverage_done("lib/options/videosize.js", 84);
    var fixedWidth = data.size.match(/([0-9]+)x\?/);
    _$jscoverage_done("lib/options/videosize.js", 85);
    var fixedHeight = data.size.match(/\?x([0-9]+)/);
    _$jscoverage_done("lib/options/videosize.js", 86);
    var percentRatio = data.size.match(/\b([0-9]{1,3})%/);
    _$jscoverage_done("lib/options/videosize.js", 87);
    var width, height, aspect;
    _$jscoverage_done("lib/options/videosize.js", 89);
    if (_$jscoverage_done("lib/options/videosize.js", 89, percentRatio)) {
        _$jscoverage_done("lib/options/videosize.js", 90);
        var ratio = Number(percentRatio[1]) / 100;
        _$jscoverage_done("lib/options/videosize.js", 91);
        return [ "scale=trunc(iw*" + ratio + "/2)*2:trunc(ih*" + ratio + "/2)*2" ];
    } else {
        _$jscoverage_done("lib/options/videosize.js", 92);
        if (_$jscoverage_done("lib/options/videosize.js", 92, fixedSize)) {
            _$jscoverage_done("lib/options/videosize.js", 94);
            width = Math.round(Number(fixedSize[1]) / 2) * 2;
            _$jscoverage_done("lib/options/videosize.js", 95);
            height = Math.round(Number(fixedSize[2]) / 2) * 2;
            _$jscoverage_done("lib/options/videosize.js", 97);
            aspect = width / height;
            _$jscoverage_done("lib/options/videosize.js", 99);
            if (_$jscoverage_done("lib/options/videosize.js", 99, data.pad)) {
                _$jscoverage_done("lib/options/videosize.js", 100);
                return getScalePadFilters(width, height, aspect, data.pad);
            } else {
                _$jscoverage_done("lib/options/videosize.js", 103);
                return [ "scale=" + width + ":" + height ];
            }
        } else {
            _$jscoverage_done("lib/options/videosize.js", 105);
            if (_$jscoverage_done("lib/options/videosize.js", 105, fixedWidth) || _$jscoverage_done("lib/options/videosize.js", 105, fixedHeight)) {
                _$jscoverage_done("lib/options/videosize.js", 106);
                if (_$jscoverage_done("lib/options/videosize.js", 106, "aspect" in data)) {
                    _$jscoverage_done("lib/options/videosize.js", 108);
                    width = fixedWidth ? fixedWidth[1] : Math.round(Number(fixedHeight[1]) * data.aspect);
                    _$jscoverage_done("lib/options/videosize.js", 109);
                    height = fixedHeight ? fixedHeight[1] : Math.round(Number(fixedWidth[1]) / data.aspect);
                    _$jscoverage_done("lib/options/videosize.js", 112);
                    width = Math.round(width / 2) * 2;
                    _$jscoverage_done("lib/options/videosize.js", 113);
                    height = Math.round(height / 2) * 2;
                    _$jscoverage_done("lib/options/videosize.js", 115);
                    if (_$jscoverage_done("lib/options/videosize.js", 115, data.pad)) {
                        _$jscoverage_done("lib/options/videosize.js", 116);
                        return getScalePadFilters(width, height, data.aspect, data.pad);
                    } else {
                        _$jscoverage_done("lib/options/videosize.js", 119);
                        return [ "scale=" + width + ":" + height ];
                    }
                } else {
                    _$jscoverage_done("lib/options/videosize.js", 124);
                    if (_$jscoverage_done("lib/options/videosize.js", 124, fixedWidth)) {
                        _$jscoverage_done("lib/options/videosize.js", 125);
                        return [ "scale=" + Math.round(Number(fixedWidth[1]) / 2) * 2 + ":trunc(ow/a/2)*2" ];
                    } else {
                        _$jscoverage_done("lib/options/videosize.js", 127);
                        return [ "scale=trunc(oh*a/2)*2:" + Math.round(Number(fixedHeight[1]) / 2) * 2 ];
                    }
                }
            } else {
                _$jscoverage_done("lib/options/videosize.js", 131);
                throw new Error("Invalid size specified: " + data.size);
            }
        }
    }
}

_$jscoverage_done("lib/options/videosize.js", 140);
module.exports = function(proto) {
    _$jscoverage_done("lib/options/videosize.js", 154);
    proto.keepPixelAspect = proto.keepDisplayAspect = proto.keepDisplayAspectRatio = proto.keepDAR = function() {
        _$jscoverage_done("lib/options/videosize.js", 158);
        return this.videoFilters("scale='w=if(gt(sar,1),iw*sar,iw):h=if(lt(sar,1),ih/sar,ih)'", "setsar=1");
    };
    _$jscoverage_done("lib/options/videosize.js", 183);
    proto.withSize = proto.setSize = proto.size = function(size) {
        _$jscoverage_done("lib/options/videosize.js", 186);
        var filters = createSizeFilters(this._currentOutput, "size", size);
        _$jscoverage_done("lib/options/videosize.js", 188);
        this._currentOutput.sizeFilters.clear();
        _$jscoverage_done("lib/options/videosize.js", 189);
        this._currentOutput.sizeFilters(filters);
        _$jscoverage_done("lib/options/videosize.js", 191);
        return this;
    };
    _$jscoverage_done("lib/options/videosize.js", 205);
    proto.withAspect = proto.withAspectRatio = proto.setAspect = proto.setAspectRatio = proto.aspect = proto.aspectRatio = function(aspect) {
        _$jscoverage_done("lib/options/videosize.js", 211);
        var a = Number(aspect);
        _$jscoverage_done("lib/options/videosize.js", 212);
        if (_$jscoverage_done("lib/options/videosize.js", 212, isNaN(a))) {
            _$jscoverage_done("lib/options/videosize.js", 213);
            var match = aspect.match(/^(\d+):(\d+)$/);
            _$jscoverage_done("lib/options/videosize.js", 214);
            if (_$jscoverage_done("lib/options/videosize.js", 214, match)) {
                _$jscoverage_done("lib/options/videosize.js", 215);
                a = Number(match[1]) / Number(match[2]);
            } else {
                _$jscoverage_done("lib/options/videosize.js", 217);
                throw new Error("Invalid aspect ratio: " + aspect);
            }
        }
        _$jscoverage_done("lib/options/videosize.js", 221);
        var filters = createSizeFilters(this._currentOutput, "aspect", a);
        _$jscoverage_done("lib/options/videosize.js", 223);
        this._currentOutput.sizeFilters.clear();
        _$jscoverage_done("lib/options/videosize.js", 224);
        this._currentOutput.sizeFilters(filters);
        _$jscoverage_done("lib/options/videosize.js", 226);
        return this;
    };
    _$jscoverage_done("lib/options/videosize.js", 240);
    proto.applyAutopadding = proto.applyAutoPadding = proto.applyAutopad = proto.applyAutoPad = proto.withAutopadding = proto.withAutoPadding = proto.withAutopad = proto.withAutoPad = proto.autoPad = proto.autopad = function(pad, color) {
        _$jscoverage_done("lib/options/videosize.js", 251);
        if (_$jscoverage_done("lib/options/videosize.js", 251, typeof pad === "string")) {
            _$jscoverage_done("lib/options/videosize.js", 252);
            color = pad;
            _$jscoverage_done("lib/options/videosize.js", 253);
            pad = true;
        }
        _$jscoverage_done("lib/options/videosize.js", 257);
        if (_$jscoverage_done("lib/options/videosize.js", 257, typeof pad === "undefined")) {
            _$jscoverage_done("lib/options/videosize.js", 258);
            pad = true;
        }
        _$jscoverage_done("lib/options/videosize.js", 261);
        var filters = createSizeFilters(this._currentOutput, "pad", pad ? color || "black" : false);
        _$jscoverage_done("lib/options/videosize.js", 263);
        this._currentOutput.sizeFilters.clear();
        _$jscoverage_done("lib/options/videosize.js", 264);
        this._currentOutput.sizeFilters(filters);
        _$jscoverage_done("lib/options/videosize.js", 266);
        return this;
    };
};