Stream ouput in python using vlc

This forum is about all development around libVLC.
jimmykarily
New Cone
New Cone
Posts: 3
Joined: 11 Apr 2009 21:12

Stream ouput in python using vlc

Postby jimmykarily » 11 Apr 2009 21:29

I want to create a python script that takes a stream from a unique ip and streams it to multiple others. I've built the vlc.so file and succesfully imported it. I used the sample code from videolan site :

Code: Select all

#! /usr/bin/python """VLC Widget classes. This module provides two helper classes, to ease the embedding of a VLC component inside a pygtk application. VLCWidget is a simple VLC widget. DecoratedVLCWidget provides simple player controls. $Id$ """ import gtk import sys import vlc from gettext import gettext as _ class VLCWidget(gtk.DrawingArea): """Simple VLC widget. Its player can be controlled through the 'player' attribute, which is a MediaControl instance. """ def __init__(self, *p): gtk.DrawingArea.__init__(self) self.player=vlc.MediaControl(*p) def handle_embed(*p): if sys.platform == 'win32': xidattr='handle' else: xidattr='xid' self.player.set_visual(getattr(self.window, xidattr)) return True self.connect("map-event", handle_embed) self.set_size_request(320, 200) class DecoratedVLCWidget(gtk.VBox): """Decorated VLC widget. VLC widget decorated with a player control toolbar. Its player can be controlled through the 'player' attribute, which is a MediaControl instance. """ def __init__(self, *p): gtk.VBox.__init__(self) self._vlc_widget=VLCWidget(*p) self.player=self._vlc_widget.player self.pack_start(self._vlc_widget, expand=True) self._toolbar = self.get_player_control_toolbar() self.pack_start(self._toolbar, expand=False) def get_player_control_toolbar(self): """Return a player control toolbar#! /usr/bin/python """VLC Widget classes. This module provides two helper classes, to ease the embedding of a VLC component inside a pygtk application. VLCWidget is a simple VLC widget. DecoratedVLCWidget provides simple player controls. $Id$ """ import gtk import sys import vlc from gettext import gettext as _ class VLCWidget(gtk.DrawingArea): """Simple VLC widget. Its player can be controlled through the 'player' attribute, which is a MediaControl instance. """ def __init__(self, *p): gtk.DrawingArea.__init__(self) self.player=vlc.MediaControl(*p) def handle_embed(*p): if sys.platform == 'win32': xidattr='handle' else: xidattr='xid' self.player.set_visual(getattr(self.window, xidattr)) return True self.connect("map-event", handle_embed) self.set_size_request(320, 200) class DecoratedVLCWidget(gtk.VBox): """Decorated VLC widget. VLC widget decorated with a player control toolbar. Its player can be controlled through the 'player' attribute, which is a MediaControl instance. """ def __init__(self, *p): gtk.VBox.__init__(self) self._vlc_widget=VLCWidget(*p) self.player=self._vlc_widget.player self.pack_start(self._vlc_widget, expand=True) self._toolbar = self.get_player_control_toolbar() self.pack_start(self._toolbar, expand=False) def get_player_control_toolbar(self): """Return a player control toolbar """ tb=gtk.Toolbar() tb.set_style(gtk.TOOLBAR_ICONS) def on_play(b): self.player.start(0) return True def on_stop(b): self.player.stop(0) return True def on_pause(b): self.player.pause(0) return True tb_list = ( (_("Play"), _("Play"), gtk.STOCK_MEDIA_PLAY, on_play), (_("Pause"), _("Pause"), gtk.STOCK_MEDIA_PAUSE, on_pause), (_("Stop"), _("Stop"), gtk.STOCK_MEDIA_STOP, on_stop), ) for text, tooltip, stock, callback in tb_list: b=gtk.ToolButton(stock) b.connect("clicked", callback) tb.insert(b, -1) tb.show_all() return tb class VideoPlayer: """Example video player. """ def __init__(self): self.vlc = DecoratedVLCWidget() def main(self, fname): self.vlc.player.set_mrl(fname) self.popup() gtk.main() def popup(self): w=gtk.Window() w.add(self.vlc) w.show_all() w.connect("destroy", gtk.main_quit) return w if __name__ == '__main__': if not sys.argv[1:]: print "You must provide a movie filename" sys.exit(1) p=VideoPlayer() p.main(sys.argv[1]) """ tb=gtk.Toolbar() tb.set_style(gtk.TOOLBAR_ICONS) def on_play(b): self.player.start(0) return True def on_stop(b): self.player.stop(0) return True def on_pause(b): self.player.pause(0) return True tb_list = ( (_("Play"), _("Play"), gtk.STOCK_MEDIA_PLAY, on_play), (_("Pause"), _("Pause"), gtk.STOCK_MEDIA_PAUSE, on_pause), (_("Stop"), _("Stop"), gtk.STOCK_MEDIA_STOP, on_stop), ) for text, tooltip, stock, callback in tb_list: b=gtk.ToolButton(stock) b.connect("clicked", callback) tb.insert(b, -1) tb.show_all() return tb class VideoPlayer: """Example video player. """ def __init__(self): self.vlc = DecoratedVLCWidget() def main(self, fname): self.vlc.player.set_mrl(fname) self.popup() gtk.main() def popup(self): w=gtk.Window() w.add(self.vlc) w.show_all() w.connect("destroy", gtk.main_quit) return w if __name__ == '__main__': if not sys.argv[1:]: print "You must provide a movie filename" sys.exit(1) p=VideoPlayer() p.main(sys.argv[1])


The script runs with no errors and if I use a stream ip as a parameter it actually does half the job (it takes a stream as an input). The problem is that
I don't want a window at all (So gtk stuff is not needed) but I just want the script to create an other stream as ouput. The concept is this :
"original stream" ----> python script ------> "new stream (multiple addresses)". I know this is possible using the ui so I think there must be a way to do the same using the library. Anyone?

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

Re: Stream ouput in python using vlc

Postby Rémi Denis-Courmont » 11 Apr 2009 22:01

The native library won't start the UI unless asked explicitly. The native library does not create a video window either, unless it is told to play a video file instead of streaming it.

Your problem: you're trying to use a GTK-centric Python binding. Of course, that's not going to work.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

jimmykarily
New Cone
New Cone
Posts: 3
Joined: 11 Apr 2009 21:12

Re: Stream ouput in python using vlc

Postby jimmykarily » 11 Apr 2009 22:33

Thanks for the answer and for pointing out the problem but I would really appreciate a direction to a solution. I tried to read the documentation but most of it is outdated. To tell you the truth I didn't know there was an other binding for vlc (Is there?). Python bindings are very little documented and this example is all I found and made to work.

wlourf
Blank Cone
Blank Cone
Posts: 12
Joined: 01 Nov 2007 19:56

Re: Stream ouput in python using vlc

Postby wlourf » 16 Apr 2009 21:56

Thanks for the answer and for pointing out the problem but I would really appreciate a direction to a solution
Did you try the subprocess module in Python :

Code: Select all

p = subprocess.Popen(['vlc', yourstream, option1,option2]
If you don't want any window, use the option --intf=dummy


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 5 guests