Stream your Windows desktop to Kodi.
+------------[Windows PC]-----------+
| +--------+ +-------+ | +------+
| | ffmpeg |<--[RTMP]-->| srs |<-+--[RTMP]-->| kodi |
| +--------+ +-------+ | +------+
| ^ ^ | ^
| | | | |
| +----+--------------------+---+ | |
| | desktop2kodi.py |--+--[JSON-RPC]---+
| +-----------------------------+ |
+-----------------------------------+
This Python script is executed on the streaming Windows host and integrates these functions:
- launch SRS background process as RTMP server
- launch ffmpeg background process to start A/V-grabbing, encoding and streaming to RTMP server
- employ Kodi's JSON-RPC interface to start playing from RTMP server
- mute the streaming host's desktop speakers while streaming (Windows only)
The script ends when you press Q
, it will stop SRS, ffmpeg and kodi and will unmute your desktop speakers.
You need to install Python 3, ffmpeg, and a clone of this repository. For Windows it is recommended to also install screen-capture-recorder-to-video-windows-free for an audio capture device. You will also need to install SRS.
Create a copy of desktop2kodi.ini.template
and name it desktop2kodi.ini
. This INI file mostly revolves around FFmpeg configuration, and it is the only file you need to edit. Edit your copy as needed, most importantly try to employ a GPU-accelerated video encoder.
This software was developed and tested with a GPU from NVIDIA and a Raspberry Pi 4.
This project's ffmpeg pipeline has a fixed layout:
+---------+ +---------+
| Screen | | Audio |
| grabber | | grabber |
+----+----+ +----+----+
| |
+----V----+ +----V----+
| Video | | Audio |
| encoder | | encoder |
+----+----+ +----+----+
| |
+----V---------------V----+ +-------------+
| FLV/RTMP muxer |----//---->| Kodi device |
+-------------------------+ +-------------+
The grabbers "Screen grabber" and "Audio grabber" depend on the streaming host's operating system. The video grabber should capture the desktop screen as fast as possible. Any audio grabber will do, but in this use case we prefer "unmutable" audio grabbers (that is an audio grabber that is not muted when the desktop speakers are muted).
- General
- Capturing your Desktop / Screen Recording
- ffmpeg Input Devices
- ffmpeg HWAccelIntro - see "Platform API Availability" and "FFmpeg API Implementation Status"
- Windows
- gdigrab (recommended)
- Linux
- Windows
- Install FOSS screen-capture-recorder-to-video-windows-free and use its
virtual-audio-capturer
as an unmutable audio grabber device (recommended)
- Install FOSS screen-capture-recorder-to-video-windows-free and use its
- Linux
Preferred video encoding format is H.265/HEVC, H.264 is considered only as a fallback in case H.265 is too demanding for either the encoding host or the decoding device. Using a GPU-accelerated encoder on the streaming host is most likely a requirement if you aim for 60fps at 1080p. Usually the decoding device has less computing power than the encoding host, start by identifying hardware-accelerated decoders for the device and then see if you find an accelerated encoder for your streaming host that encodes in the device's preferred format.
- GPU-accelerated video encoders (Windows and Linux, recommended)
- hevc_nvenc: NVIDIA GPU-accelerated H.264/H.265 encoder, see here for supported cards
- libmfx: Intel GPU-accelerated encoder
- AMD (Windows): see
h264_amf
andhevc_amf
- AMD (Linux): see h264_vaapi and hevc_vaapi
- CPU-based video encoders (for all platforms)
You can always reduce the load by lowering fps (to 30, for example) and/or screen resolution (to 720p, for example).
Audio encoder is AAC, the successor to MP3.
- AAC (recommended)