dank074 / Discord-video-stream

Experiment for making video streaming work for discord selfbots.
180 stars 32 forks source link

H265 support #71

Closed longnguyen2004 closed 6 months ago

longnguyen2004 commented 7 months ago

This is a fairly big PR, since it also included various code reorganization, but the summary of all the changes are:

Stuff that doesn't work right now:

longnguyen2004 commented 7 months ago

Some screenshots image image

longnguyen2004 commented 7 months ago

For NVENC, these errors are outputted into the discord_voice log

[2024-03-03 11:29:40.573] [17108] (packet_buffer.cc:337): Found an H.265 key frame
[2024-03-03 11:29:40.576] [9480] (h265_decoder_impl.cpp:395): avcodec_send_packet error: -1094995529
[2024-03-03 11:29:40.576] [9480] (generic_decoder.cc:302): Failed to decode frame with timestamp 2610000, error code: -1

-1094995529 corresponds to AVERROR_INVALIDDATA, and that's where I'm at right now. ~I haven't found a way to get ffmpeg logs yet, so I have no clues what's wrong with the NVENC bitstream.~ All ffmpeg logging is disabled by Chromium on official builds :( The probability of Discord enabling ffmpeg logs on their own build (if they even build Electron from scratch at all) is probably slim...

longnguyen2004 commented 7 months ago

After a couple more hours of looking at the code and debugging, I failed to find anything wrong with the code. Considering that HEVC is still not popular on the web, and decoding HEVC in the Discord app is still not hardware accelerated, I don't think it's worth the time to go deeper into. The fact that it works with AMD HEVC is probably enough to say that it's "working".

longnguyen2004 commented 7 months ago

Even x265 isn't working...If someone can look into this I'd very appreciate it, but I'll have to call it there for now. AV1 is more important anyway.

longnguyen2004 commented 7 months ago

Turns out I couldn't let it be a cliffhanger, so I went through with it and eventually found the culprit. See the commit for more info. All it took is a custom build of FFmpeg, and 20GB of Chromium source code...

Now, this is truly complete :)

dank074 commented 7 months ago

Awesome job! I'm looking forward to looking through the code. Having a hectic week and been out of town so I won't be able to look at it until early next week. Can't wait!

longnguyen2004 commented 7 months ago

I have another PR coming, so stay tuned for that. It's optimization related though, so I figured I'd split it out and submit it later.

longnguyen2004 commented 6 months ago

Hello, how is this going now?