dank074 / Discord-video-stream

Experiment for making video streaming work for discord selfbots.
183 stars 35 forks source link

Great library! Some concerns... #37

Open JustAHippo opened 1 year ago

JustAHippo commented 1 year ago

Why is the bitrate so far gone, why is Hardware accel off by default, why Ultrafast, why 720P, heck, why even re-encode a video that is allowed by discord's bitrate standards?

dank074 commented 1 year ago

Hardware acceleration is off by default because not all environments support it, and it will just exit ffmpeg with error if it isn't supported. It's very easy to enable it though so I didn't see it as an issue.

Bitrate and resolution are also customizable, and very easy to set your own so I didn't see an issue with setting it to discord's default value.

I set the encoding to ultrafast because that's the recommended setting to use for least amount of latency when live streaming. Maybe we can make this customizable for better usability.

Re-encoding because I had to set a bitstream filter on h264 to insert access unit delimiters so that I can chunk frames properly in the h264 transformer class. Also, rtp h264 spec is very restrictive about the format of the h264 video. It must be baseline and use certain pixel format. Discord also added extra restrictions and the video must have a fixed key frame interval (this actually gave me a headache or two because I couldn't figure out why my h264 packetizer ended up rendering black screen on discord, when it was a key frame issue and not an error on my packetizer)

Pull requests are accepted if you find a solution to any of the above. Cheers

JustAHippo commented 1 year ago

Thanks for the response! Most of it looks fine, I found out how to change and customize all of those settings. The last question I have is where the ffmpeg process is outputting to

dank074 commented 1 year ago

Thanks for the response! Most of it looks fine, I found out how to change and customize all of those settings. The last question I have is where the ffmpeg process is outputting to

It outputs two streams: one for audio and one for video to a Unix socket (uses https://github.com/dank074/fluent-ffmpeg-multistream-ts) and then those sockets are piped into some codec transformers/frame splitter and finally to AudioStream or VideoStream which buffers the data and sends it to discord