oaubert / python-vlc

Python vlc bindings
GNU Lesser General Public License v2.1
391 stars 111 forks source link

Player created from binding doesn't work as a streaming server #105

Closed project-owner closed 2 years ago

project-owner commented 5 years ago

If I'm creating player this way:

from  vlc import Instance
instance = Instance("--sout=#transcode{acodec=flac}:std{access=http,mux=flac,dst=10.0.0.6:8080}")
player = self.instance.media_player_new()

and then trying to play some file I cannot connect to the player as a streaming server. But the following command works fine from the command line:

vlc -I dummy --dummy-quiet --sout=#transcode{acodec=flac}:std{access=http,mux=flac,dst=10.0.0.6:8080} wav-file.wav

I can connect to vlc as a streaming server. I believe it was working fine some time ago (1-2 years ago?).

Thanks in advance!

project-owner commented 4 years ago

Any update? Thanks!

theodore-dream commented 4 years ago

I am facing the same exact issue... I can get it to work using command line but not python script. I increased logging verbosity and set a log file for VLC and seeing modules importing error and I'm seeing incorrect audio decoder used when using the script version. Things I've tried on Raspbian (Debian version for Raspberry Pi)

alsa debug: default (default) alsa debug: snd_rpi_hifiberry_dac, HifiBerry DAC HiFi pcm5102a-hifi-0 Default Audio Device (sysdefault:CARD=sndrpihifiberry) alsa debug: snd_rpi_hifiberry_dac, HifiBerry DAC HiFi pcm5102a-hifi-0 Direct sample mixing device (dmix:CARD=sndrpihifiberry,DEV=0) alsa debug: snd_rpi_hifiberry_dac, HifiBerry DAC HiFi pcm5102a-hifi-0 Direct sample snooping device (dsnoop:CARD=sndrpihifiberry,DEV=0) alsa debug: snd_rpi_hifiberry_dac, HifiBerry DAC HiFi pcm5102a-hifi-0 Direct hardware device without any conversions (hw:CARD=sndrpihifiberry,DEV=0) alsa debug: snd_rpi_hifiberry_dac, HifiBerry DAC HiFi pcm5102a-hifi-0 Hardware device with all software conversions (plughw:CARD=sndrpihifiberry,DEV=0) main debug: using audio output module "alsa" main debug: keeping audio output main debug: Creating an input for '(null)' main debug: using timeshift granularity of 50 MiB main debug: using default timeshift path main debug: http://s1.voscast.com:8652/' gives accesshttp' demux any' paths1.voscast.com:8652/' main debug: creating demux: access='http' demux='any' location='s1.voscast.com:8652/' file='(null)' main debug: looking for access_demux module matching "http": 17 candidates <<<<<<<<<<<<<<<<<<<<<< main debug: no access_demux modules matched <<<<<<<<<<<<<<<<<<<<<< main debug: creating access: http://s1.voscast.com:8652/ main debug: looking for access module matching "http": 28 candidates http debug: resolving s1.voscast.com ... http debug: outgoing request: GET / HTTP/1.1 Host: s1.voscast.com:8652 Accept: / Accept-Language: en_US User-Agent: VLC/3.0.11 LibVLC/3.0.11 Range: bytes=0-

So I may try your command line method for {access=http} in the script to see if that helps... otherwise I may need to compile it myself. Really don't want to do that because I want to make an instructional guide for other Raspberry Pi users and that's not very noob friendly method. Very frusterating. Can provide better replication steps and a script if anyone would take a look

project-owner commented 4 years ago

theodore-dream, what do you mean to compile it? Compile what? Thanks!

theodore-dream commented 4 years ago

Hello @project-owner I created my own thread on VideoLan forums here: https://forum.videolan.org/viewtopic.php?f=13&t=154620

To answer your question, I am referring to this.. if you lookup "python vlc" this PyPI listing shows the Pip module, you can install it. So it seems the most obvious method to use vlc in python is to use "vlc" package and "python-vlc" pip module, right? Ref: https://pypi.org/project/python-vlc/

