Skip to main content

Stream video and audio into Discord voice channels (Go Live / webcam) using Python.

Project description

discord-video-stream-py Logo

discord-video-stream-py

Stream video and audio directly into Discord voice channels (Go Live / webcam) using Python. No Node.js required.

Inspired by the TypeScript @dank074/discord-video-stream, built from the ground up for Python developers.

PyPI Python License: MIT


Features

  • ๐ŸŽฌ H264 & VP8 video streaming via Discord Go Live
  • ๐ŸŽ™๏ธ Opus audio (48 kHz stereo, 20 ms frames)
  • ๐Ÿ” Full SRTP encryption โ€” XSalsa20-Poly1305, XChaCha20-Poly1305, and AES-256-GCM
  • ๐Ÿ“บ Webcam mode (non-Go Live) and Go Live streaming
  • ๐ŸŒ Online sources via yt-dlp (YouTube, Twitch, 1000+ sites)
  • โฏ๏ธ Full playback controls: pause, resume, seek, stop
  • ๐Ÿ” Auto-reconnect with exponential backoff on voice gateway drops
  • ๐ŸŽ›๏ธ Events system โ€” on_start, on_finish, on_error, on_progress
  • ๐Ÿ“ Resolution presets โ€” 480p, 720p, 1080p, or source quality
  • ๐Ÿ”Œ Familiar discord.py-style async API

System Requirements

  • Python 3.10+
  • (Optional) ffmpeg and yt-dlp installed in your system PATH.

[!NOTE] Zero Setup Required: The library automatically downloads and bundles cross-platform static binaries for ffmpeg and yt-dlp (supporting Windows x64, Linux x64/arm64, and macOS Intel/Apple Silicon). The library will fall back to your system's ffmpeg or yt-dlp if the bundled binaries are not found.


Installation

pip install discord-video-stream-py

Quick Start

Stream a local file

import discord
from discord_video_stream import Streamer, VideoPlayer

client = discord.Client()
streamer = Streamer(client)

@client.event
async def on_ready():
    print(f"Logged in as {client.user}")
    await streamer.join_voice(guild_id=123456789, channel_id=987654321)
    udp = await streamer.create_stream(resolution="720p", fps=30, codec="h264")
    player = VideoPlayer("movie.mp4", udp)
    await player.play()

client.run("YOUR_USER_TOKEN")

Stream from YouTube

player = VideoPlayer("https://www.youtube.com/watch?v=dQw4w9WgXcQ", udp)
await player.play()

VP8 & Webcam mode

udp = await streamer.create_stream(
    resolution="480p", fps=30,
    codec="vp8", stream_type="webcam"
)
player = VideoPlayer("video.mp4", udp, codec="vp8")
await player.play()

Playback Controls

player.pause()
await player.seek(120)  # seek to 2:00
player.resume()
player.stop()

Events

@player.on("start")
async def on_start():
    print("Streaming started!")

@player.on("finish")
async def on_finish():
    await streamer.stop_stream()

@player.on("error")
async def on_error(exc):
    print(f"Stream error: {exc}")

API Reference

Streamer(client)

Wraps a discord.py-self Client and manages the stream lifecycle.

Method Description
await join_voice(guild_id, channel_id) Join a voice channel
await create_stream(resolution, fps, codec, stream_type) Start streaming, returns MediaUdp
await stop_stream() Stop the stream and clean up
await leave_voice(guild_id) Leave the voice channel

VideoPlayer(source, udp, **kwargs)

High-level media player with events.

Method Description
await play() Start playback
pause() Pause (FFmpeg keeps running)
resume() Resume playback
await seek(seconds) Seek to position (restarts FFmpeg)
stop() Stop playback
on(event)(callback) Register event callback

Enums

Enum Values
Codec "h264", "vp8"
StreamType "go_live", "webcam"
Resolution "480p", "720p", "1080p", "source"

Development Status

Phase Status Description
1 โ€” Foundation โœ… Complete Voice Gateway + Audio streaming
2 โ€” Video (H264) โœ… Complete H264 Go Live streaming + FU-A fragmentation
3 โ€” VP8 + Webcam โœ… Complete VP8 codec + webcam mode
4 โ€” yt-dlp + DX โœ… Complete Online sources + player events + seek
5 โ€” Release ๐Ÿšง In Progress PyPI publish + docs + tests

