|
@@ -15,11 +15,60 @@
|
|
|
-- along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
+-- Margin before and after a clip (in seconds)
|
|
|
+local clip_margin = 0.4
|
|
|
+assert(clip_margin >= 0.0)
|
|
|
+
|
|
|
+-- How loud should noise be to be considered a sound?
|
|
|
+local audio_treshold = 0.01
|
|
|
+assert(audio_treshold > 0.0 and audio_treshold <= 1.0)
|
|
|
+
|
|
|
+-- Minimum clip length (in seconds)
|
|
|
+-- Sounds shorter than that will be considered noise and cut.
|
|
|
+local min_clip_length = 0.2
|
|
|
+assert(min_clip_length > 0.0)
|
|
|
+
|
|
|
+-- Minimum silence length to skip (in seconds)
|
|
|
+local min_skip_length = 2.0
|
|
|
+assert(min_skip_length > 2 * clip_margin)
|
|
|
+
|
|
|
+
|
|
|
local enabled = false
|
|
|
local minutes = {}
|
|
|
local skips = {}
|
|
|
|
|
|
+
|
|
|
+function fix_boundaries()
|
|
|
+ -- Merge skips across minutes (required for next step)
|
|
|
+ for ia, a in pairs(skips) do
|
|
|
+ for ib, b in pairs(skips) do
|
|
|
+ if ia ~= ib and (b[1] - a[2] < min_clip_length) then
|
|
|
+ table.insert(skips, {a[1], b[2]})
|
|
|
+
|
|
|
+ if ia > ib then
|
|
|
+ table.remove(skips, ia)
|
|
|
+ table.remove(skips, ib)
|
|
|
+ else
|
|
|
+ table.remove(skips, ib)
|
|
|
+ table.remove(skips, ia)
|
|
|
+ end
|
|
|
+
|
|
|
+ return fix_boundaries()
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ -- Add margin when someone stops talking right as the minute rolls over
|
|
|
+ for _, a in pairs(skips) do
|
|
|
+ if a[1] > 0.0 and a[1] % 60.0 == 0.0 then
|
|
|
+ a[1] = a[1] + clip_margin
|
|
|
+ end
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
function load_minute(minute)
|
|
|
+ if minutes[minute] == "loading" then return end
|
|
|
+
|
|
|
local utils = require("mp.utils")
|
|
|
local scripts_dir = mp.find_config_file("scripts")
|
|
|
local cutitoutpy = utils.join_path(scripts_dir, "cutitout_shared/cutitout.py")
|
|
@@ -31,13 +80,31 @@ function load_minute(minute)
|
|
|
name = "subprocess",
|
|
|
capture_stdout = true,
|
|
|
playback_only = false,
|
|
|
- args = { "python3", cutitoutpy, video_path, tostring(minute - 1) }
|
|
|
+ args = {
|
|
|
+ "python3", cutitoutpy, video_path, tostring(minute - 1),
|
|
|
+ tostring(clip_margin), tostring(audio_treshold),
|
|
|
+ tostring(min_clip_length), tostring(min_skip_length),
|
|
|
+ }
|
|
|
}, function(res, val, err)
|
|
|
new_skips = loadstring(val.stdout)()
|
|
|
|
|
|
- for _, skip in pairs(new_skips) do table.insert(skips, skip) end
|
|
|
+ local seconds_skippable = 0.0
|
|
|
+ for _, skip in pairs(new_skips) do
|
|
|
+ table.insert(skips, skip)
|
|
|
+ seconds_skippable = seconds_skippable + (skip[2] - skip[1])
|
|
|
+ end
|
|
|
+
|
|
|
+ fix_boundaries()
|
|
|
minutes[minute] = "loaded"
|
|
|
+
|
|
|
print(tostring(#new_skips) .. " skips loaded for minute " .. tostring(minute - 1))
|
|
|
+ print(tostring(math.floor(seconds_skippable)) .. " seconds skippable in minute " .. tostring(minute - 1))
|
|
|
+
|
|
|
+ -- If majority of the minute is skippable, keep looking for skips
|
|
|
+ -- (so silent videos portions lasting more than 2 minutes get skipped in one go)
|
|
|
+ if seconds_skippable > 30 then
|
|
|
+ load_minute(minute + 1)
|
|
|
+ end
|
|
|
end)
|
|
|
end
|
|
|
|