How can I open a VLC stream?

plugin-dev

#1

Hi, I am trying to open a stream served by VLC on the same box as PMS. I feel like i have tried every combination that VLC is capable of but nothing is working.



I know VLC is streaming correctly since i can access the stream via safari (tho it just starts downloading as a file) and via VLC on another computer (however no sound, but im not concerning myself with that now)



VLC offers 4 kinds of streams:

HTTP

UDP

MMSH

RTP



surely plex ought to work with at least HTTP. I tried replicating what the EyeTV plugin is doing to open it's http stream which is: return Redirect('http://127.0.0.1:1234')



I have also tried this:


<br />
def MainMenu():<br />
    dir = MediaContainer(title1="VLC Player")<br />
    dir.Append(<br />
        VideoItem(<br />
            'mms://127.0.0.1:1234',<br />
            title='Play Movie',<br />
            subtitle="Click to open this stream!",<br />
            summary="VLC"<br />
            )<br />
        )<br />
    return dir<br />






sometimes I can get an infinite "Opening stream box" and have to force quit plex. most of the time nothing at all happens.



the logs are usually void of anything, but some combinations of VLC options do get plex to show a 302 with 0 bytes in the log.



Long story short: does anybody have a clue how to stream from VLC to plex?


#2

The streaming capability will depend on more than just the protocol used. The file type and codecs can be important. When you access the http stream via a browser, what sort of file do you get?


#3

I'm sure actually getting video to play in plex does require a compatible format and whatnot, but shouldnt it popup something about "unknown format" or some such? certainly shouldn't be locking up when i try to cancel the connection.



If I try an HTTP stream with MPEG TS container plex seems to successfully open it, but it thinks the stream is 0 bytes. the log indicates HTTP 200 0 bytes transfered and using curl on the command line does in fact reveal the content-length header is 0, yet the file still downloads in safari and can be viewed from another VLC instance. Im certainly no HTTP/streaming expert, but I'm guessing the length is 0 because it is not known how long the stream is? So it seems that plex doesnt support streaming of live "endless" streams?



I have also tried "Raw" and "ASF" encapsulation streamed over HTTP with no luck.



I am not sure how i am supposed to verify what type of data is in the file safari was downloading, but I see no reason why it wouldnt be the raw data that VLC was streaming in whatever format/container it was using at the time.



If i hexdump the partial download in terminal i can see that this particular instance has "mpgv" repeated throughout it and also "Unknown Video" those are the only human readable strings i saw the rest is pure binary data.


#4

Sounds like HTTP Live Streaming which Plex does support. The trick is in telling PMS how to grab the stream. I don't know if the previous plugin framework (v2.0) supported HLS. It'd be better and you'll have more usable examples, if you switch to v2.1.



URL Services are generally implemented for the v2.1 plugins but they are not entirely necessary. Something like this should work...



<br />
def MainMenu():<br />
    oc = ObjectContainer(title1="VLC Player")<br />
    oc.add(VideoClipObject(title="Play",<br />
        items=[MediaObject(<br />
            parts = [PartObject(<br />
                key=HTTPLiveStreamURL("http://127.0.0.1:1234")<br />
                )]<br />
            )]<br />
        )<br />
    )<br />






The CityTV URL Service is an example of HLS urls being implemented although more complex than this case requires. I can't comment on the issue regarding content length. That's beyond my experience.


#5

i didn't even know there was a 2.1. I just change the PlexFrameworkVersion in info.plist to 2.1 I assume.



I'll give this a shot thanks!


#6

Actually, there's no need to change the version key in the plist. The changes are primarily in the init.py. The docs at dev.plexapp.com elaborate more on the object types etc. There's some nice blog posts there from IanB! with pointers for channel development.


#7

I'm certain this shouldnt be as hard as it is being. I see no reason why i shouldnt simply be able to specify a stream URL and have plex play it. (vlc and quicktime this is all that is required)



trying to add a VideoClipObject requires either the URL attribute to be set or both the "key" and "rating_key" attributes. The problem being setting the URL to 'http://127.0.0.1:1234' does nothing at all. the docs say key should return a meta data object (which i tried), but that makes no sense because VideoClipObject itself is a meta data object.



I'm sure this is super easy, but the documentation is a complete disaster IMO. nowhere in the docs does it list the items attribute you gave nor does it have anything regarding HTTPLiveStreamURL



