Janus WebRTC async client in Python.
Project description
Janus Client in Python
A Janus webrtc client written in Python, to be used with asyncio.
Install
pip install janus-client
Description
The package is implementing a general purpose client that can communicate with Janus webrtc server.
The VideoRoom plugin implemented in plugin_video_room_ffmpeg.py uses FFmpeg instead. It depends on the ffmpeg-cli, and that is required to be installed separately.
FFmpeg Stream To WebRTC (WARNING !!!)
This FFmpeg stream to WebRTC solution is a hack. The fact is that FFmpeg doesn't support WebRTC and aiortc is implemented using PyAV. PyAV has much less features than a full fledged installed FFmpeg, so to support more features and keep things simple, I hacked about a solution without the use of neither WHIP server nor UDP nor RTMP.
First the ffmpeg input part should be constructed by the user, before passing it to JanusVideoRoomPlugin.publish
. When the media player needs to stream the video, the following happens:
- A thread will be created and a ffmpeg process will be created. Output of ffmpeg is hardcoded to be
rawvideo rgb24
. - Thread reads output of ffmpeg process.
- Coverts the output data to numpy array and then to
av.VideoFrame
frame. - Hack the
pts
andtime_base
parameter of the frame. I don't know what it is and just found a value that works. - Put the frame into video track queue to be received and sent by
aiortc.mediastreams.MediaStreamTrack
.
References:
Features
:heavy_check_mark: Connect to Janus server through:
- Websocket API (websockets)
- HTTP (aiohttp)
:heavy_check_mark: Automatically manage Janus client connection
:heavy_check_mark: Manage message transactions with Janus
:heavy_check_mark: Manage sessions
from janus_client import JanusSession
# Protocol will be derived from base_url
session = JanusSession(
base_url="wss://janusmy.josephgetmyip.com/janusbasews/janus",
)
# OR
session = JanusSession(
base_url="https://janusmy.josephgetmyip.com/janusbase/janus",
)
:heavy_check_mark: Manage plugins
:heavy_check_mark: Manage multiple sessions and or multiple plugins at the same time
from janus_client import JanusVideoRoomPlugin
plugin_handle_1 = JanusVideoRoomPlugin()
plugin_handle_2 = JanusVideoRoomPlugin()
# Attach to Janus session
await plugin_handle_1.attach(session=session)
await plugin_handle_2.attach(session=session)
:heavy_check_mark: Support authentication with shared static secret (API key) and/or stored token
:heavy_check_mark: Expose Admin/Monitor API client
:heavy_check_mark: Use Janus VideoRoom plugin with FFmpeg
import ffmpeg
room_id = 1234
publisher_id = 333
display_name = "qweqwe"
width = 640
height = 480
ffmpeg_input = ffmpeg.input(
"desktop",
format="gdigrab",
framerate=30,
offset_x=20,
offset_y=30,
video_size=[
width,
height,
],
show_region=1,
)
await plugin_handle_1.join(room_id, publisher_id, display_name)
await plugin_handle_1.publish(ffmpeg_input=ffmpeg_input, width=width, height=height)
await asyncio.sleep(60)
await plugin_handle_1.unpublish()
TODO
:clock3: Emit events to respective session and plugin handlers
:clock3: Documentation
:clock3: Publish audio with FFmpeg VideoRoom plugin
:clock3: Subscribe to stream with FFmpeg VideoRoom plugin
Usage
Use test_ffmpeg.py to try streaming a portion of monitor display to Janus videoroom demo.
Result:
Delay of 0.175s
Server ping:
Support for GStreamer VideoRoom plugin has been deprecated since v0.2.5
Contributions to migrate the plugin to latest JanusPlugin
API would be greatly appreciated.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file janus_client-0.4.1.tar.gz
.
File metadata
- Download URL: janus_client-0.4.1.tar.gz
- Upload date:
- Size: 18.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.4 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1282210b25ddb8c2a098b0f29ccc6cea310743011cfdd167cf347729f46a958 |
|
MD5 | 84f29ef4948f66bf39066d5003bfad64 |
|
BLAKE2b-256 | 25d95c1e221a8b3cd3c2d87b8bd6f515df45873caabf86cf0d007a811592949e |
File details
Details for the file janus_client-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: janus_client-0.4.1-py3-none-any.whl
- Upload date:
- Size: 24.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.4 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd35a71a6305b678c2e0bf9cba31cae9b8c162c0b8deed444bb82ffed7fb1d18 |
|
MD5 | 6b9ea43453cfdff080975572b1f97d37 |
|
BLAKE2b-256 | 9b975f1910d59cdb9de9894527d79a2374709102042e3d8c914fe10e22ab6cd8 |