video.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*jshint node:true*/
  2. 'use strict';
  3. var utils = require('../utils');
  4. /*
  5. *! Video-related methods
  6. */
  7. module.exports = function(proto) {
  8. /**
  9. * Disable video in the output
  10. *
  11. * @method FfmpegCommand#noVideo
  12. * @category Video
  13. * @aliases withNoVideo
  14. *
  15. * @return FfmpegCommand
  16. */
  17. proto.withNoVideo =
  18. proto.noVideo = function() {
  19. this._currentOutput.video.clear();
  20. this._currentOutput.videoFilters.clear();
  21. this._currentOutput.video('-vn');
  22. return this;
  23. };
  24. /**
  25. * Specify video codec
  26. *
  27. * @method FfmpegCommand#videoCodec
  28. * @category Video
  29. * @aliases withVideoCodec
  30. *
  31. * @param {String} codec video codec name
  32. * @return FfmpegCommand
  33. */
  34. proto.withVideoCodec =
  35. proto.videoCodec = function(codec) {
  36. this._currentOutput.video('-vcodec', codec);
  37. return this;
  38. };
  39. /**
  40. * Specify video bitrate
  41. *
  42. * @method FfmpegCommand#videoBitrate
  43. * @category Video
  44. * @aliases withVideoBitrate
  45. *
  46. * @param {String|Number} bitrate video bitrate in kbps (with an optional 'k' suffix)
  47. * @param {Boolean} [constant=false] enforce constant bitrate
  48. * @return FfmpegCommand
  49. */
  50. proto.withVideoBitrate =
  51. proto.videoBitrate = function(bitrate, constant) {
  52. bitrate = ('' + bitrate).replace(/k?$/, 'k');
  53. this._currentOutput.video('-b:v', bitrate);
  54. if (constant) {
  55. this._currentOutput.video(
  56. '-maxrate', bitrate,
  57. '-minrate', bitrate,
  58. '-bufsize', '3M'
  59. );
  60. }
  61. return this;
  62. };
  63. /**
  64. * Specify custom video filter(s)
  65. *
  66. * Can be called both with one or many filters, or a filter array.
  67. *
  68. * @example
  69. * command.videoFilters('filter1');
  70. *
  71. * @example
  72. * command.videoFilters('filter1', 'filter2=param1=value1:param2=value2');
  73. *
  74. * @example
  75. * command.videoFilters(['filter1', 'filter2']);
  76. *
  77. * @example
  78. * command.videoFilters([
  79. * {
  80. * filter: 'filter1'
  81. * },
  82. * {
  83. * filter: 'filter2',
  84. * options: 'param=value:param=value'
  85. * }
  86. * ]);
  87. *
  88. * @example
  89. * command.videoFilters(
  90. * {
  91. * filter: 'filter1',
  92. * options: ['value1', 'value2']
  93. * },
  94. * {
  95. * filter: 'filter2',
  96. * options: { param1: 'value1', param2: 'value2' }
  97. * }
  98. * );
  99. *
  100. * @method FfmpegCommand#videoFilters
  101. * @category Video
  102. * @aliases withVideoFilter,withVideoFilters,videoFilter
  103. *
  104. * @param {...String|String[]|Object[]} filters video filter strings, string array or
  105. * filter specification array, each with the following properties:
  106. * @param {String} filters.filter filter name
  107. * @param {String|String[]|Object} [filters.options] filter option string, array, or object
  108. * @return FfmpegCommand
  109. */
  110. proto.withVideoFilter =
  111. proto.withVideoFilters =
  112. proto.videoFilter =
  113. proto.videoFilters = function(filters) {
  114. if (arguments.length > 1) {
  115. filters = [].slice.call(arguments);
  116. }
  117. if (!Array.isArray(filters)) {
  118. filters = [filters];
  119. }
  120. this._currentOutput.videoFilters(utils.makeFilterStrings(filters));
  121. return this;
  122. };
  123. /**
  124. * Specify output FPS
  125. *
  126. * @method FfmpegCommand#fps
  127. * @category Video
  128. * @aliases withOutputFps,withOutputFPS,withFpsOutput,withFPSOutput,withFps,withFPS,outputFPS,outputFps,fpsOutput,FPSOutput,FPS
  129. *
  130. * @param {Number} fps output FPS
  131. * @return FfmpegCommand
  132. */
  133. proto.withOutputFps =
  134. proto.withOutputFPS =
  135. proto.withFpsOutput =
  136. proto.withFPSOutput =
  137. proto.withFps =
  138. proto.withFPS =
  139. proto.outputFPS =
  140. proto.outputFps =
  141. proto.fpsOutput =
  142. proto.FPSOutput =
  143. proto.fps =
  144. proto.FPS = function(fps) {
  145. this._currentOutput.video('-r', fps);
  146. return this;
  147. };
  148. /**
  149. * Only transcode a certain number of frames
  150. *
  151. * @method FfmpegCommand#frames
  152. * @category Video
  153. * @aliases takeFrames,withFrames
  154. *
  155. * @param {Number} frames frame count
  156. * @return FfmpegCommand
  157. */
  158. proto.takeFrames =
  159. proto.withFrames =
  160. proto.frames = function(frames) {
  161. this._currentOutput.video('-vframes', frames);
  162. return this;
  163. };
  164. };