Подтвердить что ты не робот

VLC Scripting с Lua: переход к определенному времени в файле?

Кажется, это должно быть просто, но я прихожу сюда с пустыми руками. Я пытаюсь сделать простой VLC script, который проверяет, включена ли "случайная" кнопка, и если это так, когда она перескакивает в случайный файл, вместо запуска в момент времени = 0, она начинается в произвольное время.

До сих пор мне казалось, что это должен быть плейлист script, и я могу получить продолжительность от объекта плейлиста, но в этой странице документации или в Google, я не могу найти способ перейти к определенному времени из Lua script. Кто-нибудь имеет больше опыта в управлении воспроизведением VLC с помощью Lua?

4b9b3361

Ответ 1

Собственно, документация говорит, что вы можете это сделать... хотя и не так много слов. Вот что он говорит о интерфейсе для парсеров плейлистов:

VLC Lua playlist modules should define two functions:
   * probe(): returns true if we want to handle the playlist in this script
   * parse(): read the incoming data and return playlist item(s)
        Playlist items use the same format as that expected in the
        playlist.add() function (see general lua/README.txt)

Если вы перейдете к описанию playlist.add(), он говорит, что элементы имеют большой список полей, которые вы можете предоставить. Существует множество вариантов выбора (.name, .title, .artist и т.д.), Но единственное, что требуется, похоже, .path... которое представляет собой "полный путь/URL-адрес элемента".

Здесь нет явного упоминания о том, где искать, но один из параметров, который вы можете выбрать, - это .options, который называется "списком параметров VLC". В качестве примера он дает fullscreen. --fullscreen работает, могут ли другие параметры командной строки, такие как --start-time и --stop-time?

В моей системе они работают, и здесь script!

-- randomseek.lua
--
-- A compiled version of this file (.luac) should be put into the proper VLC
-- playlist parsers directory for your system type.  See:
--
--   http://wiki.videolan.org/Documentation:Play_HowTo/Building_Lua_Playlist_Scripts
--
-- The file format is extremely simple and is merely alternating lines of
-- filenames and durations, such as if you had a file "example.randomseek"
-- it might contain:
--
--     foo.mp4
--     3:04
--     bar.mov
--     10:20
--
-- It simply will seek to a random location in the file and play a random
-- amount of the remaining time in the clip.

function probe()
    -- seed the random number since other VLC lua plugins don't seem to
    math.randomseed(os.time())

    -- tell VLC we will handle anything ending in ".randomseek"
    return string.match(vlc.path, ".randomseek$")
end

function parse()
    -- VLC expects us to return a list of items, each item itself a list
    -- of properties
    playlist = {}

    -- I'll assume a well formed input file but obviously you should do
    -- error checking if writing something real
    while true do
       playlist_item = {}

       line = vlc.readline()
       if line == nil then
           break --error handling goes here
       end

       playlist_item.path = line

       line = vlc.readline()
       if line == nil then
           break --error handling goes here
       end

       for _min, _sec in string.gmatch( line, "(%d*):(%d*)" )
           do
               duration = 60 * _min + _sec
           end

       -- math.random with integer argument returns an integer between
       -- one and the number passed in inclusive, VLC uses zero based times
       start_time = math.random(duration) - 1
       stop_time = math.random(start_time, duration - 1)

       -- give the viewer a hint of how long the clip will take
       playlist_item.duration = stop_time - start_time

       -- a playlist item has another list inside of it of options
       playlist_item.options = {}
       table.insert(playlist_item.options, "start-time="..tostring(start_time))
       table.insert(playlist_item.options, "stop-time="..tostring(stop_time))
       table.insert(playlist_item.options, "fullscreen")

       -- add the item to the playlist
       table.insert( playlist, playlist_item )
    end

    return playlist
end

Ответ 2

Просто используйте это:

vlc.var.set(input, "time", time)

Ответ 3

Существует метод поиска в common.lua.

Примеры использования:

require 'common'
common.seek(123) -- seeks to 02m03s
common.seek("50%") -- seeks to middle of video