Get elapsed time of a media file...programmatically

Discuss your Lua playlist, album art and interface scripts.
Carmel88
New Cone
New Cone
Posts: 9
Joined: 25 Jan 2014 23:55

Get elapsed time of a media file...programmatically

Postby Carmel88 » 26 Jan 2014 00:31

1st! Thanks to the person that put the time.lua script together that has been part of my solution so far...

2nd: how do I get the time from VLC running in a normal window on a PC programmatically?

3rd: Is it possible to start a lua extension from the command line? (maybe something like vlc.exe test.mp4 --extraintf myAwesomeLuaStartupScript)

I am using VBA to launch VLC from the command line. I played around with the C# wrapper project but my skill level (or available time) just isn't enough to make a full blown embeddable component that has VLC inside it working smoothly. So I edited "time.lua" so that it will write out the file name and elapsed time to a file...then my vba code reads the file. I set this project down for awhile(months) and just today this extension no longer works.

Any ideas?

Etoh
Blank Cone
Blank Cone
Posts: 60
Joined: 12 Jan 2013 16:33

Re: Get elapsed time of a media file...programmatically

Postby Etoh » 26 Jan 2014 02:34

2nd: how do I get the time from VLC running in a normal window on a PC programmatically?
3rd: Is it possible to start a lua extension from the command line? (maybe something like vlc.exe test.mp4 --extraintf myAwesomeLuaStartupScript)
2nd: Use an interface to access get_var("time") or equivalent.
3rd: Only if it is an interface script.

---

There have been various changes to VLC over the years, so some things which used to work either need to be modified or are just no longer possible. Importantly, many functions have been limited to only work with interface scripts and so no longer work with regular scripts. Similarly, some functionality has been limited to non-Windows operating systems as they were buggy on Windows. See http://www.videolan.org/developers/vlc/share/lua/ for the readmes and existing interface scripts which you can use as reference.

My understanding is that there is no way to "auto-start" a regular script from the standard version of VLC. However, you can tell VLC to load an interface. For example, for a LUA interface script use --extraintf=luaintf --lua-intf=YOURINTERFACENAME (and put the interface file in %ProgramFiles%\VideoLAN\VLC\lua\intf\, etc).

