discord-stream-rs
A Rust library for streaming audio/video to Discord voice channels via selfbot.
Port of @dank074/discord-video-stream (TypeScript) — same architecture, same protocol, native Rust performance.
⚠️ Warning: Using selfbots violates Discord's Terms of Service. Use at your own risk.
Features
- DAVE / E2EE — Full Discord end-to-end encryption via the
daveycrate (itself written in Rust) - WebRTC — ICE negotiation, DTLS-SRTP, RTP packetization via
webrtc-rs - All video codecs — H264, H265, VP8, VP9, AV1
- Hardware encoders — NVENC (NVIDIA), VA-API (Intel/AMD), or software (x264/x265)
- Media pipeline — Demux + decode any container via FFmpeg (
ffmpeg-next) - Go Live / Screen Share —
StreamConnectionfor guild streams - AV sync — PTS-based timing with cross-stream synchronization
- H264 SPS VUI rewriting — Automatically patches
max_num_reorder_frames = 0for real-time playback
Requirements
System packages (Ubuntu/Debian):
Rust: edition 2024 (Rust ≥ 1.85)
Installation
[]
= "0.1"
= { = "1", = ["full"] }
Add to .cargo/config.toml in your project (required for FFmpeg bindings):
[]
= "/usr/lib/llvm-18/lib"
Architecture Overview
The library is transport-agnostic — it does not manage the main Discord gateway WebSocket. Instead:
- Your code maintains the main gateway WS connection
- You feed incoming dispatch events into [
Streamer::handle_event] - The
Streamerpushes outbound [GatewayPayload]s back to you via anmpscchannel - You write those payloads to the main gateway WS
This allows the library to work with any Discord WS client (custom, serenity, etc.).
Your WS Client ──dispatch events──▶ Streamer::handle_event()
◀── GatewayPayload ── gateway_tx (mpsc channel)
│
VoiceConnection
│ (voice WS, ICE, DTLS)
WebRtcWrapper
│ (RTP + DAVE E2EE)
┌──────┴──────┐
AudioStream VideoStream
│ │
send_audio_frame send_video_frame
Quick Start
1. Basic setup
use ;
use mpsc;
async
2. Handle voice events
use VoiceEvent;
while let Some = voice_events.recv.await
3. Stream a video file
use ;
use Arc;
use Mutex;
async
4. Go Live / Screen Share
// Start a Go Live stream
streamer.create_stream?;
// Stop it
streamer.stop_stream?;
// Leave voice
streamer.leave_voice;
Codec Support
| Codec | Video | Audio | Notes |
|---|---|---|---|
| H264 | ✅ | — | SPS VUI auto-patched for real-time |
| H265 | ✅ | — | |
| VP8 | ✅ | — | |
| VP9 | ✅ | — | |
| AV1 | ✅ | — | |
| Opus | — | ✅ | Only supported audio codec |
Hardware Encoder Settings
Software (CPU)
use ;
use ;
let encoders = build;
// encoders.h264.name == "libx264"
// encoders.h264.options == ["-forced-idr 1", "-tune zerolatency", "-preset veryfast"]
NVENC (NVIDIA GPU)
use ;
let encoders = build;
// encoders.h264.name == "h264_nvenc"
VA-API (Intel / AMD)
use ;
let encoders = build;
// encoders.h264.name == "h264_vaapi"
// encoders.h264.global_options == ["-vaapi_device", "/dev/dri/renderD128"]
Stream Key Utilities
use ;
// Generate
let key = generate_stream_key;
// → "guild:guild_id:channel_id:user_id"
// Parse
let parsed = parse_stream_key.unwrap;
assert_eq!;
assert_eq!;
H264 Processing Utilities
use ;
// Split Annex-B stream into individual NALUs
let nalus = split_nalu;
// Check NALU type
let unit_type = nal_unit_type;
// Rewrite SPS VUI (max_num_reorder_frames = 0)
let patched_sps = rewrite_sps_vui;
Crate Structure
discord-stream-rs
├── dave — DAVE E2EE session wrapper
├── gateway — Main gateway opcodes, events, Streamer controller
├── voice — Voice WS state machine, WebRTC wrapper, codec constants
├── processing — H264 Annex-B bitstream reader/writer, SPS VUI rewriter
└── media — FFmpeg demuxer, decoder, audio/video streams, encoder settings
Credits
- Original TypeScript library:
@dank074/discord-video-stream - DAVE E2EE Rust crate:
daveyby @snazzah - WebRTC:
webrtc-rs
License
MIT