fluent-ffmpeg.js.html 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: fluent-ffmpeg.js</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <h1 class="page-title">Source: fluent-ffmpeg.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>/*jshint node:true*/
  20. 'use strict';
  21. var path = require('path');
  22. var util = require('util');
  23. var EventEmitter = require('events').EventEmitter;
  24. var utils = require('./utils');
  25. var ARGLISTS = ['_global', '_audio', '_audioFilters', '_video', '_videoFilters', '_sizeFilters', '_complexFilters'];
  26. /**
  27. * Create an ffmpeg command
  28. *
  29. * Can be called with or without the 'new' operator, and the 'input' parameter
  30. * may be specified as 'options.source' instead (or passed later with the
  31. * addInput method).
  32. *
  33. * @constructor
  34. * @param {String|ReadableStream} [input] input file path or readable stream
  35. * @param {Object} [options] command options
  36. * @param {Object} [options.logger=&lt;no logging>] logger object with 'error', 'warning', 'info' and 'debug' methods
  37. * @param {Number} [options.niceness=0] ffmpeg process niceness, ignored on Windows
  38. * @param {Number} [options.priority=0] alias for `niceness`
  39. * @param {String} [options.presets="fluent-ffmpeg/lib/presets"] directory to load presets from
  40. * @param {String} [options.preset="fluent-ffmpeg/lib/presets"] alias for `presets`
  41. * @param {String} [options.stdoutLines=100] maximum lines of ffmpeg output to keep in memory, use 0 for unlimited
  42. * @param {Number} [options.timeout=&lt;no timeout>] ffmpeg processing timeout in seconds
  43. * @param {String|ReadableStream} [options.source=&lt;no input>] alias for the `input` parameter
  44. */
  45. function FfmpegCommand(input, options) {
  46. // Make 'new' optional
  47. if (!(this instanceof FfmpegCommand)) {
  48. return new FfmpegCommand(input, options);
  49. }
  50. EventEmitter.call(this);
  51. if (typeof input === 'object' &amp;&amp; !('readable' in input)) {
  52. // Options object passed directly
  53. options = input;
  54. } else {
  55. // Input passed first
  56. options = options || {};
  57. options.source = input;
  58. }
  59. // Add input if present
  60. this._inputs = [];
  61. if (options.source) {
  62. this.input(options.source);
  63. }
  64. // Add target-less output for backwards compatibility
  65. this._outputs = [];
  66. this.output();
  67. // Create argument lists
  68. var self = this;
  69. ['_global', '_complexFilters'].forEach(function(prop) {
  70. self[prop] = utils.args();
  71. });
  72. // Set default option values
  73. options.stdoutLines = 'stdoutLines' in options ? options.stdoutLines : 100;
  74. options.presets = options.presets || options.preset || path.join(__dirname, 'presets');
  75. options.niceness = options.niceness || options.priority || 0;
  76. // Save options
  77. this.options = options;
  78. // Setup logger
  79. this.logger = options.logger || {
  80. debug: function() {},
  81. info: function() {},
  82. warn: function() {},
  83. error: function() {}
  84. };
  85. }
  86. util.inherits(FfmpegCommand, EventEmitter);
  87. module.exports = FfmpegCommand;
  88. /**
  89. * Clone an ffmpeg command
  90. *
  91. * This method is useful when you want to process the same input multiple times.
  92. * It returns a new FfmpegCommand instance with the exact same options.
  93. *
  94. * All options set _after_ the clone() call will only be applied to the instance
  95. * it has been called on.
  96. *
  97. * @example
  98. * var command = ffmpeg('/path/to/source.avi')
  99. * .audioCodec('libfaac')
  100. * .videoCodec('libx264')
  101. * .format('mp4');
  102. *
  103. * command.clone()
  104. * .size('320x200')
  105. * .save('/path/to/output-small.mp4');
  106. *
  107. * command.clone()
  108. * .size('640x400')
  109. * .save('/path/to/output-medium.mp4');
  110. *
  111. * command.save('/path/to/output-original-size.mp4');
  112. *
  113. * @method FfmpegCommand#clone
  114. * @return FfmpegCommand
  115. */
  116. FfmpegCommand.prototype.clone = function() {
  117. var clone = new FfmpegCommand();
  118. var self = this;
  119. // Clone options and logger
  120. clone.options = this.options;
  121. clone.logger = this.logger;
  122. // Clone inputs
  123. clone._inputs = this._inputs.map(function(input) {
  124. return {
  125. source: input.source,
  126. options: input.options.clone()
  127. };
  128. });
  129. // Create first output
  130. if ('target' in this._outputs[0]) {
  131. // We have outputs set, don't clone them and create first output
  132. clone._outputs = [];
  133. clone.output();
  134. } else {
  135. // No outputs set, clone first output options
  136. clone._outputs = [
  137. clone._currentOutput = {
  138. flags: {}
  139. }
  140. ];
  141. ['audio', 'audioFilters', 'video', 'videoFilters', 'sizeFilters', 'options'].forEach(function(key) {
  142. clone._currentOutput[key] = self._currentOutput[key].clone();
  143. });
  144. if (this._currentOutput.sizeData) {
  145. clone._currentOutput.sizeData = {};
  146. utils.copy(this._currentOutput.sizeData, clone._currentOutput.sizeData);
  147. }
  148. utils.copy(this._currentOutput.flags, clone._currentOutput.flags);
  149. }
  150. // Clone argument lists
  151. ['_global', '_complexFilters'].forEach(function(prop) {
  152. clone[prop] = self[prop].clone();
  153. });
  154. return clone;
  155. };
  156. /* Add methods from options submodules */
  157. require('./options/inputs')(FfmpegCommand.prototype);
  158. require('./options/audio')(FfmpegCommand.prototype);
  159. require('./options/video')(FfmpegCommand.prototype);
  160. require('./options/videosize')(FfmpegCommand.prototype);
  161. require('./options/output')(FfmpegCommand.prototype);
  162. require('./options/custom')(FfmpegCommand.prototype);
  163. require('./options/misc')(FfmpegCommand.prototype);
  164. /* Add processor methods */
  165. require('./processor')(FfmpegCommand.prototype);
  166. /* Add capabilities methods */
  167. require('./capabilities')(FfmpegCommand.prototype);
  168. FfmpegCommand.setFfmpegPath = function(path) {
  169. (new FfmpegCommand()).setFfmpegPath(path);
  170. };
  171. FfmpegCommand.setFfprobePath = function(path) {
  172. (new FfmpegCommand()).setFfprobePath(path);
  173. };
  174. FfmpegCommand.setFlvtoolPath = function(path) {
  175. (new FfmpegCommand()).setFlvtoolPath(path);
  176. };
  177. FfmpegCommand.availableFilters =
  178. FfmpegCommand.getAvailableFilters = function(callback) {
  179. (new FfmpegCommand()).availableFilters(callback);
  180. };
  181. FfmpegCommand.availableCodecs =
  182. FfmpegCommand.getAvailableCodecs = function(callback) {
  183. (new FfmpegCommand()).availableCodecs(callback);
  184. };
  185. FfmpegCommand.availableFormats =
  186. FfmpegCommand.getAvailableFormats = function(callback) {
  187. (new FfmpegCommand()).availableFormats(callback);
  188. };
  189. /* Add ffprobe methods */
  190. require('./ffprobe')(FfmpegCommand.prototype);
  191. FfmpegCommand.ffprobe = function(file) {
  192. var instance = new FfmpegCommand(file);
  193. instance.ffprobe.apply(instance, Array.prototype.slice.call(arguments, 1));
  194. };
  195. /* Add processing recipes */
  196. require('./recipes')(FfmpegCommand.prototype);
  197. </code></pre>
  198. </article>
  199. </section>
  200. </div>
  201. <nav>
  202. <h2><a href="index.html">Index</a></h2><ul><li><a href="index.html#installation">Installation</a></li><ul></ul><li><a href="index.html#usage">Usage</a></li><ul><li><a href="index.html#prerequisites">Prerequisites</a></li><li><a href="index.html#creating-an-ffmpeg-command">Creating an FFmpeg command</a></li><li><a href="index.html#specifying-inputs">Specifying inputs</a></li><li><a href="index.html#input-options">Input options</a></li><li><a href="index.html#audio-options">Audio options</a></li><li><a href="index.html#video-options">Video options</a></li><li><a href="index.html#video-frame-size-options">Video frame size options</a></li><li><a href="index.html#specifying-multiple-outputs">Specifying multiple outputs</a></li><li><a href="index.html#output-options">Output options</a></li><li><a href="index.html#miscellaneous-options">Miscellaneous options</a></li><li><a href="index.html#setting-event-handlers">Setting event handlers</a></li><li><a href="index.html#starting-ffmpeg-processing">Starting FFmpeg processing</a></li><li><a href="index.html#controlling-the-ffmpeg-process">Controlling the FFmpeg process</a></li><li><a href="index.html#reading-video-metadata">Reading video metadata</a></li><li><a href="index.html#querying-ffmpeg-capabilities">Querying ffmpeg capabilities</a></li><li><a href="index.html#cloning-an-ffmpegcommand">Cloning an FfmpegCommand</a></li></ul><li><a href="index.html#contributing">Contributing</a></li><ul><li><a href="index.html#code-contributions">Code contributions</a></li><li><a href="index.html#documentation-contributions">Documentation contributions</a></li><li><a href="index.html#updating-the-documentation">Updating the documentation</a></li><li><a href="index.html#running-tests">Running tests</a></li></ul><li><a href="index.html#main-contributors">Main contributors</a></li><ul></ul><li><a href="index.html#license">License</a></li><ul></ul></ul><h3>Classes</h3><ul><li><a href="FfmpegCommand.html">FfmpegCommand</a></li><ul><li> <a href="FfmpegCommand.html#audio-methods">Audio methods</a></li><li> <a href="FfmpegCommand.html#capabilities-methods">Capabilities methods</a></li><li> <a href="FfmpegCommand.html#custom-options-methods">Custom options methods</a></li><li> <a href="FfmpegCommand.html#input-methods">Input methods</a></li><li> <a href="FfmpegCommand.html#metadata-methods">Metadata methods</a></li><li> <a href="FfmpegCommand.html#miscellaneous-methods">Miscellaneous methods</a></li><li> <a href="FfmpegCommand.html#other-methods">Other methods</a></li><li> <a href="FfmpegCommand.html#output-methods">Output methods</a></li><li> <a href="FfmpegCommand.html#processing-methods">Processing methods</a></li><li> <a href="FfmpegCommand.html#video-methods">Video methods</a></li><li> <a href="FfmpegCommand.html#video-size-methods">Video size methods</a></li></ul></ul>
  203. </nav>
  204. <br clear="both">
  205. <footer>
  206. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Sun May 01 2016 12:10:37 GMT+0200 (CEST)
  207. </footer>
  208. <script> prettyPrint(); </script>
  209. <script src="scripts/linenumber.js"> </script>
  210. </body>
  211. </html>