-
-
Save Moodkiller/7947619c2e42904cf17618045c956fe8 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, mod by MK' | |
script_version = '0.1.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 mpv = "mpv" | |
local props = aegisub.project_properties() | |
local vid = props.video_file | |
local video = aegisub.decode_path("?video").."\\" .. aegisub.project_properties().video_file:gsub("^.*\\","") | |
local subs = aegisub.decode_path("?script\\") .. aegisub.file_name() | |
--local out = vid:gsub('.m[kp][v4]$', '') .. ('_%.3f-%.3f'):format(t1, t2) .. '.mp4' | |
local out = aegisub.decode_path("?video").."\\" .. aegisub.file_name():sub(1, -5) .. ('_%.3f-%.3f'):format(t1, t2) .. '.mp4' | |
--local out = video .. ('_%.3f-%.3f'):format(t1, t2) .. '.mp4' | |
local cmd = table.concat({ | |
quo(mpv), | |
'--sub-font-provider=auto', | |
'--start=%.3f', | |
'--end=%.3f', | |
quo(video), | |
'--sub-file='..quo(subs), | |
'--vf=format=yuv420p', | |
'--o='..quo(out), | |
'\n@pause' | |
}, ' '):format(t1, t2, vid, subs, out) | |
aegisub.log(cmd) | |
--local tmp = aegisub.decode_path('?video\\tmp.bat') | |
local tmp = aegisub.decode_path('?video') .. "\\" .. aegisub.file_name():sub(1, -5) .. ('_%.3f-%.3f'):format(t1, t2) .. '.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 | |
-- This little function takes a string and wraps it in quotation marks. | |
function quo(x) x="\""..x.."\"" return x 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
Change log: 0.1.1 (I'm probably doing this wrong...)