Altering "time", adding hotkeys via LUA

Discuss your Lua playlist, album art and interface scripts.
pie.rob
New Cone
New Cone
Posts: 2
Joined: 09 May 2012 19:30

Altering "time", adding hotkeys via LUA

Postby pie.rob » 09 May 2012 19:45

Hello all,

I am a novice, but I have been attempting to write an LUA script which will get the current video's time, subtract .0416 (roughly 1/24 of a second to simulate backing up a frame), and move the playback to the new time. For a few days I have been working at this end with no success! I do not understand quite how to get the script to run. I have also decompiled hotkeys.luac and attempted to add the F12 hotkey to this function using the sample. I thank any of you for your time and efforts to help me. Here is my code:

Code: Select all

local common = require ("common") bindings = { ["F12] = "Previous" } function prevframe() --Time altering function local input = vlc.object.input() vlc.playlist.pause() var.get(input,"time") skip_back ="time"-.0416 vlc.var.set(input, "time", skip_back) end --all below taken and modified from hotkeys.luac function action(func, delta) return { func = func, delta = delta or 0, last = 0, times = 0 } end actions = { ["Previous"] = action(prevframe) } action = nil queue = {} function action_trigger(action) print("action_trigger:", tostring(action)) local a = actions[action] if a then do local ok, msg = pcall(a.func) if not ok then vlc.msg.err("Error while executing action `") end end else vlc.msg.err("Key `" .. key .. "' points to unknown action ") end end function key_press(var, old, key, data) print("key_press:", tostring(key)) if bindings[key] then action_trigger(bindings[key]) else vlc.msg.err("Key `" .. key .. "' isn't bound to any action.") end end vlc.var.add_callback(vlc.object.libvlc(), "key-pressed", key_press) while true do repeat until not vlc.misc.lock_and_wait() end vlc.var.del_callback(vlc.object.libvlc(), "key-pressed", key_press)
I compiled this file and put into the lua/intf folder in my VLC 2.0.1 Twoflower installation. I'm not sure if the code will even work, or if the .luac file is being recognized by VLC. Could anyone point me in the right direction? I appreciate any comments or criticism.

Rob

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: Altering "time", adding hotkeys via LUA

Postby mederi » 10 May 2012 19:29

I also learn Scripting VLC in Lua. So far I have learnt how to use playlist and extension script. I do not know much about interface scripts yet. I think that nobody has worked with them here yet.
So you would like to make a hotkey with "Previous frame" feature.
I can see a mistake in your code. You should assign a value to a variable and do not forget to use "vlc." with functions described in VLC Lua "README" document.

Code: Select all

current_time = vlc.var.get(input,"time") skip_back = current_time - .0416 vlc.var.set(input, "time", skip_back)
If it will not work the way you want, then try to make some extension script containing simple dialog box with "Previous frame" button instead of interface script.
You can also use non-compiled scripts with ".lua" file extension as they have been used in VLC1.

I have just realised that MiniLyrics works with VLC through custom interface script that has to be turned on in preferences first, so it starts together with VLC: viewtopic.php?f=2&t=100859#p340369

If somebody knows more about interface scripts, then please write here something about it, what they are capable of, how a custom interface can help user to customize VLC, difference with extension scripts, ...

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

VLC Extension: Previous frame

Postby mederi » 10 May 2012 22:19

Something like this:

Code: Select all

-- "previous frame.lua" -- VLC Extension script function descriptor() return { title = "Previous frame" } end function activate() dlg = vlc.dialog("Previous frame") w1 = dlg:add_text_input("25.000", 1, 1, 2, 1) w2 = dlg:add_button("Previous frame", click_PrevFrame, 1, 2, 1, 1) w3 = dlg:add_label(1/25 .. " s", 2, 2, 1, 1) end function deactivate() end function close() vlc.deactivate() end function click_PrevFrame() w3:set_text(1/w1:get_text() .. " s") local input = vlc.object.input() --vlc.playlist.pause() current_time = vlc.var.get(input,"time") skip_back = current_time - 1/w1:get_text() vlc.var.set(input, "time", skip_back) end
Just pause playing film, set proper fps and press "Previous frame" button one time or several times. You can also make "Next frame" button or you can rather use VLC's built-in hotkey "e".

pie.rob
New Cone
New Cone
Posts: 2
Joined: 09 May 2012 19:30

Re: Altering "time", adding hotkeys via LUA

Postby pie.rob » 14 May 2012 17:23

Meredi,

Thanks for this information! I knew there must be some novice mistakes in there somewhere ;). I will examine your code and links and see if I can get this working.

cpplinuxdude
New Cone
New Cone
Posts: 1
Joined: 13 Jun 2012 08:33

Re: Altering "time", adding hotkeys via LUA

Postby cpplinuxdude » 13 Jun 2012 10:05

Hi Meredi,

Did you manage to get this working? Which version for VLC does this work for? Any update or additional information would be very helpful as a quick browse of this forum shows a lot of people wish they could get this feature.

Thanks.

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: Altering "time", adding hotkeys via LUA

Postby mederi » 14 Jun 2012 20:22

Here is an update of previous code of "Previous frame" VLC Extension script:

Code: Select all

-- "previous frame.lua" -- VLC Extension script function descriptor() return { title = "Previous frame" } end function activate() create_dialog() end function deactivate() end function close() vlc.deactivate() end function create_dialog() w = vlc.dialog("Previous frame") label_fps = w:add_label("<b>Frames Per Second</b>", 1, 1, 1, 1) label_1frame = w:add_label("<b>1/FPS</b>", 2, 1, 1, 1) w1 = w:add_text_input("25.000", 1, 2, 1, 1) w2 = w:add_label(1/25 .. " s", 2, 2, 1, 1) w3 = w:add_button("Previous frame <<", click_PrevFrame, 1, 3, 1, 1) w4 = w:add_button(">> Next frame ", click_NextFrame, 2, 3, 1, 1) w5 = w:add_html("", 1, 4, 2, 1) w6 = w:add_button("Clear", click_Clear, 2, 5, 1, 1) end function click_PrevFrame() Frame("Previous") end function click_NextFrame() Frame("Next") end function click_Clear() w5:set_text("") end function Frame(action) if Pause_playback() then w2:set_text(1/w1:get_text() .. " s") local input = vlc.object.input() --vlc.playlist.pause() current_time = vlc.var.get(input,"time") frame_duration = 1/w1:get_text() if action=="Previous" then frame_duration=-frame_duration end skip_frame = current_time + frame_duration w5:set_text(skip_frame.."<br />"..current_time.." "..frame_duration.."<br />"..w5:get_text()) vlc.var.set(input, "time", skip_frame) end end function Pause_playback() if vlc.input.is_playing() then status = vlc.playlist.status() --w5:set_text(status.."<br />"..w5:get_text()) if status=="playing" then vlc.playlist.pause() elseif status=="stopped" or status=="unknown" then return false end return true else return false end end
It works quite well with AVI-XVID-MP3 format I usually work with, however it is not perfect. Could anybody test it with different formats you use and/or improve the extension? I do not know whether it is suitable for publishing on http://addons.videolan.org

bmccall
New Cone
New Cone
Posts: 2
Joined: 07 Aug 2012 15:17

Re: Altering "time", adding hotkeys via LUA

Postby bmccall » 07 Aug 2012 15:25

I know nothing about LUA but would like to use your "previous frame" code in VLC. Can you direct me to the place that describes how to accomplish this using a shortcut or actually placing it on the control panel as with the "next frame" that is already available in VLC.

Thanks!

Ben

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

VLC Extension: Previous frame

Postby mederi » 10 Jan 2013 23:02

I have just polished the script as much as I could and added "Numpad 4" and "Numpad 6" hotkeys.
Here it is: VLC Extension: Previous frame

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: Altering "time", adding hotkeys via LUA

Postby Jean-Baptiste Kempf » 10 Jan 2013 23:42

Nice. Does it work well?
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: Altering "time", adding hotkeys via LUA

Postby mederi » 10 Jan 2013 23:51

It works quite well at least with AVI{XVID, MP3} format that I use the most.

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: Altering "time", adding hotkeys via LUA

Postby Jean-Baptiste Kempf » 11 Jan 2013 00:01

TS? MKV?
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: Altering "time", adding hotkeys via LUA

Postby mederi » 11 Jan 2013 00:32

If I find some TS and MKV, I will test them later. You can also try the extension out, can't you? You could run it on all 3 operating systems and share an experience as I am only on Windows XP. Thanks.

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: Altering "time", adding hotkeys via LUA

Postby mederi » 11 Jan 2013 21:11

I tested the extension on a short sample of TS{M2V, M1A} and MKV{AVC1, AAC}. The extension does not work well with these formats if you would like to perform split-second jumps, but it still can be used for longer backward/forward jumps. Tiny jumps work well in AVI{XVID, MP3}.

einer
New Cone
New Cone
Posts: 4
Joined: 20 Aug 2013 19:50

Re: Altering "time", adding hotkeys via LUA

Postby einer » 23 Oct 2013 12:04

Hi mederi!
Thanks for your extension, it is very useful for me. But now that I switched my OS to Windows 8, it does not work anymore. I can see the entry in the View-menu of VLC, but the window does not pop up on click. I used WindowsXP before, where it worked without problems. VLC version is 2.1.0. Could you help me?

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: Altering "time", adding hotkeys via LUA

Postby mederi » 24 Oct 2013 13:06

Edit the script in a text editor. Commnet out or delete two lines, 23 and 26:

Code: Select all

-- vlc.var.add_callback( vlc.object.libvlc(), "key-pressed", key_press ) -- vlc.var.del_callback( vlc.object.libvlc(), "key-pressed", key_press )
This way you eliminate custom hotkeys (Num4 & Num6) in this extension.
add_callback() is not available in VLC-2.1

einer
New Cone
New Cone
Posts: 4
Joined: 20 Aug 2013 19:50

Re: Altering "time", adding hotkeys via LUA

Postby einer » 05 Nov 2013 14:58

Yes, that helped! Thanks a lot!

gatisnolv

Re: Altering "time", adding hotkeys via LUA

Postby gatisnolv » 10 Nov 2014 13:39

Coul someone please explain me how to change the hotkeys to other keys? Specifically the (,) and (.) keys. I tried changing the global variable key codes to both 33 & 34, as well as 188 & 190, because different resources had listed different key codes, - neither of which worked. I also tried remapping the (,) and (.) keys with AutoHotkey to the Numpad4 and Numpad6 keys, and while the keys were remapped correctly, these didn't work when trying to switch to the previous/next frames.

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: Altering "time", adding hotkeys via LUA

Postby mederi » 10 Nov 2014 15:02

Lua Hotkeys work only in VLC-2.0.x and VLC-1.1.x!
What key codes do you see in dialog box in HELP > Logger if you press "," and "." in VLC player? My computer says 44 and 46.

gatisnolv

Re: Altering "time", adding hotkeys via LUA

Postby gatisnolv » 11 Nov 2014 16:31

I didn't realize, the hotkeys worked only in those versions. I have 2.1.5 installed. The logger didn't register any key presses, not just the (,) and (.).
Is it impossible to write a script with such behaviour regardless of the version?

mederi
Big Cone-huna
Big Cone-huna
Posts: 1951
Joined: 15 Mar 2011 16:38
VLC version: 2.0.8
Operating System: Windows Vista/XP

Re: Altering "time", adding hotkeys via LUA

Postby mederi » 11 Nov 2014 22:50

You need to disable hotkeys in the downloaded script for VLC-2.1+ (instructions are provided in one of my previous posts here). You can only use buttons in dialog window of the extension.
As a workaround you could write (and share if you want) an AutoHotkey script. You could find some hints here:
https://forum.videolan.org/viewtopic.ph ... 40#p407066
https://forum.videolan.org/viewtopic.ph ... 36#p403621

gatisnolv

Re: Altering "time", adding hotkeys via LUA

Postby gatisnolv » 02 Dec 2014 18:48

Sorry for taking so long.
I wrote and AutoHotkey script that checked for and launched the Previous frame plug-in window, then activated VLC, and simulated pressing the "Previous frame" and "Next frame" buttons in the now inactive plug-in window.
While the part that checked/launched the plug-in window worked consistently when nothing was playing, it worked less consistently, when a video was playing, I suspect because the script had to find the VLC window name in a substantially longer string of the window, which included the name of the video, that was playing. I tried experimenting by adding cooldown time between actions with less than satisfactory results, and ran out of ideas on how to improve the reliability of this part of the script.
The part that simulated the button presses in the inactive plug-in worked pretty much flawlessly.
Unfortunately I was surprised to notice that the plug-in didn't work as it was supposed to, which had slipped my attention when playing with the plug-in even before writing the script. The customization of the fps jump time did not affect the action of the Previous/Next buttons, when the length of the jump was under a second. In fact, in this case, the "Previous frame" button also triggers a jump forward, and the actual jump with an fps set to 25 is under a second, but much longer than the supposed 0.04s, somewhere around 1/4 to 1/5 of a second, because with around 4-5 presses the time moves by around a second. The VLC built-in e key forward jump on the other hand works consistently. When the fps was set to 1 or under, i.e., the length of the jump was a second or above, the buttons seem to work reliably.
My guess is that there are some more incompatibilities between this script and VLC 2.1.x, not just the hotkeys that have to be disabled, to launch the plug-in window.
I use VLC 2.1.5

Commander238
New Cone
New Cone
Posts: 1
Joined: 27 Dec 2014 21:05
VLC version: 2.1.5
Operating System: Windows 7
Location: Czech Republic

Re: VLC Extension: Previous frame

Postby Commander238 » 27 Dec 2014 22:08

Previous frame extension
Here is an updated version of the script, which does work in VLC 2.1.5. :)
I changed the hotkeys to Alt+W and Alt+E. They only work when the dialog box is focused.
There is still a problem regarding some video formats, that a backward jump shorter than 1/5 sec jumps forward. I can't figure out the reason, the code seems to be correct.
http://238.szm.com/files/previous-frame ... me-2-1.lua


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 13 guests