Calling vlc.var.set(input, "time") in input callback

Discuss your Lua playlist, album art and interface scripts.
kuway
New Cone
New Cone
Posts: 2
Joined: 02 Aug 2013 08:17

Calling vlc.var.set(input, "time") in input callback

Postby kuway » 02 Aug 2013 09:18

Hi,
I'm working on a script which can skip some sections I'm not interested in a video file, for example, skip the commercials or timeout section for a sports game. I think this can be done by implementing a VLC extension lua module.

The basic algorithm is like below, when the first time I watch the video, I skip these sections manually, and during the playback, I keep the start-end positions of each skipped sections in the script, and finally write down those data into a file when the playback ended. Next time when I play the same video file, the script will load the skipped sections, and whenever the playback time reach some skip section, the script will skip it by calling vlc.var.set(input, "time", nextPos).

However, I was blocked because when I call vlc.var.set(input, "time", nextPos) in the input callback function, VLC freeze and doesn't response to any user action, I can close the VLC main window, but the process is still alive so I need to use the task manager to kill the process. I try to put the code piece in another functions like activate() and input_changed(), and it works fine. I guess maybe do it in the callback function may hit some deadlock, but as long as this issue exist, there should be no other way to do my subject. Does anyone know how to work around this issue?

Below is the sample code to reproduce this issue, I work on a Windows 7 PC, VLC version 2.07,

-- Extension description
function descriptor()
return {
title = "Change Time Test" ;
version = "1.0" ;
author = "Kuway" ;
url = 'http://www.google.com';
shortdesc = "Change play position(time) in lua";
description = "Try to change position(time) of input in the input listener callback";
capabilities = { "input-listener" }
}
end

input = 0


function input_event_handler(var, old, new, data)

local CurrentPos = vlc.var.get(input, "time")

if CurrentPos % 10 < 1 then
vlc.var.set(input, "time", CurrentPos + 5)
end

end

function input_changed()
if input ~=0 then
-- Delete old callback
vlc.var.del_callback(input, "intf-event", input_event_handler, "Change time")
end

input = vlc.object.input()

if input ~= 0 then
vlc.var.add_callback(input, "intf-event", input_event_handler, "Change time")
end
end


function activate()
if vlc.object.input() then
input_changed()
end
end


function deactivate()
if input then
vlc.var.del_callback(input, "intf-event", input_event_handler, "Change time")
end
end

function meta_changed()
end

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: Calling vlc.var.set(input, "time") in input callback

Postby mederi » 02 Aug 2013 15:13

The same idea is on my to-do list of enhancements for my Subtitler extension (if subtitle text starts with [SKIP] or [MUTE] command, then perform appropriate action). O.K. I am going to look at it now, whether I am able to help you.

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: Calling vlc.var.set(input, "time") in input callback

Postby mederi » 02 Aug 2013 22:50

Please test the code and read my comments in function input_event_handler().

Code: Select all

-- Extension description function descriptor() return { title = "Change Time Test - revision" ; version = "1.0" ; author = "Kuway" ; url = 'http://www.google.com'; shortdesc = "Change play position(time) in lua"; description = "Try to change position(time) of input in the input listener callback"; capabilities = { "input-listener" } } end input = 0 parts_to_skip = {{5,10}, {20,28}} -- start time, end time couples like in subtitles function input_event_handler(var, old, new, data) local CurrentPos = vlc.var.get(input, "time") -- Watch values in VLC menu: Tools -> Messages window. vlc.msg.info("[test] CurrentPos=" .. CurrentPos .. " (".. CurrentPos % 10 ..") / os.clock()=".. os.clock() .." / Event code: new=".. new) -- Use subtitling core from Subtitler (lite) extension if you do not have a better idea. if not skip then skip_example=parts_to_skip[1] if CurrentPos>=skip_example[1] and CurrentPos<skip_example[2] then skip=skip_example --(1) VLC-1.1.x only: --vlc.var.set(input, "time", skip[2]) --(1x) --(2) VLC-2.0.x workaround according to a solution in Sampler 1.1 extension: local duration = vlc.var.get(input,"length") vlc.var.set(input,"position", skip[2] / duration) --(2x) vlc.msg.info("[test] !!! Go to new position (time) !!!") end else if CurrentPos>=skip[2] or CurrentPos<skip[1] then skip=nil end end --[[ if CurrentPos % 10 < 1 then vlc.var.set(input, "time", CurrentPos + 5) end --]] end function input_changed() if input ~=0 then -- Delete old callback vlc.var.del_callback(input, "intf-event", input_event_handler, "Change time") end input = vlc.object.input() if input ~= 0 then vlc.var.add_callback(input, "intf-event", input_event_handler, "Change time") end end function activate() if vlc.object.input() then input_changed() end end function deactivate() if input then vlc.var.del_callback(input, "intf-event", input_event_handler, "Change time") end end function meta_changed() end
http://trac.videolan.org/vlc/ticket/6527#comment:3
...
As a workaround, set the position instead of time:

Code: Select all

-- vlc.var.set(input, "time", goto_time) local duration = vlc.input.item():duration() vlc.var.set(input,"position", goto_time / duration)
...
Subtitler (lite)

evilperro
New Cone
New Cone
Posts: 9
Joined: 10 Mar 2013 17:50

Re: Calling vlc.var.set(input, "time") in input callback

Postby evilperro » 03 Aug 2013 13:51

The same idea is on my to-do list of enhancements for my Subtitler extension (if subtitle text starts with [SKIP] or [MUTE] command, then perform appropriate action). O.K. I am going to look at it now, whether I am able to help you.
As I requested here please also try to implement a feature where the user himself can choose keywords that will prompt the skip. This would work well with series that have an intro-song that is subbed. With your approach the uploader of the .srt file has to write these commands. Sure the user could manually insert the commands in all the subtitle files in a given folder using search and replace or some more advanced software that could autoamte it, but would be far simpler [for user] if keywords could just be added to a list which the extension look for when a given video file is played.

Thanks for getting the ball rolling, I can't believe after all these years this hasn't been done yet. Not in other players as well it seems, tried googling it. Sure there's the chapter skip, but not all videos have chapters.


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 5 guests