Skip to content
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

use ffmpeg for opus encoding #11

Closed
nhooyr opened this issue Jul 5, 2017 · 7 comments
Closed

use ffmpeg for opus encoding #11

nhooyr opened this issue Jul 5, 2017 · 7 comments

Comments

@nhooyr
Copy link

nhooyr commented Jul 5, 2017

I've been writing a discord bot in elixir using this library https://github.com/cronokirby/alchemy

Unlike this library where an opus library is used, the author uses ffmpeg for opus encoding directly from the file stream. In order to do this, ffmpeg has to be compiled with libopus support. On macOS, its as simple as brew install ffmpeg --with-opus.

I've ported it over to Go. It's very crude and only for demonstration purposes but it works really well and eliminates the need for a executable like dca-rs or a go opus library.

https://github.com/nhooyr/botatouille/blob/7e1cd9d5a8d517fd43fd11599b2a62bf832a5c96/cmd/botatouille/music/music.go#L62-L104

Only issue is that if the goroutine reading from ffmpeg's stdout ever falls behind ffmpeg, it may read more than a single frame. Then it will try and send more than a single frame to discord which will cause the audio to get completely screwed up. I wanted to know if you think there is any way to fix this.

I think its highly unlikely because the goroutine has its own thread and is only reading from ffmpeg and not doing anything else but I'm not 100% sure. What do you think?

If you like this method, I can incorporate it into this library.

@bwmarrin
Copy link
Owner

bwmarrin commented Jul 5, 2017

It's a great idea, but I think it should just be another example repo. This repo specifically needs to almost be removed and re-wrote if anything. But I'd hate to make such an API change to it since I know folks are using it.

Make a nice repo and tag it with discordgo :) I can add it to the discordgo wiki too. I think one downfall of the ffmpeg route is you loose some of the config options possible for opus, right? Like VBA vs Constant and maybe some other things? But, it is a nice way of doing it. Less complicated.

I think the best thing about .dca is really that you can pre-encode the files in advance for things you play often and save them in .dca files that are ready to play.

@cocoastorm
Copy link

@nhooyr, hey did you ever end up making a repo with using ffmpeg to encode with gopus directly? thanks 👍

@nhooyr
Copy link
Author

nhooyr commented Mar 9, 2019

Unfortunately I gave up on this.

@cocoastorm
Copy link

ah okie that's a shame, but thanks anyways! 👍

@nhooyr
Copy link
Author

nhooyr commented Nov 22, 2019

Going to close as it has been a long time and I'm not sure if this is relevant anymore.

@nhooyr nhooyr closed this as completed Nov 22, 2019
@forscht
Copy link

forscht commented Jul 16, 2023

@nhooyr I am working something similar, did you find something ?

@nhooyr
Copy link
Author

nhooyr commented Jul 17, 2023

Nope, never ended up continuing with my project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants