From 614d1e34bc583e888d040f4a2ff36374db941693 Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Sat, 12 Oct 2019 22:25:01 +0200 Subject: [PATCH] splitvideo: Split video a timestamp (cmdline + VLC-plugin). --- .../share/vlc/lua/extensions/splitvideo.lua | 84 +++++++ splitvideo/splitvideo | 233 ++++++++++++++++++ 2 files changed, 317 insertions(+) create mode 100644 splitvideo/dotlocal/share/vlc/lua/extensions/splitvideo.lua create mode 100755 splitvideo/splitvideo diff --git a/splitvideo/dotlocal/share/vlc/lua/extensions/splitvideo.lua b/splitvideo/dotlocal/share/vlc/lua/extensions/splitvideo.lua new file mode 100644 index 0000000..3833a52 --- /dev/null +++ b/splitvideo/dotlocal/share/vlc/lua/extensions/splitvideo.lua @@ -0,0 +1,84 @@ +--[[ +INSTALLATION (create directories if they donot exist): +- put the file in the VLC subdir /lua/extensions, by default: +* Windows (all users): %ProgramFiles%\VideoLAN\VLC\lua\extensions\ +* Windows (current user): %APPDATA%\VLC\lua\extensions\ +* Linux (all users): /usr/share/vlc/lua/extensions/ +* Linux (current user): ~/.local/share/vlc/lua/extensions/ +* Mac OS X (all users): /Applications/VLC.app/Contents/MacOS/share/lua/extensions/ +- Restart VLC. +- The extension can then be found in the menu: + View > Split video in two +- It requires 'splitvideo' from + https://gitlab.com/ole.tange/tangetools/tree/master/splitvideo + to be in $PATH +]]-- + +--[[ Extension description ]] + +function descriptor() + return { title = "SplitVideo" ; + version = "1.0" ; + author = "Ole Tange" ; + shortdesc = "Split video at the current time"; + description = "

Split Video

" + .. "When you're playing a file, use Split Video to " + .. "split the file into two files at the current time stamp. " ; + url = "https://gitlab.com/ole.tange/tangetools/tree/master/splitvideo" + } +end + +--[[ Hooks ]] + +-- Activation hook +function activate() + local filename,secs = filename_secs() ; + d = vlc.dialog("Split Video") ; + d:add_label("Split ".. filename .. " at " .. secs .. "?") ; + d:add_button("Split", splitvideo) ; + d:add_button("Cancel", close) ; + d:show() ; + vlc.msg.dbg("[Split Video] Activated") ; +end + +function filename_secs() + -- absolute filename and current play time in seconds + -- get the current playing file + local item = vlc.input.item() + -- extract its URI + local uri = item:uri() + -- decode %foo stuff from the URI + local filename = vlc.strings.decode_uri(uri) + -- remove 'file://' prefix which is 7 chars long + filename = string.sub(filename,8) + -- maybe: + vlc.msg.dbg("[SplitVideo/filename_secs] Filename " .. filename) + input = vlc.object.input() + local elapsed_secs = vlc.var.get(input, "time")/1000000 + + return filename,elapsed_secs +end + +function splitvideo() + local filename,secs = filename_secs() + -- shell quote the filename + file, _ = filename:gsub("([\002-\009\011-\026\\#?`(){}%[%]^*<>=~|; \"!$&'\130-\255])", "\\%1") + file, _ = file:gsub("\n", "'\n'") + os.execute("splitvideo " .. secs .. " " .. file) + close() +end + + +function deactivate() + -- Deactivation hook + vlc.msg.dbg("[SplitVideo] Deactivated") + vlc.deactivate() +end + +function close() + deactivate() +end + +-- This empty function is there, because vlc pested me otherwise +function meta_changed() +end diff --git a/splitvideo/splitvideo b/splitvideo/splitvideo new file mode 100755 index 0000000..d9d5233 --- /dev/null +++ b/splitvideo/splitvideo @@ -0,0 +1,233 @@ +#!/usr/bin/perl -w + +=pod + +=head1 NAME + +splitvideo - Split video at time stamp + + +=head1 SYNOPSIS + +B time videofile + + +=head1 DESCRIPTION + +B splits I at I