Going a bit deeper, this pip module is a python binding for "Complete coverage of the libvlc API" reference here: [linked from the above] https://wiki.videolan.org/Python_bindings/

Going another step deeper, if you look at the README you will see instructions for compilation: https://git.videolan.org/?p=vlc/bindings/python.git;a=blob_plain;f=README.rst

I don't know about you, but my goal is to create a simple to follow Raspberry Pi project for people who are new to the ecosystem for a simple online radio client.

After having spent over a week on this issue bashing my head on the wall, I've come to a few realizations:

The more that I came to understand what exactly "libvlc" is and how python-vlc module relates to libvlc I realize I am in extremely technical territory. I work professionally with Linux but as a sysadmin type role - not a dev. The python bindings for libvlc are designed to give you all of the functionality of libvlc in python scripts.

So to come full circle, what I am trying to share is that the main purpose of python-vlc isn't for simple helper utilities to play audio/video. The purpose is for application developers to create custom media player type applications. I'm not trying to do anything that complex, so I am abandoning this direction for now and instead using Python subprocess module to call vlc in the shell.

Hope this rambling may provide some insight to someone... probably not helpful to you because I just checked your git repos and you are definitely creating something akin to a custom media player, so you probably know most all this. I'll just note that you may want to engage VideoLAN forum and/or provide more debug logs for better assistance on this issue.

Edit: I had to come back and say that looking over your Peppy project I am really impressed by all the work put into this.

project-owner commented 4 years ago

theodore-dream, I haven't faced the issues with python-vlc which you described. I'll give the detailed answer on that videolan thread. The only problem which I faced is the streaming server use case. I thought you are saying that some 'http' module is missing and you are suggesting to recompile binding with that module included. Thanks!

oaubert commented 4 years ago

Hi @theodore-dream As described by @project-owner , using vlc through python-vlc should be rather straightforward (apt install vlc python3-vlc then run in python

import vlc
p = vlc.MediaPlayer('http://s1.voscast.com:8652'
p.play()

), even for a simple player. Seeing your multiple experiments, I would suggest to try from a clean state, install vlc and first try to simply try to play a local mp4 file. Then focus on the streaming issue. This should help you identify the exact issue, which is in fact not the same as the one initially described by @project-owner (which is about running a streaming server from python-vlc).

theodore-dream commented 4 years ago

@oaubert @project-owner I didn't realize there was python3-vlc available as an apt package. It works perfectly. I should have better searched for that. I still don't understand why it wasn't working with pip installation but this works as expected.

My issue was playing audio / connecting to a streaming server as a client and this issue is for running a streaming server. So correct - this was an entirely different issue.

I apologize for hijacking this thread. Either of you, feel free to delete my posts here or tell me if you can't and I will delete them myself. I didn't mean to derail the thread. I feel like rather stupid but grateful. Thank you very much for your help.

project-owner commented 2 years ago

Hi @oaubert, the problem is still there 3 years later. Just to remind, I cannot configure the binding to work as a streaming server:

from  vlc import Instance
instance = Instance("--sout=#transcode{acodec=flac}:std{access=http,mux=flac,dst=10.0.0.6:8080}")
player = self.instance.media_player_new()

Clients cannot connect to the stream (http://10.0.0.6:8080). The same configuration works fine from command line:

vlc --sout=#transcode{acodec=flac}:std{access=http,mux=flac,dst=10.0.0.6:8080} wav-file.wav

Clients can connect to the stream. Please let me know if there is any way to debug this issue. Thanks!

oaubert commented 2 years ago

Looks like some people manage to make it work: https://forum.videolan.org/viewtopic.php?f=32&t=159665&p=527232&hilit=libvlc+transcode#p527232 Apart from that I cannot offer any help, I do not use this feature.

project-owner commented 2 years ago

Thank you for the link! The example from that thread was very helpful. It looks like the streaming settings should be specified for the Media class instead of Instance class. It works now.