2011-05-16 15 views
18

Parece que debería ser simple, pero voy con las manos vacías aquí. Intento hacer un script VLC simple que compruebe si el botón "aleatorio" está activado, y si es así cuando salta a un archivo aleatorio, en lugar de comenzar en el tiempo = 0, comienza en un tiempo aleatorio.VLC Scripting con Lua: ¿Salta a una hora específica en un archivo?

Hasta ahora, me parece que debería ser un guión de la lista de reproducción y puedo obtener la duración del objeto de la lista de reproducción, pero en this documentation page o en Google, parece que no encuentro ninguna manera de saltar a un tiempo desde dentro del script Lua. ¿Alguien tiene más experiencia en controlar la reproducción de VLC con Lua?

+0

que me recorrió la documentación y el código fuente y que parece * * no es posible. Probablemente deberías probar tu suerte en los foros de VideoLAN http://forum.videolan.org/viewforum.php?f=29. – ponzao

+1

Esta pregunta en los foros de VideoLAN, donde alguien lanza repetidamente VLC con una determinada opción '--start-time', parece relacionada: http://forum.videolan.org/viewtopic.php?f=29&t=90656 – HostileFork

Respuesta

21

En realidad, la documentación dice que puede hacerlo ... aunque no en pocas palabras. Esto es lo que dice acerca de la interfaz de programas de análisis reproducción:

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) 

Si usted sigue a través de la descripción de playlist.add() dice que los artículos tienen una gran lista de campos que puede proporcionar. Hay muchas opciones (.name, .title, .artist, etc.) Pero el único requerido parece ser .path ... que es "la ruta/URL completa del artículo".

No hay mención explícita de dónde buscar, pero uno de los parámetros que se pueden elegir para proporcionar es .options, dice que "una lista de opciones VLC. Da fullscreen como un ejemplo. Si un paralelo a --fullscreen ?! obras, pueden otras opciones de línea de comandos como --start-time y --stop-time trabajo, así

En mi sistema que hacen, y aquí está el guión

-- 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 
+28

Diversión hecho: esta noche aprendí Lua solo para resolver esta pregunta sin respuesta. :) – HostileFork

5

Sólo tiene que utilizar esto:

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

Hay un método de búsqueda en common.lua.

ejemplos de uso:

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