Architecture

discord_video_stream/
โ”œโ”€โ”€ __init__.py          # Public API: Streamer, VideoPlayer, enums
โ”œโ”€โ”€ streamer.py          # Main entry point โ€” wraps discord.py-self client
โ”œโ”€โ”€ bin/                 # Bundled cross-platform binaries (FFmpeg & yt-dlp)
โ”‚   โ”œโ”€โ”€ windows-x64/
โ”‚   โ”œโ”€โ”€ linux-x64/
โ”‚   โ”œโ”€โ”€ linux-arm64/
โ”‚   โ”œโ”€โ”€ macos-x64/
โ”‚   โ””โ”€โ”€ macos-arm64/
โ”œโ”€โ”€ voice/
โ”‚   โ”œโ”€โ”€ gateway.py       # Voice WebSocket (all OPs, heartbeat, resume)
โ”‚   โ”œโ”€โ”€ udp.py           # MediaUdp โ€” UDP socket, RTP dispatch, keepalive
โ”‚   โ”œโ”€โ”€ rtp.py           # RTP packet builder (audio + video + extension)
โ”‚   โ””โ”€โ”€ encryption.py    # XSalsa20 / XChaCha20 / AES-256-GCM encryption
โ”œโ”€โ”€ codecs/
โ”‚   โ”œโ”€โ”€ h264.py          # NAL unit packetizer (FU-A fragmentation, SPS/PPS)
โ”‚   โ”œโ”€โ”€ vp8.py           # VP8 RTP packetizer (RFC 7741)
โ”‚   โ””โ”€โ”€ opus.py          # Opus audio framer (48kHz, 20ms)
โ”œโ”€โ”€ media/
โ”‚   โ”œโ”€โ”€ player.py        # MediaPlayer + VideoPlayer โ€” FFmpeg โ†’ RTP pipeline
โ”‚   โ”œโ”€โ”€ ffmpeg.py        # FFmpeg subprocess builder (H264/VP8/Opus)
โ”‚   โ””โ”€โ”€ ytdlp.py         # yt-dlp URL resolver
โ””โ”€โ”€ utils/
    โ”œโ”€โ”€ ssrc.py          # SSRC generation + video/RTX offsets
    โ””โ”€โ”€ binaries.py      # Cross-platform binary helper/resolver

Contributing

PRs welcome! See docs/getting-started.md for a development setup guide.

git clone https://github.com/subhobhai943/discord-video-stream-py.git
cd discord-video-stream-py
python -m venv venv && source venv/bin/activate
pip install -e ".[dev]"
pytest

License

MIT โ€” see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

discord_video_stream_py-0.1.1.tar.gz (729.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

discord_video_stream_py-0.1.1-py3-none-any.whl (41.1 kB view details)

Uploaded Python 3

File details

Details for the file discord_video_stream_py-0.1.1.tar.gz.

File metadata

  • Download URL: discord_video_stream_py-0.1.1.tar.gz
  • Upload date:
  • Size: 729.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for discord_video_stream_py-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f1de3a2b0cb151df80aecd5b71f5b5b8690938885b1dd69847af2e318f368b5c
MD5 f704b64b2d4e7eed3f5f2c8082716785
BLAKE2b-256 7ea6f4ffac58fcea425155858cdd4abef8340b302534b832c74379ef74ece3e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for discord_video_stream_py-0.1.1.tar.gz:

Publisher: publish.yml on subhobhai943/discord-video-stream-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file discord_video_stream_py-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for discord_video_stream_py-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ef81685b8d1d00e738bcb6f62929af720b1e5924a9d34222c5334c5e0bb8d6f9
MD5 820de4aa71e5348f4c4a4e31d8e1ebc6
BLAKE2b-256 ef0b79623965e6840a3d4822e1eb033b22b1b51190c7816db6ffa26bd5ec7d18

See more details on using hashes here.

Provenance

The following attestation bundles were made for discord_video_stream_py-0.1.1-py3-none-any.whl:

Publisher: publish.yml on subhobhai943/discord-video-stream-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page