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
+29
-20
No files matched your search
+5
-1
@@ -10,9 +10,13 @@ crate-type = ["cdylib"]
|
||||
dasp = { version = "0.11.0" }
|
||||
napi = { git = "https://github.com/napi-rs/napi-rs", default-features = false, features = [
|
||||
"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"] }
|
||||
tokio = { version = "1", features = ["default"] }
|
||||
|
||||
[build-dependencies]
|
||||
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 stream = createReadStream('./media.mp3');
|
||||
const { result } = mediaplex.probeStream(stream);
|
||||
const { result } = await mediaplex.probeStream(stream);
|
||||
|
||||
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.
|
||||
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
|
||||
|
||||
@@ -74,7 +83,7 @@ const encoded = encoder.encode(buffer);
|
||||
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
|
||||
|
||||
|
||||
+6
-3
@@ -2,7 +2,7 @@ const fs = require('fs');
|
||||
const { probeStream, readMetadata } = require('../index.js');
|
||||
|
||||
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) => {
|
||||
require('https').get(url, resolve);
|
||||
});
|
||||
@@ -11,8 +11,11 @@ const stream = new Promise((resolve, reject) => {
|
||||
* @param {Buffer} chunk
|
||||
*/
|
||||
async function main() {
|
||||
const probeResult = await probeStream(await stream);
|
||||
console.log(probeResult.result);
|
||||
const s = await stream;
|
||||
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));
|
||||
/*
|
||||
{
|
||||
|
||||
@@ -62,24 +62,17 @@ async function probeStream(
|
||||
};
|
||||
|
||||
const onClose = () => {
|
||||
finish(resolved || null);
|
||||
};
|
||||
|
||||
|
||||
const onData = (buffer) => {
|
||||
readBuffer = Buffer.concat([readBuffer, buffer]);
|
||||
|
||||
try {
|
||||
const result = binding.probe(readBuffer);
|
||||
if (result != null) resolved = result;
|
||||
|
||||
if (result && ![
|
||||
CodecType.MP3,
|
||||
CodecType.MP1,
|
||||
CodecType.MP2,
|
||||
].some(c => resolved.codec === c)) return finish(result);
|
||||
} catch { }
|
||||
|
||||
finish(resolved || null);
|
||||
};
|
||||
|
||||
const onData = (buffer) => {
|
||||
readBuffer = Buffer.concat([readBuffer, buffer]);
|
||||
|
||||
if (readBuffer.length >= probeSize) {
|
||||
stream.off('data', onData);
|
||||
stream.pause();
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "mediaplex",
|
||||
"version": "0.0.3",
|
||||
"version": "0.0.4",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"napi": {
|
||||
|
||||
Reference in new issue
Block a user