the MOST annoying part of this is having 3 different log files and NONE of they have anything of value in them. I select the play item in the list and plex does nothing and no messages are written anywhere.


#8

OK here is some hopefully helpful information to the next poor sap that tries to make a plex plugin:



if you want ANY helpful log information or errors for playing video you CANNOT route your plugin as an application (ie /application/myPlugin) you must have it routed as a video channel. I thought that the route was only for what section the plugin appears under, but apparently there is more to it than that. Why this makes plex freeze and not log anything (seemingly at random) is beyond me, but making the route /video/myplugin made it things are actually logged and now i may still get an error when trying to open the stream, but at least plex is trying to open it now!


#9

ok as i suspected this is not difficult. the key was to register as a video channel and not an application (this should be stressed in the docs, but i didnt see it mentioned and only discovered this myself)



here is basic code to do it:



<br />
def MainMenu():<br />
    oc = ObjectContainer(title1="VLC Player")<br />
    <br />
    mo = MediaObject(parts=[PartObject(key=HTTPLiveStreamURL("http://127.0.0.1:1234"))])<br />
    <br />
    vco = VideoClipObject(title="Play local VLC stream", url='http://127.0.0.1:1234')<br />
    vco.add(mo)<br />
    oc.add(vco)<br />
    <br />
    return oc<br />






VLC settings i used:

Stream: HTTP

Encapsulation: [s]MPEG TS[/s] ASF



EDIT: switching from "MPEG TS" to "ASF" results in butter smooth playback even on the same machine



no transcoding



I dont know if these are the "best" options; [s]there is tremendous video lag[/s], but I am streaming and viewing on the same box right now.



I would like to think plex would support some of the other streams too.



Last but not least thank you Mikedm139 for the helpful hints.



Edit2:



If anybody is curious my primary motivation for this is to make a DVD playback plugin. Now that I have the streaming working I can work on the playback controls which VLC does (allegedly) provide over HTTP.



I will of course release my work here for others to enjoy/improve starting with this shellscript coe im using to open VLC as a faceless daemon (sounds scary i know :P) and begin streaming the DVD inside the server



<br />
#!/bin/bash<br />
<br />
cmd="/Applications/VLC.app/Contents/MacOS/VLC -I http -vvv --color dvdread:///dev/rdisk1#1:1- --sout '#standard{access=http,mux=asf,dst=localhost:1234}' --sout-all -d"<br />
eval "$cmd" > /dev/null<br />
<br />
echo 0<br />
exit<br />
<br />



#10

