Coder Social home page Coder Social logo

link89 / dlna-cast Goto Github PK

View Code? Open in Web Editor NEW
25.0 3.0 1.0 51 KB

A cross-platform command-line tool that casts screen and media file to remote DLNA device.

License: GNU General Public License v3.0

Python 100.00%
dlna ffmpeg hls smart-tv upnp media screen-cast dlna-upnp h264 streaming

dlna-cast's Introduction

dlna-cast

PyPI version Downloads

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

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.

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.

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 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.

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.

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.

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.

dlna-cast's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

notoriousarnav

dlna-cast's Issues

dlna-cast not working in linux

Hello and thank you in advance for having done dlna-cast...
I have installed with:
pip install dlna-cast
The program detects my DLNA device perfectly.
The problem arises when I try to run:
dlna-cast screen --dlna_device BF913C44
I think the program cannot find my ffmpeg, this is the error trace:
File "/home/tugo/.local/pipx/venvs/dlna-cast/lib/python3.12/site-packages/dlna_cast/main.py", line 112, in screen
self._start_ffmpeg_streaming(framerate, input_opts, segment_size, crf)
File "/home/tugo/.local/pipx/venvs/dlna-cast/lib/python3.12/site-packages/dlna_cast/main.py", line 82, in _start_ffmpeg_streaming
cmd = ' '.join(cmd)
^^^^^^^^^^^^^
TypeError: sequence item 3: expected str instance, NoneType found

Waiting for your prompt attention, I remain at your service to provide you with any details that seem pertinent, again, thank you...!

device discovery shows a lot of errors

dlna-cast list_dlna_devices throws a ton of errors before listing one device in the network:

Error '404 Client Error: Not Found for url: http://192.168.88.10:8008/ssdp/notfound' for <dlna_cast.ssdp.Entry object at 0x7f8ffa91a010>
Error ''NoneType' object has no attribute 'strip'' for <dlna_cast.ssdp.Entry object at 0x7f8ffa91a090>
Error ''NoneType' object has no attribute 'strip'' for <dlna_cast.ssdp.Entry object at 0x7f8ffa91a0d0>
Error ''NoneType' object has no attribute 'strip'' for <dlna_cast.ssdp.Entry object at 0x7f8ffa91a110>
Error '404 Client Error: Not Found for url: http://192.168.88.10:8008/ssdp/notfound' for <dlna_cast.ssdp.Entry object at 0x7f8ffa91a210>
Error '404 Client Error: Not Found for url: http://192.168.88.10:8008/ssdp/notfound' for <dlna_cast.ssdp.Entry object at 0x7f8ffa91a250>
Error ''NoneType' object has no attribute 'strip'' for <dlna_cast.ssdp.Entry object at 0x7f8ffa919c10>
Error ''NoneType' object has no attribute 'strip'' for <dlna_cast.ssdp.Entry object at 0x7f8ffa919c50>
Error ''NoneType' object has no attribute 'strip'' for <dlna_cast.ssdp.Entry object at 0x7f8ffa919c90>
Error ''NoneType' object has no attribute 'strip'' for <dlna_cast.ssdp.Entry object at 0x7f8ffa919cd0>
Error ''NoneType' object has no attribute 'strip'' for <dlna_cast.ssdp.Entry object at 0x7f8ffa919d90>
Error '404 Client Error: Not Found for url: http://192.168.88.10:8008/ssdp/notfound' for <dlna_cast.ssdp.Entry object at 0x7f8ffa91a590>
Error ''NoneType' object has no attribute 'strip'' for <dlna_cast.ssdp.Entry object at 0x7f8ffa919e10>
Error ''NoneType' object has no attribute 'strip'' for <dlna_cast.ssdp.Entry object at 0x7f8ffa919ed0>
Error '404 Client Error: Not Found for url: http://192.168.88.10:8008/ssdp/notfound' for <dlna_cast.ssdp.Entry object at 0x7f8ffa91a710>
VSX-S520D

I can easily filter them out with dlna-cast list_dlna_devices | grep -v ^Error, but is there a way to get rid of them?

"frame dropped!" and "No attribute or service found with name 'AVTransport'" errors

I only get a bunch of errors like this one:

real-time buffer [screen-capture-recorder] [video input] too full or near too full (464% of size: 3041280 [rtbufsize parameter])! frame dropped!

After ~3 seconds of errors the program breaks:

AttributeError: No attribute or service found with name 'AVTransport'.

Is there any fix for this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.