audio.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*jshint node:true*/
  2. 'use strict';
  3. var utils = require('../utils');
  4. /*
  5. *! Audio-related methods
  6. */
  7. module.exports = function(proto) {
  8. /**
  9. * Disable audio in the output
  10. *
  11. * @method FfmpegCommand#noAudio
  12. * @category Audio
  13. * @aliases withNoAudio
  14. * @return FfmpegCommand
  15. */
  16. proto.withNoAudio =
  17. proto.noAudio = function() {
  18. this._currentOutput.audio.clear();
  19. this._currentOutput.audioFilters.clear();
  20. this._currentOutput.audio('-an');
  21. return this;
  22. };
  23. /**
  24. * Specify audio codec
  25. *
  26. * @method FfmpegCommand#audioCodec
  27. * @category Audio
  28. * @aliases withAudioCodec
  29. *
  30. * @param {String} codec audio codec name
  31. * @return FfmpegCommand
  32. */
  33. proto.withAudioCodec =
  34. proto.audioCodec = function(codec) {
  35. this._currentOutput.audio('-acodec', codec);
  36. return this;
  37. };
  38. /**
  39. * Specify audio bitrate
  40. *
  41. * @method FfmpegCommand#audioBitrate
  42. * @category Audio
  43. * @aliases withAudioBitrate
  44. *
  45. * @param {String|Number} bitrate audio bitrate in kbps (with an optional 'k' suffix)
  46. * @return FfmpegCommand
  47. */
  48. proto.withAudioBitrate =
  49. proto.audioBitrate = function(bitrate) {
  50. this._currentOutput.audio('-b:a', ('' + bitrate).replace(/k?$/, 'k'));
  51. return this;
  52. };
  53. /**
  54. * Specify audio channel count
  55. *
  56. * @method FfmpegCommand#audioChannels
  57. * @category Audio
  58. * @aliases withAudioChannels
  59. *
  60. * @param {Number} channels channel count
  61. * @return FfmpegCommand
  62. */
  63. proto.withAudioChannels =
  64. proto.audioChannels = function(channels) {
  65. this._currentOutput.audio('-ac', channels);
  66. return this;
  67. };
  68. /**
  69. * Specify audio frequency
  70. *
  71. * @method FfmpegCommand#audioFrequency
  72. * @category Audio
  73. * @aliases withAudioFrequency
  74. *
  75. * @param {Number} freq audio frequency in Hz
  76. * @return FfmpegCommand
  77. */
  78. proto.withAudioFrequency =
  79. proto.audioFrequency = function(freq) {
  80. this._currentOutput.audio('-ar', freq);
  81. return this;
  82. };
  83. /**
  84. * Specify audio quality
  85. *
  86. * @method FfmpegCommand#audioQuality
  87. * @category Audio
  88. * @aliases withAudioQuality
  89. *
  90. * @param {Number} quality audio quality factor
  91. * @return FfmpegCommand
  92. */
  93. proto.withAudioQuality =
  94. proto.audioQuality = function(quality) {
  95. this._currentOutput.audio('-aq', quality);
  96. return this;
  97. };
  98. /**
  99. * Specify custom audio filter(s)
  100. *
  101. * Can be called both with one or many filters, or a filter array.
  102. *
  103. * @example
  104. * command.audioFilters('filter1');
  105. *
  106. * @example
  107. * command.audioFilters('filter1', 'filter2=param1=value1:param2=value2');
  108. *
  109. * @example
  110. * command.audioFilters(['filter1', 'filter2']);
  111. *
  112. * @example
  113. * command.audioFilters([
  114. * {
  115. * filter: 'filter1'
  116. * },
  117. * {
  118. * filter: 'filter2',
  119. * options: 'param=value:param=value'
  120. * }
  121. * ]);
  122. *
  123. * @example
  124. * command.audioFilters(
  125. * {
  126. * filter: 'filter1',
  127. * options: ['value1', 'value2']
  128. * },
  129. * {
  130. * filter: 'filter2',
  131. * options: { param1: 'value1', param2: 'value2' }
  132. * }
  133. * );
  134. *
  135. * @method FfmpegCommand#audioFilters
  136. * @aliases withAudioFilter,withAudioFilters,audioFilter
  137. * @category Audio
  138. *
  139. * @param {...String|String[]|Object[]} filters audio filter strings, string array or
  140. * filter specification array, each with the following properties:
  141. * @param {String} filters.filter filter name
  142. * @param {String|String[]|Object} [filters.options] filter option string, array, or object
  143. * @return FfmpegCommand
  144. */
  145. proto.withAudioFilter =
  146. proto.withAudioFilters =
  147. proto.audioFilter =
  148. proto.audioFilters = function(filters) {
  149. if (arguments.length > 1) {
  150. filters = [].slice.call(arguments);
  151. }
  152. if (!Array.isArray(filters)) {
  153. filters = [filters];
  154. }
  155. this._currentOutput.audioFilters(utils.makeFilterStrings(filters));
  156. return this;
  157. };
  158. };