-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to save opus stream to a file? #68
Comments
https://github.com/amishshah/prism-media#what-is-it // This example will demux and decode an Opus-containing OGG file, and then write it to a file.
const prism = require('prism-media');
const fs = require('fs');
fs.createReadStream('./audio.ogg')
.pipe(new prism.opus.OggDemuxer())
.pipe(new prism.opus.Decoder({ rate: 48000, channels: 2, frameSize: 960 }))
.pipe(fs.createWriteStream('./audio.pcm')); // <-- |
@Mesteery's solution is the closest thing you can do at the moment. I have plans to add an Ogg containeriser (is that a word?) stream to let you save Opus streams in .ogg files, but that will have to wait until the TypeScript refactor. |
Thanks @Mesteery, but I meant Opus stream, not raw/pcm.
Ogg Muxer?
Could you please elaborate? Why TypeScript? |
@OnkelTem at the moment I'm prioritising refactoring the library to TypeScript to make it easier for me to maintain and add new features. I'd much rather write the Ogg muxer once in TypeScript, than have to port it from JavaScript to TypeScript. However, I think I have a solution for this use-case in the meantime, see https://gist.github.com/amishshah/1f7e202dfb8f5595ebb19b9338a4d8f2 This will allow you to send your Opus streams to some other place (e.g. send them across processes, write to filesystem) and then recover them safely. Example usage: Saving an Opus stream to filesystem: createReadStream('file.ogg')
.pipe(new prism.opus.OggDemuxer())
.pipe(new Serialiser())
.pipe(createWriteStream('file.nodestream')) Later re-reading the Opus stream: createReadStream('file.nodestream')
.pipe(new Deserialiser())
// now you have the original Opus packet object stream back Essentially, it is a very lightweight alternative to the .ogg format and so it doesn't contain support for metadata, it stores only the Opus packets. Until I get the time to write the Ogg Muxer (I'm reluctant to call it this, since I'm planning on only supporting one input stream anyway), I think that this is a more than adequate solution. |
It's nice to hear that you support TypeScript, you have my vote on this! I think I got the idea of your proposition of dumping packets. |
This is now being implemented in #70 🎉 |
Cool, gonna test it! |
Is there a way to save an Opus stream into a file using prism-media?
The text was updated successfully, but these errors were encountered: