Created
February 4, 2020 00:22
-
-
Save The0x539/6f16d4463a925e59b63738dcfb9b89f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Copyright (c) 2020, The0x539 <[email protected]> | |
-- | |
-- Permission to use, copy, modify, and distribute this software for any | |
-- purpose with or without fee is hereby granted, provided that the above | |
-- copyright notice and this permission notice appear in all copies. | |
-- | |
-- THE SOFTWARE IS PROVIDED 'AS IS' AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
local tr = aegisub.gettext | |
script_name = tr'Make clip' | |
script_description = tr'Encode a hardsubbed clip encompassing the current selection' | |
script_author = 'The0x539' | |
script_version = '0.1' | |
function make_clip(subs, sel, _) | |
local t1, t2 = math.huge, 0 | |
for _, i in ipairs(sel) do | |
t1 = math.min(t1, subs[i].start_time) | |
t2 = math.max(t2, subs[i].end_time) | |
end | |
local t1, t2 = t1/1000, t2/1000 | |
local props = aegisub.project_properties() | |
local vid = props.video_file | |
local subs = aegisub.decode_path("?script\\") .. aegisub.file_name() | |
--local out = vid:gsub('.m[kp][v4]$', '') .. ('_%.3f-%.3f'):format(t1, t2) .. '.mp4' | |
local out = subs:sub(1, -5) .. ('_%.3f-%.3f'):format(t1, t2) .. '.mp4' | |
local cmd = table.concat({ | |
'mpv', | |
'--sub-font-provider=auto', | |
'--start=%.3f', | |
'--end=%.3f', | |
'"%s"', | |
'--sub-file="%s"', | |
'--vf=format=yuv420p', | |
'--o="%s"' | |
}, ' '):format(t1, t2, vid, subs, out) | |
aegisub.log(cmd) | |
local tmp = aegisub.decode_path('?video\\tmp.bat') | |
local f = io.open(tmp, 'w') | |
f:write(cmd) | |
f:close() | |
local p = io.popen(tmp) | |
local output = p:read('*a') | |
aegisub.log(output) | |
p:close() | |
os.execute('del ' .. tmp) | |
end | |
aegisub.register_macro(script_name, script_description, make_clip) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment