-
Notifications
You must be signed in to change notification settings - Fork 45
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
Stream preview #157
base: master
Are you sure you want to change the base?
Stream preview #157
Conversation
commit: |
The function to set stream preview is now available in the library guild.members.me.voice.postPreview(base64img) To be more precise, it has been available for several versions already |
Does it work with this library handling the voice connection? If yes then I'll close |
It will work with this library, but it requires users to clearly specify which server's voice channel they are connecting to (for example, if they are connecting to server A, they will need to retrieve their own VoiceState). Alternatively, you can use this library's APIRequest to create a more secure request (there might be a typing error for ts, I will fix it to be a public property later) |
Alright so we have a bit of a problem regarding keyframe extraction. There are 3 options, with varying level of annoyance
Since option 1 changes nothing API-wise, I'll try to build libav.js and see how difficult it is to work with Emscripten |
Not too hard I'd say https://www.npmjs.com/package/@lng2004/libav.js-variant-webcodecs-avf-with-decoders |
A little late since you've already done it with libav.js
You can also use https://github.com/dank074/fluent-ffmpeg-multistream-ts for multiple outputs/inputs |
That is option 3 above (extra mkv stream containing the decoded keyframes). I wanted to avoid it since that means running 2 demuxer instances, which I don't like, and it also requires us to pass an extra stream around, which is not ideal. |
You're right, that's actually option 3, sorry misunderstood at first glance |
I screwed up the last build, let's try again
115711d
to
3ab1b2f
Compare
It works! For performance: Decoding, resizing and encode to jpg a 1920x1080 H.264/5 keyframe on an i3-330M takes ~1s, and increases the CPU usage to 30%, which is actually better than I expected, considering that there are no SIMD optimizations. Since we only decode once every 5s (which is overkill even, since Discord doesn't load the preview that often), this is acceptable for me. |
Let's see if this is the source of the issue
Leak is gone, I used the wrong free function... (note to self: if there's a function |
This version enables `O3` optimization level
With Again, big disclaimer that this doesn't work on Deno or Bun, and trying to enable it anyway will result in catastrophic failure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about the delay, somehow my comment stayed as pending and was never actually submitted
Just one comment
const { streamKey } = this.voiceConnection.streamConnection; | ||
const data = `data:image/jpeg;base64,${image.toString("base64")}`; | ||
|
||
await fetch(`https://discord.com/api/v9/streams/${streamKey}/preview`, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you find that aiko's library postPreview
or APIRequest wouldn't work here? I think it's a good idea to try to stick to it as much as possible to prevent getting possibly detected by Discord anti bot measures since the HTTP headers between requests might potentially be different (e.g. user-agent)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it exported yet? I'll have a look later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code snippet
const voiceState = client.guilds.cache.get(server_id).members.me.voice;
await voiceState.postPreview('base64image');
// If error code is USER_NOT_STREAMING, try setting the property 'streaming' to true
// If this error occurs, it may be because the VOICE_STATE_UPDATE event is not cached properly
voiceState.streaming = true;
await voiceState.postPreview('base64image');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be simpler to just do
await this.client.user.voice.postPreview(data);
since users can't join multiple voice channels anyway (bots can, as long as they're in separate servers)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we expose the APIRequest
thing for now? It's kinda weird for us to re-query information that we already have (but then again we already kinda did that in some ways so I'll try the suggestion above)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be simpler to just do
await this.client.user.voice.postPreview(data);since users can't join multiple voice channels anyway (bots can, as long as they're in separate servers)
Users can also join multiple voice channels across different servers
Only took 2 months since #133 was made...
Should keyframe extraction be in this repo though, or it should be in https://github.com/Discord-RE/FFmpeg-input-premade?