summaryrefslogtreecommitdiff
path: root/node_modules/prism-media
diff options
context:
space:
mode:
author8cy <[email protected]>2020-04-03 02:37:42 -0700
committer8cy <[email protected]>2020-04-03 02:37:42 -0700
commit60867fb030bae582082340ead7dbc7efdc2f5398 (patch)
tree4c6a7356351be2e4914e15c4703172597c45656e /node_modules/prism-media
parentcommenting (diff)
downloads5nical-60867fb030bae582082340ead7dbc7efdc2f5398.tar.xz
s5nical-60867fb030bae582082340ead7dbc7efdc2f5398.zip
2020/04/03, 02:34, v1.2.0
Diffstat (limited to 'node_modules/prism-media')
-rw-r--r--node_modules/prism-media/.eslintrc.json132
-rw-r--r--node_modules/prism-media/.travis.yml6
-rw-r--r--node_modules/prism-media/LICENSE201
-rw-r--r--node_modules/prism-media/README.md29
-rw-r--r--node_modules/prism-media/package.json56
-rw-r--r--node_modules/prism-media/src/Prism.js17
-rw-r--r--node_modules/prism-media/src/index.js6
-rw-r--r--node_modules/prism-media/src/opus/OggOpus.js90
-rw-r--r--node_modules/prism-media/src/transcoders/MediaTranscoder.js31
-rw-r--r--node_modules/prism-media/src/transcoders/ffmpeg/Ffmpeg.js56
-rw-r--r--node_modules/prism-media/src/transcoders/ffmpeg/FfmpegProcess.js95
-rw-r--r--node_modules/prism-media/src/util/Constants.js0
-rw-r--r--node_modules/prism-media/test/main.js19
-rw-r--r--node_modules/prism-media/test/test.js12
14 files changed, 750 insertions, 0 deletions
diff --git a/node_modules/prism-media/.eslintrc.json b/node_modules/prism-media/.eslintrc.json
new file mode 100644
index 0000000..7669dbd
--- /dev/null
+++ b/node_modules/prism-media/.eslintrc.json
@@ -0,0 +1,132 @@
+{
+ "extends": "eslint:recommended",
+ "parserOptions": {
+ "ecmaVersion": 6
+ },
+ "env": {
+ "es6": true,
+ "node": true
+ },
+ "rules": {
+ "no-extra-parens": ["warn", "all", {
+ "nestedBinaryExpressions": false
+ }],
+ "valid-jsdoc": ["error", {
+ "requireReturn": false,
+ "requireReturnDescription": false,
+ "preferType": {
+ "String": "string",
+ "Number": "number",
+ "Boolean": "boolean",
+ "Function": "function",
+ "object": "Object",
+ "date": "Date",
+ "error": "Error"
+ },
+ "prefer": {
+ "return": "returns"
+ }
+ }],
+
+ "accessor-pairs": "warn",
+ "array-callback-return": "error",
+ "complexity": "warn",
+ "consistent-return": "error",
+ "curly": ["error", "multi-line", "consistent"],
+ "dot-location": ["error", "property"],
+ "dot-notation": "error",
+ "eqeqeq": "error",
+ "no-empty-function": "error",
+ "no-floating-decimal": "error",
+ "no-implied-eval": "error",
+ "no-invalid-this": "error",
+ "no-lone-blocks": "error",
+ "no-multi-spaces": "error",
+ "no-new-func": "error",
+ "no-new-wrappers": "error",
+ "no-new": "error",
+ "no-octal-escape": "error",
+ "no-return-assign": "error",
+ "no-self-compare": "error",
+ "no-sequences": "error",
+ "no-throw-literal": "error",
+ "no-unmodified-loop-condition": "error",
+ "no-unused-expressions": "error",
+ "no-useless-call": "error",
+ "no-useless-concat": "error",
+ "no-useless-escape": "error",
+ "no-void": "error",
+ "no-warning-comments": "warn",
+ "wrap-iife": "error",
+ "yoda": "error",
+
+ "no-label-var": "error",
+ "no-shadow": "error",
+ "no-undef-init": "error",
+
+ "callback-return": "error",
+ "handle-callback-err": "error",
+ "no-mixed-requires": "error",
+ "no-new-require": "error",
+ "no-path-concat": "error",
+
+ "array-bracket-spacing": "error",
+ "block-spacing": "error",
+ "brace-style": ["error", "1tbs", { "allowSingleLine": true }],
+ "comma-dangle": ["error", "always-multiline"],
+ "comma-spacing": "error",
+ "comma-style": "error",
+ "computed-property-spacing": "error",
+ "consistent-this": ["error", "$this"],
+ "eol-last": "error",
+ "func-names": "error",
+ "func-style": ["error", "declaration", { "allowArrowFunctions": true }],
+ "indent": ["error", 2, { "SwitchCase": 1 }],
+ "key-spacing": "error",
+ "keyword-spacing": "error",
+ "max-depth": "error",
+ "max-len": ["error", 120, 2],
+ "max-nested-callbacks": ["error", { "max": 4 }],
+ "max-statements-per-line": ["error", { "max": 2 }],
+ "new-cap": "error",
+ "newline-per-chained-call": ["error", { "ignoreChainWithDepth": 3 }],
+ "no-array-constructor": "error",
+ "no-inline-comments": "error",
+ "no-lonely-if": "error",
+ "no-mixed-operators": "error",
+ "no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1, "maxBOF": 0 }],
+ "no-new-object": "error",
+ "no-spaced-func": "error",
+ "no-trailing-spaces": "error",
+ "no-unneeded-ternary": "error",
+ "no-whitespace-before-property": "error",
+ "object-curly-spacing": ["error", "always"],
+ "operator-assignment": "error",
+ "operator-linebreak": ["error", "after"],
+ "padded-blocks": ["error", "never"],
+ "quote-props": ["error", "as-needed"],
+ "quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }],
+ "semi-spacing": "error",
+ "semi": "error",
+ "space-before-blocks": "error",
+ "space-before-function-paren": ["error", "never"],
+ "space-in-parens": "error",
+ "space-infix-ops": "error",
+ "space-unary-ops": "error",
+ "spaced-comment": "error",
+ "unicode-bom": "error",
+
+ "arrow-body-style": "error",
+ "arrow-spacing": "error",
+ "no-duplicate-imports": "error",
+ "no-useless-computed-key": "error",
+ "no-useless-constructor": "error",
+ "prefer-arrow-callback": "error",
+ "prefer-rest-params": "error",
+ "prefer-spread": "error",
+ "prefer-template": "error",
+ "rest-spread-spacing": "error",
+ "template-curly-spacing": "error",
+ "yield-star-spacing": "error"
+ }
+} \ No newline at end of file
diff --git a/node_modules/prism-media/.travis.yml b/node_modules/prism-media/.travis.yml
new file mode 100644
index 0000000..e2c605c
--- /dev/null
+++ b/node_modules/prism-media/.travis.yml
@@ -0,0 +1,6 @@
+language: node_js
+node_js:
+ - node
+cache:
+ directories:
+ - node_modules \ No newline at end of file
diff --git a/node_modules/prism-media/LICENSE b/node_modules/prism-media/LICENSE
new file mode 100644
index 0000000..8dada3e
--- /dev/null
+++ b/node_modules/prism-media/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "{}"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright {yyyy} {name of copyright owner}
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/node_modules/prism-media/README.md b/node_modules/prism-media/README.md
new file mode 100644
index 0000000..9b3d822
--- /dev/null
+++ b/node_modules/prism-media/README.md
@@ -0,0 +1,29 @@
+# prism-media
+[![Build Status](https://travis-ci.org/hydrabolt/prism-media.svg?branch=master)](https://travis-ci.org/hydrabolt/prism-media)
+[![dependencies](https://david-dm.org/hydrabolt/prism-media/status.svg)](https://david-dm.org/hydrabolt/prism-media)
+[![devDependencies](https://david-dm.org/hydrabolt/prism-media/dev-status.svg)](https://david-dm.org/hydrabolt/prism-media?type=dev)
+
+Makes programmatically transcoding media easier
+
+`npm install --save hydrabolt/prism-media`
+
+```js
+const Prism = require('prism-media');
+const fs = require('fs');
+
+const prism = new Prism();
+
+const transcoder = prism.transcode({
+ type: 'ffmpeg',
+ media: './test/test.mp3',
+ ffmpegArguments: [
+ '-analyzeduration', '0',
+ '-loglevel', '0',
+ '-f', 's16le',
+ '-ar', '48000',
+ '-ac', '2',
+ ],
+});
+
+transcoder.output.pipe(fs.createWriteStream('./test/test.pcm'));
+``` \ No newline at end of file
diff --git a/node_modules/prism-media/package.json b/node_modules/prism-media/package.json
new file mode 100644
index 0000000..5529937
--- /dev/null
+++ b/node_modules/prism-media/package.json
@@ -0,0 +1,56 @@
+{
+ "_from": "prism-media@^0.0.4",
+ "_id": "[email protected]",
+ "_inBundle": false,
+ "_integrity": "sha512-dG2w7WtovUa4SiYTdWn9H8Bd4JNdei2djtkP/Bk9fXq81j5Q15ZPHYSwhUVvBRbp5zMkGtu0Yk62HuMcly0pRw==",
+ "_location": "/prism-media",
+ "_phantomChildren": {},
+ "_requested": {
+ "type": "range",
+ "registry": true,
+ "raw": "prism-media@^0.0.4",
+ "name": "prism-media",
+ "escapedName": "prism-media",
+ "rawSpec": "^0.0.4",
+ "saveSpec": null,
+ "fetchSpec": "^0.0.4"
+ },
+ "_requiredBy": [
+ "/discord.js"
+ ],
+ "_resolved": "https://registry.npmjs.org/prism-media/-/prism-media-0.0.4.tgz",
+ "_shasum": "df5ddc6463670c97ff0e9cbac3c3e0db18df326f",
+ "_spec": "prism-media@^0.0.4",
+ "_where": "E:\\Documents\\GitHub\\s5nical\\node_modules\\discord.js",
+ "author": {
+ "name": "Amish Shah",
+ "email": "[email protected]"
+ },
+ "bugs": {
+ "url": "https://github.com/hydrabolt/prism-media/issues"
+ },
+ "bundleDependencies": false,
+ "deprecated": false,
+ "description": "Makes transcoding media easier",
+ "devDependencies": {
+ "eslint": "^6.8.0"
+ },
+ "homepage": "https://github.com/hydrabolt/prism-media#readme",
+ "keywords": [
+ "audio",
+ "media",
+ "ffmpeg"
+ ],
+ "license": "Apache-2.0",
+ "main": "src/index.js",
+ "name": "prism-media",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/hydrabolt/prism-media.git"
+ },
+ "scripts": {
+ "lint": "eslint src && eslint test",
+ "test": "npm run lint"
+ },
+ "version": "0.0.4"
+}
diff --git a/node_modules/prism-media/src/Prism.js b/node_modules/prism-media/src/Prism.js
new file mode 100644
index 0000000..b2cee9e
--- /dev/null
+++ b/node_modules/prism-media/src/Prism.js
@@ -0,0 +1,17 @@
+const MediaTranscoder = require('./transcoders/MediaTranscoder');
+
+class Prism {
+ constructor() {
+ this.transcoder = new MediaTranscoder(this);
+ }
+
+ createTranscoder(...args) {
+ return this.transcode(...args);
+ }
+
+ transcode(...args) {
+ return this.transcoder.transcode(...args);
+ }
+}
+
+module.exports = Prism;
diff --git a/node_modules/prism-media/src/index.js b/node_modules/prism-media/src/index.js
new file mode 100644
index 0000000..9437f57
--- /dev/null
+++ b/node_modules/prism-media/src/index.js
@@ -0,0 +1,6 @@
+const Prism = require('./Prism');
+const MediaTranscoder = require('./transcoders/MediaTranscoder');
+
+Prism.MediaTranscoder = MediaTranscoder;
+
+module.exports = Prism;
diff --git a/node_modules/prism-media/src/opus/OggOpus.js b/node_modules/prism-media/src/opus/OggOpus.js
new file mode 100644
index 0000000..9a938cd
--- /dev/null
+++ b/node_modules/prism-media/src/opus/OggOpus.js
@@ -0,0 +1,90 @@
+const { Transform } = require('stream');
+
+const OGG_PAGE_HEADER_SIZE = 26;
+const STREAM_STRUCTURE_VERSION = 0;
+
+const OGGS_HEADER = Buffer.from('OggS'.split('').map(x => x.charCodeAt(0)));
+const OPUS_HEAD = Buffer.from('OpusHead'.split('').map(x => x.charCodeAt(0)));
+const OPUS_TAGS = Buffer.from('OpusTags'.split('').map(x => x.charCodeAt(0)));
+
+class OggOpusTransform extends Transform {
+ constructor() {
+ super();
+ this._remainder = null;
+ this._head = null;
+ }
+
+ _transform(chunk, encoding, done) {
+ if (this._remainder) {
+ chunk = Buffer.concat([this._remainder, chunk]);
+ this._remainder = null;
+ }
+
+ while (chunk) {
+ try {
+ const result = this.readPage(chunk);
+ if (result) chunk = result;
+ else break;
+ } catch (err) {
+ this.emit('error', err);
+ }
+ }
+ this._remainder = chunk;
+ done();
+ }
+
+ /**
+ * Reads a page from a buffer
+ * @param {Buffer} chunk The chunk containing the page
+ * @returns {boolean|Buffer}
+ */
+ readPage(chunk) {
+ if (chunk.length < OGG_PAGE_HEADER_SIZE) {
+ return false;
+ }
+ if (!chunk.slice(0, 4).equals(OGGS_HEADER)) {
+ throw Error(`capture_pattern is not ${OGGS_HEADER}`);
+ }
+ if (chunk.readUInt8(4) !== STREAM_STRUCTURE_VERSION) {
+ throw Error(`stream_structure_version is not ${STREAM_STRUCTURE_VERSION}`);
+ }
+
+ const pageSegments = chunk.readUInt8(26),
+ table = chunk.slice(27, 27 + pageSegments);
+
+ let sizes = [], totalSize = 0;
+
+ for (let i = 0; i < pageSegments;) {
+ let size = 0, x = 255;
+ while (x === 255) {
+ x = table.readUInt8(i);
+ i++;
+ size += x;
+ }
+ sizes.push(size);
+ totalSize += size;
+ }
+
+ if (chunk.length < 27 + pageSegments + totalSize) {
+ return false;
+ }
+
+ let start = 27 + pageSegments;
+ for (const size of sizes) {
+ const segment = chunk.slice(start, start + size);
+ const header = segment.slice(0, 8);
+ if (this._head) {
+ if (header.equals(OPUS_TAGS)) this.emit('opusTags', segment);
+ else this.push(segment);
+ } else if (header.equals(OPUS_HEAD)) {
+ this._head = segment;
+ } else {
+ throw Error(`Invalid segment ${segment}`);
+ }
+ start += size;
+ }
+ return chunk.slice(start);
+ }
+}
+
+module.exports = OggOpusTransform;
diff --git a/node_modules/prism-media/src/transcoders/MediaTranscoder.js b/node_modules/prism-media/src/transcoders/MediaTranscoder.js
new file mode 100644
index 0000000..217e34c
--- /dev/null
+++ b/node_modules/prism-media/src/transcoders/MediaTranscoder.js
@@ -0,0 +1,31 @@
+const Ffmpeg = require('./ffmpeg/Ffmpeg');
+
+const transcoders = [
+ 'ffmpeg',
+];
+
+class MediaTranscoder {
+ constructor(prism) {
+ this.prism = prism;
+ this.ffmpeg = new Ffmpeg(this);
+ }
+
+ static verifyOptions(options) {
+ if (!options) throw new Error('Options must be passed to MediaTranscoder.transcode()');
+ if (!options.type) throw new Error('Options.type must be passed to MediaTranscoder.transcode()');
+ if (!transcoders.includes(options.type)) throw new Error(`Options.type must be: ${transcoders.join(' ')}`);
+ return options;
+ }
+
+ /**
+ * Transcodes a media stream based on specified options
+ * @param {Object} options the options to use when transcoding
+ * @returns {ReadableStream} the transcodeed stream
+ */
+ transcode(options) {
+ options = MediaTranscoder.verifyOptions(options);
+ return this[options.type].transcode(options);
+ }
+}
+
+module.exports = MediaTranscoder;
diff --git a/node_modules/prism-media/src/transcoders/ffmpeg/Ffmpeg.js b/node_modules/prism-media/src/transcoders/ffmpeg/Ffmpeg.js
new file mode 100644
index 0000000..b34dadc
--- /dev/null
+++ b/node_modules/prism-media/src/transcoders/ffmpeg/Ffmpeg.js
@@ -0,0 +1,56 @@
+const ChildProcess = require('child_process');
+const FfmpegProcess = require('./FfmpegProcess');
+
+class FfmpegTranscoder {
+ constructor(mediaTranscoder) {
+ this.mediaTranscoder = mediaTranscoder;
+ this.command = FfmpegTranscoder.selectFfmpegCommand();
+ this.processes = [];
+ }
+
+ static verifyOptions(options) {
+ if (!options) throw new Error('Options not provided!');
+ if (!options.media) throw new Error('Media must be provided');
+ if (!options.ffmpegArguments || !(options.ffmpegArguments instanceof Array)) {
+ throw new Error('FFMPEG Arguments must be an array');
+ }
+ if (options.ffmpegArguments.includes('-i')) return options;
+ if (typeof options.media === 'string') {
+ options.ffmpegArguments = ['-i', `${options.media}`].concat(options.ffmpegArguments).concat(['pipe:1']);
+ } else {
+ options.ffmpegArguments = ['-i', '-'].concat(options.ffmpegArguments).concat(['pipe:1']);
+ }
+ return options;
+ }
+
+ /**
+ * Transcodes an input using FFMPEG
+ * @param {FfmpegTranscoderOptions} options the options to use
+ * @returns {FfmpegProcess} the created FFMPEG process
+ * @throws {FFMPEGOptionsError}
+ */
+ transcode(options) {
+ if (!this.command) this.command = FfmpegTranscoder.selectFfmpegCommand();
+ const proc = new FfmpegProcess(this, FfmpegTranscoder.verifyOptions(options));
+ this.processes.push(proc);
+ return proc;
+ }
+
+ static selectFfmpegCommand() {
+ try {
+ const ffmpegStatic = require('ffmpeg-static');
+ return ffmpegStatic.path || ffmpegStatic;
+ } catch (err1) {
+ try {
+ return require('ffmpeg-binaries');
+ } catch (err2) {
+ for (const command of ['ffmpeg', 'avconv', './ffmpeg', './avconv']) {
+ if (!ChildProcess.spawnSync(command, ['-h']).error) return command;
+ }
+ throw new Error('FFMPEG not found');
+ }
+ }
+ }
+}
+
+module.exports = FfmpegTranscoder;
diff --git a/node_modules/prism-media/src/transcoders/ffmpeg/FfmpegProcess.js b/node_modules/prism-media/src/transcoders/ffmpeg/FfmpegProcess.js
new file mode 100644
index 0000000..c6561a9
--- /dev/null
+++ b/node_modules/prism-media/src/transcoders/ffmpeg/FfmpegProcess.js
@@ -0,0 +1,95 @@
+const EventEmitter = require('events').EventEmitter;
+const ChildProcess = require('child_process');
+
+/**
+ * A spawned FFMPEG process
+ */
+class FfmpegProcess extends EventEmitter {
+ constructor(ffmpegTranscoder, options) {
+ super();
+ /**
+ * The ffmpeg process
+ * @type {ChildProcess}
+ */
+ this.process = ChildProcess.spawn(ffmpegTranscoder.command, options.ffmpegArguments);
+ /**
+ * The FFMPEG transcoder that created this process
+ * @type {FfmpegTranscoder}
+ */
+ this.transcoder = ffmpegTranscoder;
+ /**
+ * The input media
+ * @type {?ReadableStream|string}
+ */
+ this.inputMedia = options.media;
+
+ if (typeof this.inputMedia !== 'string') {
+ try {
+ this.connectStream(this.inputMedia);
+ } catch (e) {
+ this.emit('error', e, 'instantiation');
+ }
+ } else {
+ this.attachErrorHandlers();
+ }
+
+ this.on('error', this.kill.bind(this));
+ this.once('end', this.kill.bind(this));
+ }
+
+ /**
+ * The ffmpeg output stream
+ * @type {?ReadableStream}
+ */
+ get output() {
+ return this.process ? this.process.stdout : null;
+ }
+
+ attachErrorHandlers() {
+ this.process.stdin.on('error', e => {
+ // if not killed
+ if (this.process) {
+ this.emit('error', e, 'ffmpegProcess.stdin');
+ }
+ });
+ this.process.stdout.on('error', e => {
+ // if not killed
+ if (this.process) {
+ this.emit('error', e, 'ffmpegProcess.stdout');
+ }
+ });
+ this.process.on('error', e => this.emit('error', e, 'ffmpegProcess'));
+ this.process.stdout.on('end', () => this.emit('end'));
+ }
+
+ /**
+ * Connects an input stream to the ffmpeg process
+ * @param {ReadableStream} inputMedia the stream to pass to ffmpeg
+ * @returns {ReadableStream} the ffmpeg output stream
+ */
+ connectStream(inputMedia) {
+ if (!this.process) throw new Error('No FFMPEG process available');
+ this.inputMedia = inputMedia;
+ this.inputMedia.pipe(this.process.stdin, { end: false });
+
+ inputMedia.on('error', e => this.emit('error', e, 'inputstream', inputMedia));
+
+ this.attachErrorHandlers();
+
+ return this.process.stdout;
+ }
+
+ /**
+ * Kills the ffmpeg process
+ */
+ kill() {
+ if (!this.process) return;
+ if (this.inputMedia && this.inputMedia.unpipe) {
+ this.inputMedia.unpipe(this.process.stdin);
+ }
+ this.process.kill('SIGKILL');
+ this.process = null;
+ }
+}
+
+module.exports = FfmpegProcess;
diff --git a/node_modules/prism-media/src/util/Constants.js b/node_modules/prism-media/src/util/Constants.js
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/node_modules/prism-media/src/util/Constants.js
diff --git a/node_modules/prism-media/test/main.js b/node_modules/prism-media/test/main.js
new file mode 100644
index 0000000..495fb2e
--- /dev/null
+++ b/node_modules/prism-media/test/main.js
@@ -0,0 +1,19 @@
+/* eslint no-console: 0 */
+const Prism = require('../');
+const fs = require('fs');
+
+const prism = new Prism();
+
+const transcoder = prism.transcode({
+ type: 'ffmpeg',
+ media: './test/test.mp3',
+ ffmpegArguments: [
+ '-analyzeduration', '0',
+ '-loglevel', '0',
+ '-f', 's16le',
+ '-ar', '48000',
+ '-ac', '2',
+ ],
+});
+
+transcoder.output.pipe(fs.createWriteStream('./test/test.pcm'));
diff --git a/node_modules/prism-media/test/test.js b/node_modules/prism-media/test/test.js
new file mode 100644
index 0000000..cad8bad
--- /dev/null
+++ b/node_modules/prism-media/test/test.js
@@ -0,0 +1,12 @@
+const fs = require('fs');
+const OggOpusTransform = require('../src/opus/OggOpus');
+const opus = require('node-opus');
+
+const decoder = new opus.Decoder(48000, 2, 1920);
+
+const transformer = new OggOpusTransform();
+
+fs.createReadStream('./test/ts.ogg')
+ .pipe(transformer)
+ .pipe(decoder)
+ .pipe(fs.createWriteStream('./output.opus'));