output.js.html 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: options/output.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: options/output.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>/*jshint node:true*/
  20. 'use strict';
  21. var utils = require('../utils');
  22. /*
  23. *! Output-related methods
  24. */
  25. module.exports = function(proto) {
  26. /**
  27. * Add output
  28. *
  29. * @method FfmpegCommand#output
  30. * @category Output
  31. * @aliases addOutput
  32. *
  33. * @param {String|Writable} target target file path or writable stream
  34. * @param {Object} [pipeopts={}] pipe options (only applies to streams)
  35. * @return FfmpegCommand
  36. */
  37. proto.addOutput =
  38. proto.output = function(target, pipeopts) {
  39. var isFile = false;
  40. if (!target &amp;&amp; this._currentOutput) {
  41. // No target is only allowed when called from constructor
  42. throw new Error('Invalid output');
  43. }
  44. if (target &amp;&amp; typeof target !== 'string') {
  45. if (!('writable' in target) || !(target.writable)) {
  46. throw new Error('Invalid output');
  47. }
  48. } else if (typeof target === 'string') {
  49. var protocol = target.match(/^([a-z]{2,}):/i);
  50. isFile = !protocol || protocol[0] === 'file';
  51. }
  52. if (target &amp;&amp; !('target' in this._currentOutput)) {
  53. // For backwards compatibility, set target for first output
  54. this._currentOutput.target = target;
  55. this._currentOutput.isFile = isFile;
  56. this._currentOutput.pipeopts = pipeopts || {};
  57. } else {
  58. if (target &amp;&amp; typeof target !== 'string') {
  59. var hasOutputStream = this._outputs.some(function(output) {
  60. return typeof output.target !== 'string';
  61. });
  62. if (hasOutputStream) {
  63. throw new Error('Only one output stream is supported');
  64. }
  65. }
  66. this._outputs.push(this._currentOutput = {
  67. target: target,
  68. isFile: isFile,
  69. flags: {},
  70. pipeopts: pipeopts || {}
  71. });
  72. var self = this;
  73. ['audio', 'audioFilters', 'video', 'videoFilters', 'sizeFilters', 'options'].forEach(function(key) {
  74. self._currentOutput[key] = utils.args();
  75. });
  76. if (!target) {
  77. // Call from constructor: remove target key
  78. delete this._currentOutput.target;
  79. }
  80. }
  81. return this;
  82. };
  83. /**
  84. * Specify output seek time
  85. *
  86. * @method FfmpegCommand#seek
  87. * @category Input
  88. * @aliases seekOutput
  89. *
  90. * @param {String|Number} seek seek time in seconds or as a '[hh:[mm:]]ss[.xxx]' string
  91. * @return FfmpegCommand
  92. */
  93. proto.seekOutput =
  94. proto.seek = function(seek) {
  95. this._currentOutput.options('-ss', seek);
  96. return this;
  97. };
  98. /**
  99. * Set output duration
  100. *
  101. * @method FfmpegCommand#duration
  102. * @category Output
  103. * @aliases withDuration,setDuration
  104. *
  105. * @param {String|Number} duration duration in seconds or as a '[[hh:]mm:]ss[.xxx]' string
  106. * @return FfmpegCommand
  107. */
  108. proto.withDuration =
  109. proto.setDuration =
  110. proto.duration = function(duration) {
  111. this._currentOutput.options('-t', duration);
  112. return this;
  113. };
  114. /**
  115. * Set output format
  116. *
  117. * @method FfmpegCommand#format
  118. * @category Output
  119. * @aliases toFormat,withOutputFormat,outputFormat
  120. *
  121. * @param {String} format output format name
  122. * @return FfmpegCommand
  123. */
  124. proto.toFormat =
  125. proto.withOutputFormat =
  126. proto.outputFormat =
  127. proto.format = function(format) {
  128. this._currentOutput.options('-f', format);
  129. return this;
  130. };
  131. /**
  132. * Add stream mapping to output
  133. *
  134. * @method FfmpegCommand#map
  135. * @category Output
  136. *
  137. * @param {String} spec stream specification string, with optional square brackets
  138. * @return FfmpegCommand
  139. */
  140. proto.map = function(spec) {
  141. this._currentOutput.options('-map', spec.replace(utils.streamRegexp, '[$1]'));
  142. return this;
  143. };
  144. /**
  145. * Run flvtool2/flvmeta on output
  146. *
  147. * @method FfmpegCommand#flvmeta
  148. * @category Output
  149. * @aliases updateFlvMetadata
  150. *
  151. * @return FfmpegCommand
  152. */
  153. proto.updateFlvMetadata =
  154. proto.flvmeta = function() {
  155. this._currentOutput.flags.flvmeta = true;
  156. return this;
  157. };
  158. };
  159. </code></pre>
  160. </article>
  161. </section>
  162. </div>
  163. <nav>
  164. <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>
  165. </nav>
  166. <br clear="both">
  167. <footer>
  168. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha5</a> on Tue Jul 08 2014 21:22:19 GMT+0200 (CEST)
  169. </footer>
  170. <script> prettyPrint(); </script>
  171. <script src="scripts/linenumber.js"> </script>
  172. </body>
  173. </html>