I'm sorry. Had I known you were trying to play video from an application plugin, I would have warned you that doesn't work :( That's a pet peave of mine with CouchPotato plugin.

FWIW, I understand that those sorts of differentiations are not likely to be a permanent issue.


#11

[quote name='Mikedm139' timestamp='1337140088' post='263617']


I'm sorry. Had I known you were trying to play video from an application plugin, I would have warned you that doesn't work :( That's a pet peave of mine with CouchPotato plugin.

FWIW, I understand that those sorts of differentiations are not likely to be a permanent issue.

[/quote]




Heh no worries. I do wish plex would have thrown an error when trying to do it rather than being obstinately silent tho...



the important think is it works now.


#12

Out of curiosity - does vlc use relative or absolute urls in its hls playlists?

I'm asking because I (and a hand full of other users) have faced nasty problems when trying to Redirect() to a hls playlist which contained relative content urls.



The problem being Plex which simply ignored the base URL of the playlist and tryed to grab the relative parts from where the plugin did the Redirect() (e.g /video/xxx/tunto/part1.ts instead of http://1.2.3.4:1111/stream/part1.ts).



And yes, I've tryed to wrap the URL / key resources in HTTPLiveStreamURL() and I've also tryed by implementing this it with a URLService.


#13

I honestly have no idea. as you can see from the above code i simply give plex the address and port. I do know that there is a 302, but I've never followed it or tried to examine the stream in any other way.



definitely sounds like plex is dropping the ball for you. In all honesty i havent yet streamed more than 10 seconds of video from VLC so for all I know I am subject to the same issues you are having.


#14

[quote name='Shirk' timestamp='1337212532' post='263850']


Out of curiosity - does vlc use relative or absolute urls in its hls playlists?

I'm asking because I (and a hand full of other users) have faced nasty problems when trying to Redirect() to a hls playlist which contained relative content urls.

[/quote]




VLC can provide both relative and absolute paths in an HLS playlist. From Murderous Moppet's bash script though it doesn't appear that he is streaming via HLS but rather just HTTP and that's why he can provide Plex with just the host:port without the m3u8 playlist.



I currently stream with VLC from a HDPVR to Plex using the same method as above and it has been working very nicely for about 6 months. The only thing different is that I use mpegts as the container since that is what the HDPVR provides and in my case the playback is smooth. I can now view and control my directv box directly from within Plex so there shouldn't be any issues doing the same for DVDs. The interface is a little clunky as I haven't found a way to use the remote as cleanly as i would like to and I am going to be looking at that this week. For example when you want to fast forward you would need to capture the plex fastforward and instead of fastforwarding the stream that plex is playing you want to send a fastforward command to the directv box or VLC. Im not sure if this is possible if you're not using a site configuration as i cannot find any documentation for it.



My current idea is that I could use some external program to listen for certain key presses (ex play/pause/ff etc..) and then query the Plex client to see if it's currently playing the stream or not. If it is then route the command to whatever interface setup for controlling the stream or just route as a different keypress that plex will pick up.


#15

[quote name='fillet54' timestamp='1337720301' post='265419']


VLC can provide both relative and absolute paths in an HLS playlist. From Murderous Moppet's bash script though it doesn't appear that he is streaming via HLS but rather just HTTP and that's why he can provide Plex with just the host:port without the m3u8 playlist.



I currently stream with VLC from a HDPVR to Plex using the same method as above and it has been working very nicely for about 6 months. The only thing different is that I use mpegts as the container since that is what the HDPVR provides and in my case the playback is smooth. I can now view and control my directv box directly from within Plex so there shouldn't be any issues doing the same for DVDs. The interface is a little clunky as I haven't found a way to use the remote as cleanly as i would like to and I am going to be looking at that this week. For example when you want to fast forward you would need to capture the plex fastforward and instead of fastforwarding the stream that plex is playing you want to send a fastforward command to the directv box or VLC. Im not sure if this is possible if you're not using a site configuration as i cannot find any documentation for it.



My current idea is that I could use some external program to listen for certain key presses (ex play/pause/ff etc..) and then query the Plex client to see if it's currently playing the stream or not. If it is then route the command to whatever interface setup for controlling the stream or just route as a different keypress that plex will pick up.

[/quote]




Thanks for chiming in. The only thing I can suggest regarding the remote/keymapping is that if you're using a Harmony (or perhaps other universal) remote, you may be able to add some custom keymapping for use during playback that would send commands to VLC/HDPVR. Of course that would only work with the desktop client(s) but, it might serve your purposes.


#16

[quote]
My current idea is that I could use some external program to listen for certain key presses (ex play/pause/ff etc..) and then query the Plex client to see if it's currently playing the stream or not. If it is then route the command to whatever interface setup for controlling the stream or just route as a different keypress that plex will pick up.

[/quote]




Indeed this is the only way I have found to do things. I hope plex API adds native support for input hooks soon (i may end up forking the latest PMC and do it myself)



If you are interested (and on a mac) I can provide you the code i have been using to hook the keyboard input for the eyetv plugin.


#17

Is there any chance you can make this code available and some sort of steps on how to implement it in a plex media server? I am trying to achieve the same thing (stream custom URL in Plex) but I'm a bit of a n00b and don't have a clue where to start.



Thanks in advance,

D


#18

[quote name='donaldjackson' timestamp='1350749568' post='304465']


Is there any chance you can make this code available and some sort of steps on how to implement it in a plex media server? I am trying to achieve the same thing (stream custom URL in Plex) but I'm a bit of a n00b and don't have a clue where to start.



Thanks in advance,

D

[/quote]




look at post #9. that is all the code you need to stream from a VLC server.


#19

Hi, im new on this issue, im trying to stream live video through PLEX by VLC... But i dont understand where i suppose to change or write the code that u guys show on the post #9.. if some one can teach me how to do it, i`ll really appreciate. tHanks!


#20

you need to crate a new plex channel plugin



easiest way to get a handle on it is probably to find an existing basic plugin and change the info.plist to your own values and then strip out the code except for init.py and then replace all the code in init.py with teh example in post #9 edited to reflect your VLC server.