You might be able to use vlc.msg.info(get_var("time")) and send the information via a pipe. To avoid problems you would need to use the --no-quiet command-line switch (to ensure the message gets through) and you might want to check if vlc.object.input() exists (so you don't try and get the time if there is no file open).

One option is to write code to work with an existing VLC LUA or non-LUA interface. For the Syncplay interface script I get the current time through get_var("time") and then pass it to the launching Python script via a socket created through vlc.net.listen_tcp. See: https://raw2.github.com/Uriziel/syncpla ... ncplay.lua

Carmel88
New Cone
New Cone
Posts: 9
Joined: 25 Jan 2014 23:55

Re: Get elapsed time of a media file...programmatically

Postby Carmel88 » 26 Jan 2014 03:29

I will look at the options from Etoh. Thanks.

I did find this ticket: https://trac.videolan.org/vlc/ticket/8097
I agree with the person that submitted the ticket...what's a few cpu cycles compared to a few days of struggling to find a pretty solution?

This seems like a case of elegance vs engineering. I don't have much experience with sockets but maybe that is the elegant method. For now time.lua and my mods to it are broken.

Carmel88
New Cone
New Cone
Posts: 9
Joined: 25 Jan 2014 23:55

Re: Get elapsed time of a media file...programmatically

Postby Carmel88 » 27 Jan 2014 21:03

After looking at Etoh's links and spending a great deal of time convincing myself by example that callbacks and anything that remotely looks like polling is broken for lua in the most recent VLC release. I made a VB winsock connection to an RC interface in VLC. So it works awesome for stopping, starting, seeking, pausing, etc. What is doesn't work for, not very well anyway, is any RC requests that actually require VLC to send something back. If I ask for get_time every second for 100 seconds I only get about 7 responses and they are not timely responses as each takes several seconds. Is this as good as it gets? Am I trying to smash a square peg in a round hole? Why is it so difficult to get the elapsed time from VLC programmatically? Is there some other way that I am not considering?

Etoh
Blank Cone
Blank Cone
Posts: 60
Joined: 12 Jan 2013 16:33

Re: Get elapsed time of a media file...programmatically

Postby Etoh » 27 Jan 2014 22:37

I've not tried RC, but things work fine for me with the Syncplay interface script and VLC 2.1.2 (64-bit) on Windows and various other 2.x versions when connecting with Python (asynchat/asyncore) or Telnet (i.e. raw manual socket connection). The Syncplay interface script does not use callbacks, it uses a command/response system based on net.listen_tcp (rather than net.poll, which did not work properly on Windows). See if the RC connection works fine through Telnet. Also, try using the Syncplay script and regularly (but not constantly) polling with "." (a full stop, followed by a newline terminator if necessary) to see if that works (either through your VB script or through Telnet). What set-up are you using?

bll
New Cone
New Cone
Posts: 9
Joined: 27 Sep 2013 02:21
VLC version: 3.0.2
Operating System: Linux
Contact:

Re: Get elapsed time of a media file...programmatically

Postby bll » 28 Jan 2014 22:17

The telnet interface on windows works for versions <= 2.0.8. For versions > 2.0.8, use the oldrc interface (which does not expose the 'rate' command :-(, but everything else works). I have no trouble getting responses to get_length/get_time, but I'm not using VB either.

Carmel88
New Cone
New Cone
Posts: 9
Joined: 25 Jan 2014 23:55

Re: Get elapsed time of a media file...programmatically

Postby Carmel88 » 29 Jan 2014 08:03

What set-up are you using?
winxp/vb6/vlc

I like your approach because the script should run automatically instead of having to always select it from the view menu. I'll have to give it another try...

Carmel88
New Cone
New Cone
Posts: 9
Joined: 25 Jan 2014 23:55

Re: Get elapsed time of a media file...programmatically

Postby Carmel88 » 29 Jan 2014 16:19

try using the Syncplay script...What set-up are you using?
Here's my vlc launch command:

..\vlc.exe ..\test.mp4 --start-time=600 --rate=2.0 -I intf --extraintf=luaintf --lua-intf syncplay --log -verbose=2 --verbose -objects=+all -vvv --fullscreen --server-port 1234

When I look in the log the only location listed by vlc looking for scripts is ..meta\reader.

Etoh: how do you launch vlc to use with syncplay?

Etoh
Blank Cone
Blank Cone
Posts: 60
Joined: 12 Jan 2013 16:33

Re: Get elapsed time of a media file...programmatically

Postby Etoh » 29 Jan 2014 17:33

Etoh: how do you launch vlc to use with syncplay?
Syncplay (which is a Python application that synchronises playback across multiple instances of VLC) puts the syncplay.lua interface file in %ProgramFiles%\VideoLAN\VLC\lua\intf\ and launches VLC using:

--extraintf=luaintf --lua-intf=syncplay --no-quiet --no-input-fast-seek --no-one-instance --no-one-instance-when-started-from-file --lua-config=syncplay={{port="4123"}}

You only need to include --no-input-fast-seek if you want to enforce precise seeking. I actually specify a random port each time so multiple instances of VLC won't cause conflicts (4123 is the default port for if you do not specify one).

Carmel88
New Cone
New Cone
Posts: 9
Joined: 25 Jan 2014 23:55

Re: Get elapsed time of a media file...programmatically

Postby Carmel88 » 30 Jan 2014 06:43

Ok, got it.

First I must say that syncplay is pretty slick. It does take some configuration to get working. When using VB6, syncplay doesn't like it if the connection is opened and closed repeatedly but works very well if the socket is left open. Also there was some issues with formatting the command. At first I was appending too many vbcrlf and it was confusing the syncplay loop. At the end I am able to get timely responses which is what I need.

I made a command for get-elapsed. The "." command has position in it which works, get-elapsed has less other stuff...it looks like this (basically a modified get-duration):

function get_elapsed ()
-- [Used by get-elapsed command]
local response
local errormsg
local item
local input = vlc.object.input()
if input then
local elapsed_time = vlc.var.get(input, "time")
response = elapsed_time --item:duration()
else
errormsg = noinput
end
return response, errormsg
end

Thanks Etoh!!!

Etoh
Blank Cone
Blank Cone
Posts: 60
Joined: 12 Jan 2013 16:33

Re: Get elapsed time of a media file...programmatically

Postby Etoh » 30 Jan 2014 11:29

Glad that helped. Thanks for sharing your experience of getting it to do what you wanted. The Syncplay interface code was not designed for multiple connections as that was not something that I would be doing.

Etoh
Blank Cone
Blank Cone
Posts: 60
Joined: 12 Jan 2013 16:33

Re: Get elapsed time of a media file...programmatically

Postby Etoh » 23 Feb 2014 00:26

I've updated the syncplay.lua file to fix a bug which meant that VLC would not close because it was still in a loop (i.e. it would disappear but the process would still be running in the background) - see https://raw2.github.com/Uriziel/syncpla ... ncplay.lua for the new version (0.1.7). You might need to update your code accordingly (see history for a list of changes).


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 8 guests