Jump to content

Communicating with VLC


 Share

Recommended Posts

I need to establish interactive read/write relationship with the VideoLan player from AutoIT. However, I'm unable to achieve this. VLC doesn't offer a COM interface, so there goes our easiest way. VLC does offer some language specific bindings which are therefore of no use to AutoIt. VLC does offer a basic command line interface so I've tried to tap into this.

command line interface

On the surface it seems like any other command line interface, but I'm now having my doubts since it doesn't seem to be cooperating as such. Many of you will have VLC on your systems, so you can play along with the examples I give. To allow flexibility, I'm placing each example of each command type in a separate function and clearly labelling it. There are other steps I've taken that aren't shown. But I thought I'd show basic examples of what would need to be working before we can move onto those later steps.

1. Basic VLC startup

#include <Constants.au3>
$file="c:\temp\test.mpg" ; change this to a file that exists on your system

start_nothing_streamed()
func start_nothing_streamed()
    global $vlc=run('C:\Program Files\VideoLAN\VLC\vlc.exe --extraintf rc "'&$file&'"',"",@sw_show)
endfunc
oÝ÷ Ù¼(®K?m

fails

So redirecting just the outputs means that we it stops accepting keystrokes. And as we know from our previous example, the command line doesn't accept redirected input either.

5. Fudge input and output

I have a requirement that VLC be communicated with while in the background. While we can use controlsend() to send commands, this does preclude any alt-space screen scrapes, since they require the app to have the current focus.

To me, it looks like VLC command line is non standard and doesn't want to play nice. (If there's any errors in the way I've attempted to communicate with it just let me know so we can all go home.)

Can anyone help in sending commands and receiving responses to VLC?

Link to comment
Share on other sites

Man, your post is neat! You get a million kudos for that post. Both thumbs high up for you.

Anyway, in general command line interfaces are only read by the application when this program starts.. VLC must be ignoring the other in stream by AutoIt. The only solutions that I can think of currently, are using another program, or either just using the Send command or ControlSend to pass any other parameters to the window. Why is it so important that this is hidden?

Link to comment
Share on other sites

Man, your post is neat! You get a million kudos for that post. Both thumbs high up for you.

lol thanks. I'll let my parents know the education they gave me is paying dividends.

Anyway, in general command line interfaces are only read by the application when this program starts..

Ah yes. I referred to "command line" a few times as my way of describing the line oriented, DOS like command window that comes up after you start VLC. But I can see the confusion.

VLC must be ignoring the other in stream by AutoIt. The only solutions that I can think of currently, are using another program, or either just using the Send command or ControlSend to pass any other parameters to the window. Why is it so important that this is hidden?

No requirement for it to be hidden. But not in focus (ie in the background) is a requirement, since VLC needs to be pumping video out to, say, the TV output while simultaneously allowing someone else to be chatting to you right here on the forum.
Link to comment
Share on other sites

  • 2 weeks later...

Finally I got this junk to record!!

$vlcid=Run('C:\PROGRA~1\VideoLAN\VLC\vlc http://69.1.83.130:80/Endavo3abn?MSWMExt=.asf --sout="#duplicate{dst=std{access=file,mux=asf,url="C:\test\somefile101.asf"},dst=nodisplay}"')

$pathtovlc @space $streamURL @space

and then this junk:

--sout="#duplicate{dst=std{access=file,mux=asf,url="C:\test\somefile101.asf"},dst=nodisplay}"

what throws me off is the string in string business.

ok now "i am a string and "I am a string in a string" is that ok?"

That's too wierd. It's making me crazy..

Link to comment
Share on other sites

ok now "i am a string and "I am a string in a string" is that ok?"

That's too wierd. It's making me crazy..

Use StringFormat() to help clean up your syntax, and perhaps an if test to properly handle escaping quotes / double quotes in your strings.

Looking forward to seeing your progress.

Edited by flyingboz

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Link to comment
Share on other sites

Use StringFormat() to help clean up your syntax, and perhaps an if test to properly handle escaping quotes / double quotes in your strings.

Looking forward to seeing your progress.

That's the way it was in the http://videolan.org/ forum post.

http://forum.videolan.org/viewtopic.php?p=47884#47884

It's really incorrect.

You can see in my last post there I made it right, like this:

C:\PROGRA~1\VideoLAN\VLC\vlc http://something.asf --sout="#duplicate{dst=std{access=file,mux=asf,url='C:\test\spaces may be.asf'},dst=nodisplay}"

Doing it with the wierd quotes caused the output file to be named with only the first word if there are spaces in the name.

I'm working on my stream recording program. 3abn.org changed thier format so now the SDP media recorder is not as reliable as VLC.

But here's a clip from this new version using VLC to record:

Global $savedir = FileGetShortName( IniRead ( "settings.ini", "paths", "$savedir", @MyDocumentsDir ) ) & "\"
Global $vlcpath = FileGetShortName( IniRead ( "settings.ini", "paths", "$vlcpath", "C:\Program Files\VideoLAN\VLC\vlc.exe" ) )
Global $streamurl = IniRead ( "settings.ini", "paths", "$streamurl", "http://69.1.83.130:80/Endavo3abn?MSWMExt=.asf" )


$VLCpid=Run($vlcpath &' '& $streamurl &' --sout="#duplicate{dst=std{access=file,mux=asf,url='''& makename() &'''},dst='& iif($OPT_VLC_DISPLAY,'','no') &'display}" --stop-time=7200'); 2 hr limit in case of bug
WinWaitActive($VLCtitle)
$VLCwinid = WinGetHandle("active")
If Not $OPT_VLC_DISPLAY Then WinSetState("active",'',@SW_HIDE)
Edited by rush4hire
Link to comment
Share on other sites

Finally I got this junk to record!!

$vlcid=Run('C:\PROGRA~1\VideoLAN\VLC\vlc http://69.1.83.130:80/Endavo3abn?MSWMExt=.asf --sout="#duplicate{dst=std{access=file,mux=asf,url="C:\test\somefile101.asf"},dst=nodisplay}"')

OK. This thread seems to have been taken off on a slight tangent. The purpose of this thread being how to programatically control VLC: pause, jump to location x, "what position am I currently playing in the file",unpause, stop etc. So I will bring it back to that.

I've messaged the VLC support forums about this http://forum.videolan.org/viewtopic.php?p=106030#106030 and have been told that VLC can successfully be controlled via ActiveX without needing to use a web browser. I will add that virtually 100% of times VLC mentions ActiveX on their site it in the same sentence as web browser. Hence it wasn't my first avenue to try from a stand alone language. The support forum for ActiveX is even called "Web and scripting". But let's move on.

ActiveX

Taking the examples from the VLC website written in other languages, having read numerous posts on their support forum etc et al, I've written some code for starting VLC via ActiveX that almost works.

#include <Constants.au3>
$file="c:\temp\test.mpg" ; change this to a file that exists on your system

$vlc=ObjCreate("VideoLAN.VLCPlugin.1")
if @error then 
    msgbox(0,"Error","Unable to create VLC object")
    exit
endif
;msgbox(0,"",$vlc.versioninfo) ; uncomment this line if you'd like confirmation that we're successfully communicating with VLC

dim $options[1]
$options[0]=":vout-filter=deinterlace"
enum $VLCPlayListInsert=00000001,$VLCPlayListReplace=00000002,$VLCPlayListAppend=00000004,$VLCPlayListGo=00000008,$VLCPlayListCheckInsert=00000010

$vlc.addTarget($file, $options,$VLCPlayListGo,0)

What it does is:

1. Successfully create a VLC object

2. Successfully communicate with that object

3. Starts up VLC

4. But AutoIt errors out immediately after starting up VLC

5. VLC will successfully play the file until you close down the AutoIt error

I believe that we're 90% of the way there; the objective being to start VLC via ActiveX with the view to allow full control over the VLC object. The error is caused by the $vlc.addTarget() line, so it's probably simply means we have the wrong variable type in the one of the fields. That's what we're here to figure out together. I have posted my code and asked for assistance in the VLC forum etc (see the above link) but I haven't received any reply. Hence, it's up to us AutoIt people to work out how to start up VLC via ActiveX on our own.

Reference Material

To figure out what might be wrong with the addTarget line, here are some VLC resources:

http://wiki.videolan.org/ActiveX_Controls

This page tells us the format for addTarger is: addTarget(uri as String, options, mode as VLCPlaylistMode, Position as Long)

http://wiki.videolan.org/ActiveX/Delphi

This gives us an example of using ActiveX via Delphi

Edited by Zaxon
Link to comment
Share on other sites

Hi!

The error is gone, but still this error.

D:\src\vlc-0.8.6a\test3.au3 (35) : ==> The requested action with this object has failed.: 
$item = $PlayListItems.add($file,$name,$options,$itemID) 
$item = $PlayListItems.add($file,$name,$options,$itemID)^ ERROR

Changed the script a bit, addtarged is deprecated?

#include <Constants.au3>

$file = "c:\temp\HowTo_Integrate_Addons.avi"
$name = "Howto ?"

Dim $options[1], $itemID

$VLCViewer1 = ObjCreate("VideoLAN.VLCPlugin.2")
If @error Then
    MsgBox(0, "Error", "Unable to create VLC object")
    Exit
EndIf

$SinkVNCObject = ObjEvent($VLCViewer1, "VLCControl_", "IVLCControl2") ; Assign events to UDFs starting with VLCControl_
$SinkVNCObject = 0  ; Stop IE Events ??VLC ?? from helpfile, it stops autoit from "erroring out"

$AutoLoop = $VLCViewer1.AutoLoop = 1
$AutoPlay = $VLCViewer1.AutoPlay = 0

$options[0] = ":vout-filter=deinterlace"

Enum $VLCPlayListInsert = 1, $VLCPlayListInsertAndGo = 9, $VLCPlayListReplace = 2, $VLCPlayListReplaceAndGo = 10, $VLCPlayListAppend = 4, $VLCPlayListAppendAndGo = 12, $VLCPlayListCheckInsert = 16

$VLC_PlayListObj = $VLCViewer1.playlist ()
;$ok = $VLC_PlayListObj.Stop
$PlayListItems = $VLC_PlayListObj.items ()
$NumbersInPlayList = $PlayListItems.count ()
MsgBox(0, "Number of items in playlist", $NumbersInPlayList)
;[00000293] main playlist debug: adding playlist item `D:\src\vlc-0.8.6a\test3.au3' ( D:\src\vlc-0.8.6a\test3.au3 )
;[00000293] main playlist debug: adding playlist item `/ErrorStdOut' ( /ErrorStdOut )
; I get 2 here...

$PlayListItems.clear ()
;remove script and /ErrStdOut...

$NumbersInPlayList = $PlayListItems.count ()
MsgBox(0, "Number of items in playlist(0)", $NumbersInPlayList)

;$id must be ref...
$item = $PlayListItems.add ($file, $name, $options, $itemID)
; From OLE/COM Object View /or vlc-source
; [helpstring("Add a playlist item.")]
; HRESULT add([in] BSTR uri, [in, optional] VARIANT name, [in, optional] VARIANT options, [out, retval] long* itemId);
;  -----------------------------------------------------------------------------------------------^^^^^^^^^^^^^^^^----
; A pointer... in helpfile this is not working...

$NumbersInPlayList = $PlayListItems.count ()
MsgBox(0, "Number of items in playlist ? ", $NumbersInPlayList)
;$PlayListItems.Play()


Func VLCPLayList_Add($uri, $name, $options, $id)

EndFunc   ;==>VLCPLayList_Add
Link to comment
Share on other sites

The error is gone, but still this error.

D:\src\vlc-0.8.6a\test3.au3 (35) : ==> The requested action with this object has failed.: 
$item = $PlayListItems.add($file,$name,$options,$itemID) 
$item = $PlayListItems.add($file,$name,$options,$itemID)^ ERROR
It seems like we've taken a step backwards. VLC doesn't open at all with this code.

Changed the script a bit, addtarged is deprecated?

addTarget is definately still listed as a valid method in all the reference material.
Link to comment
Share on other sites

  • 2 weeks later...

So as a group we can't figure out how to start VLC via ActiveX? If this is the case, then that's a pity, since we're about 90% of the way there already. I can already start it, but one of the types I'm passing to the call is incorrect.

Link to comment
Share on other sites

  • 1 year later...

I have sucessfully used AutoIt to communicate with the tcp interface of vlc. It should be suitable. (I know this thread is dead,just posting this here so people searching will find an answer.)

http://www.autoitscript.com/forum/index.php?showtopic=76230

Edited by P5ych0Gigabyte
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...