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.0.tar.gz (728.7 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.0-py3-none-any.whl (40.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: discord_video_stream_py-0.1.0.tar.gz
  • Upload date:
  • Size: 728.7 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.0.tar.gz
Algorithm Hash digest
SHA256 0a318ee5474f8b79169e122170b7c22d66659987583969e462707bfdd5b82244
MD5 87a92d8b8c50011c2e7aa19f10d486b4
BLAKE2b-256 d33522fa4516cd80cebe2bac23f6278421e554a96729e216122947b84500ed8a

See more details on using hashes here.

Provenance

The following attestation bundles were made for discord_video_stream_py-0.1.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for discord_video_stream_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b93dc1d368e8ffac13052fbc54b044d4f8fd02b4c81a164830b65aa64137e6b
MD5 d776dc9040a2f01f0e82994565e35a53
BLAKE2b-256 1656a112718ea951875009bc845bad9319732be593ad38729c0bdb9c70367c3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for discord_video_stream_py-0.1.0-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