Streaming - Works from CMD but not from Python

This forum is about all development around libVLC.
MisfitGeek
New Cone
New Cone
Posts: 3
Joined: 08 Apr 2022 22:27

Streaming - Works from CMD but not from Python

Postby MisfitGeek » 13 Apr 2022 18:24

Hello All,

Hoping someone can help me solve this puzzle.

I'm trying to stream from a Python script on Windows.

It works using this command line:

"C:\Program Files\VideoLAN\VLC\vlc.exe" sample-mp4-file.mp4 --sout="#transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:duplicate{dst=http{mux=ffmpeg{mux=flv},dst=:8080/}", :no-sout-all :sout-keep

However, this code using the same sout doesn't seem to work.

import vlc
inst = vlc.Instance("""--sout="#transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:duplicate{dst=http{mux=ffmpeg{mux=flv},dst=:8080/}", :no-sout-all :sout-keep""")
med = inst.media_new("sample-mp4-file.mp4")
p = med.player_new_from_media()
p.play()

while True:
pass

Does anyone have any suggestions

TIA

MisfitGeek
New Cone
New Cone
Posts: 3
Joined: 08 Apr 2022 22:27

Re: Streaming - Works from CMD but not from Python

Postby MisfitGeek » 14 Apr 2022 15:46

This code works - don't ask me why :)

import vlc

inst = vlc.Instance()
param=[
"sample-mp4-file.mp4"
,"sout=#transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:duplicate{dst=http{mux=ffmpeg{mux=flv},dst=:8080/}"
]
Media = inst.media_new(*param)
player = Media.player_new_from_media()
player.play()

while True:
pass

unidan
Developer
Developer
Posts: 1493
Joined: 25 Mar 2018 01:00

Re: Streaming - Works from CMD but not from Python

Postby unidan » 29 Apr 2022 09:13

