Package: dlna-cast
dlna-castA cross-platform command-line tool that casts screen and media file to remote DLNA device.Introductiondlna-castusesffmpegto 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.Installpipinstalldlna-castPlease ensure your Python is 3.7 or above.Install ffmpegYou can installffmpegby compiling from source code, or just download the prebuild binary fromhttps://ffmpeg.org/download.htmlYou need to ensure theffmpegcommand can be found in thePATHenvironment variable, or else you need to setFFMPEG_BINorFFMPEG_HOMEto letdlna-castknow where to find the command.dlna-castsupports reading the environment variable from.envfile.  You can create a.envfile under the folder you are gonna run thedlna-castcommand with the following content.FFMPEG_BIN=D:\ffmpeg\ffmpeg.exe# orFFMPEG_HOME=D:\ffmpegYou can also use thedotenv setcommand to update the.envfile and use thedotenv listto check result.dotenvsetFFMPEG_HOME"D:\ffmpeg"dotenvlistInstall ScreenCapturerRecorder on WindowsThoughffmpegis shipped withgdigrabto capture screens on Windows, its performance is terrible when frame rate is high.dlna-castuses ScreenCapturerRecorder for the sake of performance. You need todownloadand install it before starting to cast.Get StartedBefore 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-castlist_dlna_devices# You will see the output if supported devices are foundHuaweiPro
LebocastAnd now you can cast your screen to one of the found devices by running the following command.dlna-castscreen--dlna_deviceHuaweiProOr you can also setDLNA_DEVICEin the.envfile so that you can skip to set--dlna_devicenext time.dotenvsetDLNA_DEVICEHuaweiPro
dlna-castscreenTo stop casting just pressCtrl+C.FAQLinux LimitationsThe default--input_optsonLinuxis-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 LimitationsNot provide default--input_optsonMacOSyet. You need to provide your own--input_opts, for example--input_opts='-f avfoundation -i 1:0TODOSupport cast media file.Optimize devices discover.Optimize latency.Cross platform support.