I was facing the same issue and looked into the Python VLC bindings but because I was pressed for time and there was a lack of examples using the bindings, I went for another approach.
The vlc command line is extremely powerful. Using subprocess.call i did direct calls to the vlc command line.
This is the format I used and it worked beautifully.
subprocess.call([path_to_vlc,
mms_url,
'--sout',
'file/avi:'+target_file,
'vlc://quit'])
In the part of the list of parameters you send to call, here is a description of each:
- path_to_vlc -- As the name suggests. You don't have to use " to encapsulate spaces as with os.system for Program Files, etc. subprocess.call does that for you.
- mms_url -- is the url to the stream. Since in my case it was a mms stream the param name stuck. You can use any of the supported vlc stream prefixes.
- '--sout' -- since call encapsulate spaces for you, you need to explicitly separate each param where a space is needed. The actual param here is --sout file/avi:.... but we have to split them into two.
- 'file/avi:'+target_file -- The uri (and muxer) pointing to the target file. I used no path to the file since I was standing in the target directory when calling the python script. The target file should
- 'vlc://quit' -- Last we tell vlc to quit after playback. This way you get rid of the zombie vlc windows that stick around after.
If you wish to see the full code i used to first find the it here.