Hi, in the first code, because of the """ string marker, you gave only one big option which was

Code: Select all

--sout="#transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:duplicate{dst=http{mux=ffmpeg{mux=flv},dst=:8080/}", :no-sout-all :sout-keep
Python libvlc will split it at spaces, but then the first argument will become

Code: Select all

--sout="#transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100,scodec=none}:duplicate{dst=http{mux=ffmpeg{mux=flv},dst=:8080/}",
Which might have raised an error at the sout creation.

Using media_new is correct here and you can keep that!

peppy.player
Blank Cone
Blank Cone
Posts: 38
Joined: 10 Nov 2017 00:07

Re: Streaming - Works from CMD but not from Python

Postby peppy.player » 05 May 2022 00:02

Hi,

I've prepared the following code using the example from this thread:

Code: Select all

import vlc import time inst = vlc.Instance() url = "https://rockthecradle.stream.publicradio.org/rockthecradle-tunein.mp3" param=[url, "--sout=#transcode{acodec=flac}:std{access=http,mux=flac,dst=10.0.0.6:8080}"] m = inst.media_new(*param) player = m.player_new_from_media() player.play() while True: time.sleep(0.2)
When I run it I can hear the stream played locally but I cannot connect any client to that stream (e.g. Firefox browser): http://10.0.0.6:8080

If I do the same from command line:

Code: Select all

vlc --sout=#transcode{acodec=flac}:std{access=http,mux=flac,dst=10.0.0.6:8080} "https://rockthecradle.stream.publicradio.org/rockthecradle-tunein.mp3"
I can connect clients (Firefox) to that stream.
I'm just wondering how my example is different from the suggested solution?
Thanks!

Rémi Denis-Courmont
Developer
Developer
Posts: 15266
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: Streaming - Works from CMD but not from Python

Postby Rémi Denis-Courmont » 05 May 2022 09:40

The LibVLC media player API does not support the streaming output (except through the renderer selection).
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

peppy.player
Blank Cone
Blank Cone
Posts: 38
Joined: 10 Nov 2017 00:07

Re: Streaming - Works from CMD but not from Python

Postby peppy.player » 05 May 2022 17:07

OK, how does the player stream without selecting renderer when I start it from command line?

Code: Select all

vlc --sout=#transcode{acodec=flac}:std{access=http,mux=flac,dst=10.0.0.6:8080} "https://rockthecradle.stream.publicradio.org/rockthecradle-tunein.mp3"
Does it use some default renderer?
Thanks!

Rémi Denis-Courmont
Developer
Developer
Posts: 15266
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: Streaming - Works from CMD but not from Python

Postby Rémi Denis-Courmont » 05 May 2022 17:22

VLC does not use the LibVLC media player API.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

peppy.player
Blank Cone
Blank Cone
Posts: 38
Joined: 10 Nov 2017 00:07

Re: Streaming - Works from CMD but not from Python

Postby peppy.player » 05 May 2022 18:02

Hmm, the second post in this thread is saying that it works. Though my example which follows that code doesn't actually work. Then it looks like the Python binding for libVLC doesn't support streaming output. Though I was able to use it about 4-5 years ago:
https://github.com/oaubert/python-vlc/issues/105
So more likely something was changed in the code and the only way to make streaming working now is to start 'vlc' as external process. That makes it more difficult to control the player in this case and defeats the purpose of using Python binding at all.

Thank you anyway.

Rémi Denis-Courmont
Developer
Developer
Posts: 15266
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: Streaming - Works from CMD but not from Python

Postby Rémi Denis-Courmont » 05 May 2022 19:35

The first post uses instance options while the second post uses media/item options.

Either way, there is explicitly no compatibility promise when using options, precisely because they are not compatible across versions.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

unidan
Developer
Developer
Posts: 1493
Joined: 25 Mar 2018 01:00

Re: Streaming - Works from CMD but not from Python

Postby unidan » 06 May 2022 15:16

Hmm, the second post in this thread is saying that it works
Actually Rémi's right, --sout won't work on any recent libvlc version (sort of since renderer API in libvlc).

A media option will work though, by passing the option to `media_new`, because it's no different than what VLC does, but as always it's not "public supported API" and might break some time. But you can still pass :sout-keep (or :no-sout-keep to destroy the sout) and still pass sout option in a more flexible way than when passing the option to the instance.

peppy.player
Blank Cone
Blank Cone
Posts: 38
Joined: 10 Nov 2017 00:07

Re: Streaming - Works from CMD but not from Python

Postby peppy.player » 06 May 2022 21:41

Actually Rémi's right, --sout won't work on any recent libvlc version (sort of since renderer API in libvlc).
A media option will work though, by passing the option to `media_new`, because it's no different than what VLC does, but as always it's not "public supported API" and might break some time. But you can still pass :sout-keep (or :no-sout-keep to destroy the sout) and still pass sout option in a more flexible way than when passing the option to the instance.
OK, I understand that --sout options will not work in Instance class but should work in Media class. I'm just wondering why my example which is using Media doesn't work? Is it just because now is exactly that time which you mentioned - "and might break some time"? :)
Thanks!

peppy.player
Blank Cone
Blank Cone
Posts: 38
Joined: 10 Nov 2017 00:07

Re: Streaming - Works from CMD but not from Python

Postby peppy.player » 06 May 2022 22:07

Never mind, I found the problem - it should be 'sout' not '--sout'. So, this code works:

Code: Select all

import vlc import time inst = vlc.Instance() url = "https://rockthecradle.stream.publicradio.org/rockthecradle-tunein.mp3" param=[url, "sout=#transcode{acodec=flac}:std{access=http,mux=flac,dst=:8080}"] m = inst.media_new(*param) player = m.player_new_from_media() player.play() while True: time.sleep(0.2)
I can connect to the stream from browser.
Thanks!

unidan
Developer
Developer
Posts: 1493
Joined: 25 Mar 2018 01:00

Re: Streaming - Works from CMD but not from Python

Postby unidan » 16 May 2022 09:09

What makes it working is that you're using `media_new` to pass the option instead of `vlc.Instance` ;)


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 15 guests