# dlna-cast
[![PyPI version](https://badge.fury.io/py/dlna-cast.svg)](https://badge.fury.io/py/dlna-cast)
[![Downloads](https://pepy.tech/badge/dlna-cast)](https://pepy.tech/project/dlna-cast)
A cross-platform command-line tool that casts screen and media file to remote DLNA device.
## Introduction
`dlna-cast` uses `ffmpeg` to capture screen and audio, then convert them into HLS streams which could be served by a simple HTTP server. The HLS url will be send to the selected device via uPnP protocol and the screen will be casted to the remote device (smart TV, typically).
This tool is supposed to be cross-platform but currently I don't have a Linux or MacOS device at hand so it can only run on Windows now. It won't be hard to support other platforms though, as there is no platform specific dependencies.
HLS is chosen just because it is easy to implement. But the problem of HLS is its high latency (up to 5s or more) so it's definitely not for scenarios that require low latency (presentation for example). But as a trade-off the streaming quality exceeds a lot of software-based screen-casting solutions (Lebocast for example) that have been tested by myself, which make it pretty good to stream music or video playing on your PC to the supported TV.
## Install
```bash
pip install dlna-cast
```
Please ensure your Python is 3.7 or above.
### Install ffmpeg
You can install `ffmpeg` by compiling from source code, or just download the prebuild binary from https://ffmpeg.org/download.html
You need to ensure the `ffmpeg` command can be found in the `PATH` environment variable, or else you need to set `FFMPEG_BIN` or `FFMPEG_HOME` to let `dlna-cast` know where to find the command.
`dlna-cast` supports reading the environment variable from `.env` file. You can create a `.env` file under the folder you are gonna run the `dlna-cast` command with the following content.
```bash
FFMPEG_BIN=D:\ffmpeg\ffmpeg.exe
# or
FFMPEG_HOME=D:\ffmpeg
```
You can also use the `dotenv set` command to update the `.env` file and use the `dotenv list` to check result.
```bash
dotenv set FFMPEG_HOME "D:\ffmpeg"
dotenv list
```
### Install ScreenCapturerRecorder on Windows
Though `ffmpeg` is shipped with `gdigrab` to capture screens on Windows, its performance is terrible when frame rate is high. `dlna-cast` uses ScreenCapturerRecorder for the sake of performance. You need to [download](https://github.com/rdp/screen-capture-recorder-to-video-windows-free/releases) and install it before starting to cast.
## Get Started
Before you start to stream your screen to remote devices that support DLNA protocol, you need to discover available devices in your LAN by running the following command.
```bash
dlna-cast list_dlna_devices
# You will see the output if supported devices are found
HuaweiPro
Lebocast
```
And now you can cast your screen to one of the found devices by running the following command.
```bash
dlna-cast screen --dlna_device HuaweiPro
```
Or you can also set `DLNA_DEVICE` in the `.env` file so that you can skip to set `--dlna_device` next time.
```bash
dotenv set DLNA_DEVICE HuaweiPro
dlna-cast screen
```
To stop casting just press `Ctrl+C`.
## FAQ
### Linux Limitations
The default `--input_opts` on `Linux` is `-f x11grab -i $DISPLAY`, which doesn't include capturing the audio. To support audio capture you may need to install loopback device first and then provide you own `--input_opts`, for example `--input_opts='-f x11grab -i $DISPLAY -f pulse -i name_of_your_device'`.
### MacOS Limitations
Not provide default `--input_opts` on `MacOS` yet. You need to provide your own `--input_opts`, for example `--input_opts='-f avfoundation -i 1:0`
## TODO
- [ ] Support cast media file.
- [ ] Optimize devices discover.
- [ ] Optimize latency.
- [ ] Cross platform support.
Raw data
{
"_id": null,
"home_page": null,
"name": "dlna-cast",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.7",
"maintainer_email": null,
"keywords": "DLNA, ffmpeg, media, smart-tv, screen-cast, uPnP",
"author": "weihong.xu",
"author_email": "xuweihong.cn@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/2a/2e/12746e584cedcae33a879b8c02a5b094be83a60c606cb046e79f27dae2ca/dlna_cast-0.1.8.tar.gz",
"platform": null,
"description": "# dlna-cast\n[![PyPI version](https://badge.fury.io/py/dlna-cast.svg)](https://badge.fury.io/py/dlna-cast)\n[![Downloads](https://pepy.tech/badge/dlna-cast)](https://pepy.tech/project/dlna-cast)\n\n\nA cross-platform command-line tool that casts screen and media file to remote DLNA device.\n\n## Introduction\n`dlna-cast` uses `ffmpeg` to capture screen and audio, then convert them into HLS streams which could be served by a simple HTTP server. The HLS url will be send to the selected device via uPnP protocol and the screen will be casted to the remote device (smart TV, typically).\n\nThis tool is supposed to be cross-platform but currently I don't have a Linux or MacOS device at hand so it can only run on Windows now. It won't be hard to support other platforms though, as there is no platform specific dependencies.\n\nHLS is chosen just because it is easy to implement. But the problem of HLS is its high latency (up to 5s or more) so it's definitely not for scenarios that require low latency (presentation for example). But as a trade-off the streaming quality exceeds a lot of software-based screen-casting solutions (Lebocast for example) that have been tested by myself, which make it pretty good to stream music or video playing on your PC to the supported TV.\n\n## Install\n```bash\npip install dlna-cast\n```\nPlease ensure your Python is 3.7 or above.\n\n### Install ffmpeg\nYou can install `ffmpeg` by compiling from source code, or just download the prebuild binary from https://ffmpeg.org/download.html\n\nYou need to ensure the `ffmpeg` command can be found in the `PATH` environment variable, or else you need to set `FFMPEG_BIN` or `FFMPEG_HOME` to let `dlna-cast` know where to find the command. \n\n`dlna-cast` supports reading the environment variable from `.env` file. You can create a `.env` file under the folder you are gonna run the `dlna-cast` command with the following content.\n\n```bash\nFFMPEG_BIN=D:\\ffmpeg\\ffmpeg.exe\n# or\nFFMPEG_HOME=D:\\ffmpeg\n```\n\nYou can also use the `dotenv set` command to update the `.env` file and use the `dotenv list` to check result.\n\n```bash\ndotenv set FFMPEG_HOME \"D:\\ffmpeg\"\ndotenv list\n```\n\n### Install ScreenCapturerRecorder on Windows\nThough `ffmpeg` is shipped with `gdigrab` to capture screens on Windows, its performance is terrible when frame rate is high. `dlna-cast` uses ScreenCapturerRecorder for the sake of performance. You need to [download](https://github.com/rdp/screen-capture-recorder-to-video-windows-free/releases) and install it before starting to cast.\n\n## Get Started\nBefore you start to stream your screen to remote devices that support DLNA protocol, you need to discover available devices in your LAN by running the following command.\n\n```bash\ndlna-cast list_dlna_devices\n# You will see the output if supported devices are found\nHuaweiPro\nLebocast\n``` \n\nAnd now you can cast your screen to one of the found devices by running the following command.\n```bash\ndlna-cast screen --dlna_device HuaweiPro\n``` \n\nOr you can also set `DLNA_DEVICE` in the `.env` file so that you can skip to set `--dlna_device` next time.\n\n```bash\ndotenv set DLNA_DEVICE HuaweiPro\ndlna-cast screen\n```\n\nTo stop casting just press `Ctrl+C`. \n\n## FAQ\n\n### Linux Limitations\nThe default `--input_opts` on `Linux` is `-f x11grab -i $DISPLAY`, which doesn't include capturing the audio. To support audio capture you may need to install loopback device first and then provide you own `--input_opts`, for example `--input_opts='-f x11grab -i $DISPLAY -f pulse -i name_of_your_device'`.\n\n### MacOS Limitations\nNot provide default `--input_opts` on `MacOS` yet. You need to provide your own `--input_opts`, for example `--input_opts='-f avfoundation -i 1:0`\n\n\n## TODO\n- [ ] Support cast media file.\n- [ ] Optimize devices discover.\n- [ ] Optimize latency.\n- [ ] Cross platform support.\n",
"bugtrack_url": null,
"license": "GPL-3.0-or-later",
"summary": "A cross-platform command-line tool that casts screen and media file to remote DLNA device.",
"version": "0.1.8",
"project_urls": null,
"split_keywords": [
"dlna",
" ffmpeg",
" media",
" smart-tv",
" screen-cast",
" upnp"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "34bdb56d8ccaf5b3c2f1e8d62e03c1a8583f19deb287fd9c1b93b48ccc0afe5d",
"md5": "e7b918ce725d83428000cac4af510671",
"sha256": "29f8794b03a02166403816218c65ceb7f19c1a18df119a42e70975f9fcb1ca26"
},
"downloads": -1,
"filename": "dlna_cast-0.1.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e7b918ce725d83428000cac4af510671",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.7",
"size": 31044,
"upload_time": "2024-04-19T12:51:32",
"upload_time_iso_8601": "2024-04-19T12:51:32.468074Z",
"url": "https://files.pythonhosted.org/packages/34/bd/b56d8ccaf5b3c2f1e8d62e03c1a8583f19deb287fd9c1b93b48ccc0afe5d/dlna_cast-0.1.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2a2e12746e584cedcae33a879b8c02a5b094be83a60c606cb046e79f27dae2ca",
"md5": "4c443810283bf262259d9b32a8af4a13",
"sha256": "2a20b7a78345879272ca4975601fbe24d201d2682e072fd4e2e9ac9104584cb0"
},
"downloads": -1,
"filename": "dlna_cast-0.1.8.tar.gz",
"has_sig": false,
"md5_digest": "4c443810283bf262259d9b32a8af4a13",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.7",
"size": 17802,
"upload_time": "2024-04-19T12:51:34",
"upload_time_iso_8601": "2024-04-19T12:51:34.534047Z",
"url": "https://files.pythonhosted.org/packages/2a/2e/12746e584cedcae33a879b8c02a5b094be83a60c606cb046e79f27dae2ca/dlna_cast-0.1.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-19 12:51:34",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "dlna-cast"
}