Skip to content

Instantly share code, notes, and snippets.

@ntBre
Created February 12, 2022 18:57
Show Gist options
  • Save ntBre/d191ca52232371caf3e06a22fde3b3cd to your computer and use it in GitHub Desktop.
Save ntBre/d191ca52232371caf3e06a22fde3b3cd to your computer and use it in GitHub Desktop.
Capturing video time stamps to a file in mpv
require 'mp'
FNAME = "timestamps.txt"
local function file_exists(name)
-- from https://stackoverflow.com/a/4991602
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
local function dump_time_stamp()
local exists = file_exists(FNAME)
local f = io.open(FNAME, "a+")
if not exists then
f:write(
"Time stamps\n",
"00:00:00 Introduction\n"
)
end
local time_pos = mp.get_property_number("time-pos")
local time_sec = time_pos % 60
time_pos = time_pos - time_sec
local time_hours = math.floor(time_pos / 3600)
time_pos = time_pos - (time_hours * 3600)
local time_minutes = time_pos/60
f:write(
string.format("%02d:%02d:%02d\n", time_hours, time_minutes, time_sec)
)
f:close()
mp.set_property_bool("pause", true)
end
mp.add_key_binding("Ctrl+c", "copyTime", dump_time_stamp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment