mirror of
https://github.com/darksaid98/mediaplex.git
synced 2026-12-01 14:38:45 +00:00
0.0.4
This commit is contained in:
1 parent
63876ab463
commit
a8acd04d04
5 files changed
+30
-21
No files matched your search
+5
-1
@@ -10,9 +10,13 @@ crate-type = ["cdylib"]
|
|||||||
dasp = { version = "0.11.0" }
|
dasp = { version = "0.11.0" }
|
||||||
napi = { git = "https://github.com/napi-rs/napi-rs", default-features = false, features = [
|
napi = { git = "https://github.com/napi-rs/napi-rs", default-features = false, features = [
|
||||||
"napi4",
|
"napi4",
|
||||||
|
"tokio_rt",
|
||||||
|
] }
|
||||||
|
napi-derive = { git = "https://github.com/napi-rs/napi-rs", features = [
|
||||||
|
"compat-mode",
|
||||||
] }
|
] }
|
||||||
napi-derive = { git = "https://github.com/napi-rs/napi-rs" }
|
|
||||||
symphonia = { version = "0.5.3", features = ["all"] }
|
symphonia = { version = "0.5.3", features = ["all"] }
|
||||||
|
tokio = { version = "1", features = ["default"] }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
napi-build = { git = "https://github.com/napi-rs/napi-rs" }
|
napi-build = { git = "https://github.com/napi-rs/napi-rs" }
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ You can use Mediaplex to probe media files for metadata. Here's an example:
|
|||||||
const mediaplex = require('mediaplex');
|
const mediaplex = require('mediaplex');
|
||||||
|
|
||||||
const stream = createReadStream('./media.mp3');
|
const stream = createReadStream('./media.mp3');
|
||||||
const { result } = mediaplex.probeStream(stream);
|
const { result } = await mediaplex.probeStream(stream);
|
||||||
|
|
||||||
console.log(result);
|
console.log(result);
|
||||||
|
|
||||||
@@ -58,6 +58,15 @@ console.log(result);
|
|||||||
```
|
```
|
||||||
|
|
||||||
This will output an object containing information about the media file, including the number of channels, sample rate, codec, duration, and metadata.
|
This will output an object containing information about the media file, including the number of channels, sample rate, codec, duration, and metadata.
|
||||||
|
The default probe size is `10MB`, but you can adjust this as needed by passing the second argument to `probeStream`:
|
||||||
|
|
||||||
|
```js
|
||||||
|
// probe only 1024 bytes
|
||||||
|
const { result } = await mediaplex.probeStream(stream, 1024);
|
||||||
|
|
||||||
|
// probe 5 MB
|
||||||
|
const { result } = await mediaplex.probeStream(stream, 5 * 1024 * 1024);
|
||||||
|
```
|
||||||
|
|
||||||
## Opus Encoder
|
## Opus Encoder
|
||||||
|
|
||||||
@@ -74,7 +83,7 @@ const encoded = encoder.encode(buffer);
|
|||||||
const decoded = encoder.decode(encoded);
|
const decoded = encoder.decode(encoded);
|
||||||
```
|
```
|
||||||
|
|
||||||
You can use `OpusEncoder` to encode pcm data to opus and decode opus data to pcm format.
|
You can use `OpusEncoder` to encode pcm data to opus and decode opus data to pcm format. Stream interface is provided by [@discord-player/opus](https://npm.im/@discord-player/opus) package.
|
||||||
|
|
||||||
#### Opus Benchmarks
|
#### Opus Benchmarks
|
||||||
|
|
||||||
@@ -122,4 +131,4 @@ Finished 4 cases!
|
|||||||
Slowest: opusscript (no wasm)
|
Slowest: opusscript (no wasm)
|
||||||
```
|
```
|
||||||
|
|
||||||
These benchmarks compare the performance of Mediaplex's Opus encoder/decoder to other popular Opus libraries.
|
These benchmarks compare the performance of Mediaplex's Opus encoder/decoder to other popular Opus libraries.
|
||||||
+6
-3
@@ -2,7 +2,7 @@ const fs = require('fs');
|
|||||||
const { probeStream, readMetadata } = require('../index.js');
|
const { probeStream, readMetadata } = require('../index.js');
|
||||||
|
|
||||||
const url = "https://cdn.discordapp.com/attachments/1128739211701395518/1134561530885705738/16905709686973736.mp3";
|
const url = "https://cdn.discordapp.com/attachments/1128739211701395518/1134561530885705738/16905709686973736.mp3";
|
||||||
// const stream = fs.createReadStream(`${__dirname}/test.pcm`);
|
// const stream = fs.createReadStream(`${__dirname}/test.mp3`);
|
||||||
const stream = new Promise((resolve, reject) => {
|
const stream = new Promise((resolve, reject) => {
|
||||||
require('https').get(url, resolve);
|
require('https').get(url, resolve);
|
||||||
});
|
});
|
||||||
@@ -11,8 +11,11 @@ const stream = new Promise((resolve, reject) => {
|
|||||||
* @param {Buffer} chunk
|
* @param {Buffer} chunk
|
||||||
*/
|
*/
|
||||||
async function main() {
|
async function main() {
|
||||||
const probeResult = await probeStream(await stream);
|
const s = await stream;
|
||||||
console.log(probeResult.result);
|
const start = performance.now();
|
||||||
|
const probeResult = await probeStream(s);
|
||||||
|
const end = performance.now() - start;
|
||||||
|
console.log(probeResult.result, readMetadata(probeResult.result), `Took ${end.toFixed(2)}ms`);
|
||||||
// console.log(readMetadata(probeResult.result));
|
// console.log(readMetadata(probeResult.result));
|
||||||
/*
|
/*
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -62,24 +62,17 @@ async function probeStream(
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onClose = () => {
|
const onClose = () => {
|
||||||
finish(resolved || null);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
const onData = (buffer) => {
|
|
||||||
readBuffer = Buffer.concat([readBuffer, buffer]);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = binding.probe(readBuffer);
|
const result = binding.probe(readBuffer);
|
||||||
if (result != null) resolved = result;
|
if (result != null) resolved = result;
|
||||||
|
|
||||||
if (result && ![
|
|
||||||
CodecType.MP3,
|
|
||||||
CodecType.MP1,
|
|
||||||
CodecType.MP2,
|
|
||||||
].some(c => resolved.codec === c)) return finish(result);
|
|
||||||
} catch { }
|
} catch { }
|
||||||
|
|
||||||
|
finish(resolved || null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onData = (buffer) => {
|
||||||
|
readBuffer = Buffer.concat([readBuffer, buffer]);
|
||||||
|
|
||||||
if (readBuffer.length >= probeSize) {
|
if (readBuffer.length >= probeSize) {
|
||||||
stream.off('data', onData);
|
stream.off('data', onData);
|
||||||
stream.pause();
|
stream.pause();
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "mediaplex",
|
"name": "mediaplex",
|
||||||
"version": "0.0.3",
|
"version": "0.0.4",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"types": "index.d.ts",
|
"types": "index.d.ts",
|
||||||
"napi": {
|
"napi": {
|
||||||
|
|||||||
Reference in new issue
Block a user