Old 01-09-2019, 08:01 AM   #1
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 826
Default Noob (still) needs help in Lua (VLC extension)

Hi,

this is kind of an off topic question but it also depends some kind on my work in Reaper. And it is complicated.

I often recommend users to cut big videos into clips before using them in Reaper because of Reapers inability to trim videos without rendering. The best method would be to use mkvToolnix to do this. But it needs time stamps in a special format. I found a lua script for VLC which allows to copy the playing time to the clip board. (only windows at the moment, with clip.exe)

So as an absolutely noob I tried to get it to work. And it was kind of fun to finally get the play time in the needed format copied to the clipboard without any hassle. I'm very happy. BUT I want more!

mkvToolnix needs the following format: "00:00:00-00:00:00," while 00 represents whether hours, minutes and seconds. The - represents the "until" and the "," represents the divider for the next time stamps.

I managed to get the first part of it: So if someone plays a movie and clicks at a certain time on the extensions "copy to clipboard", the "01:32:02-" for example gets copied fine. If I repeat it, the time changes of course but the format stays the same.
Now I have this stupid idea to make kind of an A to B method out of it. I want the input counted and separated into even or odd labels. So the first click marks A (odd) and copies the time as "01:32:02-" into the clipboard, the second click marks it as B (or even) and copies the end time as "01:33:24," into the clipboard.

How would I do that? I need a counter which gives the "input" kind of a label independent of the time value. Here is the code of the part I have:
Code:
function click_SAVE()
	local input = vlc.object.input()
	if input then
		local curtime=vlc.var.get(input, "time")
		local curtime=math.floor(curtime/1000)
		local curtime=curtime/1000
		local hours = math.floor(curtime/3600)
		local minutes = math.floor((curtime%3600)/60)
		local seconds = math.floor(curtime%60)
		local timeString = string.format("%02d:%02d:%02d-",hours,minutes,seconds)
		w2:set_text(timeString)
		save_to_clipboard(timeString)
	end
end
If this formatting looks a bit stupid I just did by trial and error to get the format I needed.

So I'm pretty sure before "if input then" I need something that counts and gives the input a number from 1 and 2. Then I need an "If question" for "string.format" if the input has an 1 or 2 label. This would be do it:
Code:
if (number % 2 == 0) then
    00:00:00-
else
    00:00:00,
end
Can anybody help me to get it counting the input? And sorry if this all seems a bit silly. But it would help a lot to just watch a long movie and just sending the time codes one after another into the clipboard. Even better would it be to write it in a text file, but that is another story.

Many thanks in advance.
Eli

Last edited by Eliseat; 01-11-2019 at 01:26 PM. Reason: solved
Eliseat is offline   Reply With Quote
Old 01-09-2019, 09:24 AM   #2
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 7,527
Default

Code:
-- init number to 0 "somewhere"

if number % 2 == 0 then
  -- first case
else
  -- second case
end
number = number + 1
However, the problem of course is how do you keep the value of number around between calls to the function/script. That I can't tell because I don't have experience with how Lua scripts in VLC work. (So this is not really a Lua problem but a problem with the particular environment the language is being used in.)

A hack that should work in most situations is to keep the counter variable saved and loaded in a file but that is of course tedious to implement. There probably is some easier way to do it, but it would require knowledge about the VLC Lua API.
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass, Paul(X)Stretch and λ) :
http://xenakios.wordpress.com/
Xenakios is offline   Reply With Quote
Old 01-09-2019, 09:57 AM   #3
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 826
Default

Quote:
Originally Posted by Xenakios View Post
Code:
-- init number to 0 "somewhere"

if number % 2 == 0 then
  -- first case
else
  -- second case
end
number = number + 1
However, the problem of course is how do you keep the value of number around between calls to the function/script. That I can't tell because I don't have experience with how Lua scripts in VLC work. (So this is not really a Lua problem but a problem with the particular environment the language is being used in.)

A hack that should work in most situations is to keep the counter variable saved and loaded in a file but that is of course tedious to implement. There probably is some easier way to do it, but it would require knowledge about the VLC Lua API.
Ahh, so the number doesn't need to be combined with the input? I will try that. Maybe it works. (That's how I work in this area.)
Eliseat is offline   Reply With Quote
Old 01-09-2019, 10:02 AM   #4
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 7,527
Default

Quote:
Originally Posted by Eliseat View Post
Ahh, so the number doesn't need to be combined with the input? I will try that. Maybe it works. (That's how I work in this area.)
Hmm, maybe I didn't understand your problem correctly.
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass, Paul(X)Stretch and λ) :
http://xenakios.wordpress.com/
Xenakios is offline   Reply With Quote
Old 01-09-2019, 10:11 AM   #5
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 826
Default

Code:
function click_SAVE()
	local input = vlc.object.input()
	if input then
		local curtime=vlc.var.get(input, "time")
		local curtime=math.floor(curtime/1000)
		local curtime=curtime/1000
		local hours = math.floor(curtime/3600)
		local minutes = math.floor((curtime%3600)/60)
		local seconds = math.floor(curtime%60)
		number = 1
		if number % 2 == 0
          then
              local timeString = string.format("%02d:%02d:%02d-",hours,minutes,seconds)
          else
              local timeString = string.format("%02d:%02d:%02d,",hours,minutes,seconds)
        end
        number = number + 1
		w2:set_text(timeString)
		save_to_clipboard(timeString)
	end
end
I tried this but it doesn't copy anything into the clipboard.
Eliseat is offline   Reply With Quote
Old 01-09-2019, 10:20 AM   #6
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 7,527
Default

Quote:
Originally Posted by Eliseat View Post
Code:
function click_SAVE()
	local input = vlc.object.input()
	if input then
		local curtime=vlc.var.get(input, "time")
		local curtime=math.floor(curtime/1000)
		local curtime=curtime/1000
		local hours = math.floor(curtime/3600)
		local minutes = math.floor((curtime%3600)/60)
		local seconds = math.floor(curtime%60)
		number = 1
		if number % 2 == 0
          then
              local timeString = string.format("%02d:%02d:%02d-",hours,minutes,seconds)
          else
              local timeString = string.format("%02d:%02d:%02d,",hours,minutes,seconds)
        end
        number = number + 1
		w2:set_text(timeString)
		save_to_clipboard(timeString)
	end
end
I tried this but it doesn't copy anything into the clipboard.
You declare timeString as a local variable inside the if else statements, so the code outside that won't see the initialized string.

But if you fix that, the logic still of course doesn't fully work since you initialize the number to 1 each time the function is executed.
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass, Paul(X)Stretch and λ) :
http://xenakios.wordpress.com/
Xenakios is offline   Reply With Quote
Old 01-09-2019, 10:26 AM   #7
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 826
Default

Quote:
However, the problem of course is how do you keep the value of number around between calls to the function/script. That I can't tell because I don't have experience with how Lua scripts in VLC work. (So this is not really a Lua problem but a problem with the particular environment the language is being used in.)
In my opinion it should keep the number as long as VLC is open and plays the movie. But for some reason it doesn't even work for the initial number.

And I know a conversation between a noob and a programmer is like teaching math to a little ape.
Eliseat is offline   Reply With Quote
Old 01-09-2019, 10:28 AM   #8
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 826
Default

Quote:
Originally Posted by Xenakios View Post
You declare timeString as a local variable inside the if else statements, so the code outside that won't see the initialized string.

But if you fix that, the logic still of course doesn't fully work since you initialize the number to 1 each time the function is executed.
Haha! This is how I do it!

But thanks for the hints.

Edit: YEAHHHHH!! I made it!

I put the number initializing outside the function and removed the "local".

Many thanks. I learned a lot!
Eliseat is offline   Reply With Quote
Old 01-09-2019, 10:57 AM   #9
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 826
Default

So here is the complete code:
Code:
-- Time2Clip.lua -- VLC extension --
--[[
INSTALLATION:
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\
(create directories if they don't exist)
Restart the VLC.
Then you simply use the extension by going to the "View" menu and selecting it.
Note:
	This extension has been tested for VLC 2.0.1 on Win7 sp1.
	Because the function  save_to_clipboard needs clip.exe, you've to make sure your windows system has it (just type "echo a |clip" in the cmd prompt window to check whether letter "a" has been put in the system clipboard).
	If it doesn't exist, you can download it from here:
	http://www.labnol.org/software/tutorials/copy-dos-command-line-output-clipboard-clip-exe/2506/
--]]


function descriptor()
	return {
		title = "Time2Clip";
		version = "1.0";
		author = "valuex";
		url = 'http://addons.videolan.org/content/show.php?content=149618';
		shortdesc = "Time2Clip";
		description = "<div style=\"background-color:lightgreen;\"><b>just a simple VLC extension </b></div>";
}
end
function activate()
	create_dialog()
end
function deactivate()

end
function close()
	vlc.deactivate()
end

function create_dialog()
	w = vlc.dialog("Time2Clip")
	w1 = w:add_label("<b>Timestamp:</b>",1,1,1,1)
	w2 = w:add_text_input("0",2,1,1,1)
	w3 = w:add_button("jumpto", click_SEEK,1,2,1,1)
	w4 = w:add_button("Save_to_Clip", click_SAVE,2,2,1,1)
end
number = 0
function click_SAVE()
	local input = vlc.object.input()
	if input then
		local curtime=vlc.var.get(input, "time")
		local curtime=math.floor(curtime/1000)
		local curtime=curtime/1000
		local hours = math.floor(curtime/3600)
		local minutes = math.floor((curtime%3600)/60)
		local seconds = math.floor(curtime%60)

		if number % 2 == 0
          then
              timeString = string.format("%02d:%02d:%02d-",hours,minutes,seconds)
          else
              timeString = string.format("%02d:%02d:%02d,",hours,minutes,seconds)
        end
        number = number + 1
		w2:set_text(timeString)
		save_to_clipboard(timeString)
	end
end

function click_SEEK()
	local time_togo = w2:get_text()
	local input = vlc.object.input()
	if input then
		vlc.var.set(input, "time", time_togo)	--jump to specified time
	end
end

function save_to_clipboard(var)
	strCmd = 'echo | set /p dummyName='..var..'|clip'
	os.execute(strCmd)
end
Its origin is the VLC extension Time2Clip https://forum.videolan.org/viewtopic.php?t=101114 which didn't work with VLC 3.0. I managed to get it to work properly and to offer me the right time format. I also changed the output with cmd.exe as it wasn't able to give me the time stamp without a space and break after it.

To use this script put it into the extensions folder of VLC 3.0 and open it per menu/view time2clip. It needs clip.exe which should be installed on windows 7. I have no idea if this works on Win 8 or 10. This needs to be tested.

How does it help? - Play a movie which you want to cut into parts without encoding. Open the extension and click once at the save_to_clip button to copy the first time stamp (paste it directly into mkvtoolnix or into a notepad document) and a second time to copy the second (end) time stamp.
(Okay, this explanation makes no sense so maybe I will create a tutorial in the video section as many poeple run into the problem with cutting videos in Reaper.)

My dream would be to start mkvtoolnix right out of this script and sending the timestamps directly. Have no idea if this is possible. But as long as I know mkvtoolnix can get managed over command line.
Eliseat is offline   Reply With Quote
Old 01-09-2019, 11:29 AM   #10
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 7,527
Default

Quote:
Originally Posted by Eliseat View Post

My dream would be to start mkvtoolnix right out of this script and sending the timestamps directly. Have no idea if this is possible. But as long as I know mkvtoolnix can get managed over command line.
Yeah I was going to ask why not just do it that way? It could of course be that VLC's Lua implementation doesn't allow os.execute, in which case you would out of luck I guess.
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass, Paul(X)Stretch and λ) :
http://xenakios.wordpress.com/
Xenakios is offline   Reply With Quote
Old 01-09-2019, 11:31 AM   #11
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 826
Default

Holy ****!

mkvtoolnix lets you show and copy the code for cutting videos exactly formatted for cmd.exe Theoretically this makes it possible to let the extension start the whole cutting process directly from VLC. This would be awesome! And I never thought it could be so exciting to "program" and automate things like a nerd. Amazing!
Eliseat is offline   Reply With Quote
Old 01-09-2019, 11:36 AM   #12
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 826
Default

Quote:
Originally Posted by Xenakios View Post
Yeah I was going to ask why not just do it that way? It could of course be that VLC's Lua implementation doesn't allow os.execute, in which case you would out of luck I guess.
I guess it allows it because this time2clip already uses a clip.exe to copy the timestamp into the clipboard.

Theoretically everything could be done via VLC extension. Only thing to know is how to get the exact path and filename of the current played video, as this is needed for mkvToolnix to find the video. And of course it needs a final send command which gives the final command to send all timestamps to mkvToolnix and let it do the job. Cool!

I will see if I can get it to run like that. But many, many thanks for your help.
-----------------------------------------------------------------------



Edit: I'm burning right now!

So after a short brainstorming I have the following idea. Would this work?

- getting exact path to the playing video file (and name of course)
- saving the timestamps into a temp file directly into the folder where the playing video is
- adding timestamps as needed
- at the end removing the last "," from the last timestamp (because else it gives an error) and sending the command to start mkvToolnix and give all instruction to begin cutting.

Wait... would this not also be possible from inside Reaper?
- getting the

Last edited by Eliseat; 01-09-2019 at 11:46 AM.
Eliseat is offline   Reply With Quote
Old 01-09-2019, 11:54 AM   #13
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 7,527
Default

Quote:
Originally Posted by Eliseat View Post
Wait... would this not also be possible from inside Reaper?
- getting the
Yes, I think so, video files are not handled differently to audio files for many of the scripting functions.

edit : I tested this works for a selected media item that has a video file :

Code:
local item = reaper.GetSelectedMediaItem(0,0)
local take = reaper.GetActiveTake(item)
local src = reaper.GetMediaItemTake_Source(take)
local src_filename = reaper.GetMediaSourceFileName(src,"")
reaper.ShowConsoleMsg(src_filename.."\n")
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass, Paul(X)Stretch and λ) :
http://xenakios.wordpress.com/
Xenakios is offline   Reply With Quote
Old 01-09-2019, 01:57 PM   #14
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 826
Default

New problem occurred. It was kind of stupid to only let the A and B timestamps copy separately. I need them in one string! First click adds timestamp A to string, second click adds timestamp B to the same string, third click adds "," and a new A string ... etc.

Is this possible?

The problem is: How could I get the actual string and add the new string if they have the same name?


__________________________________________________ ____________



Edit: I learned that something can easily attached to a string with ".." It works if I add a text or something but how could I add string B to string A and so on? Do I need two separate named strings depending of the odd or even number in the counter?


.

Last edited by Eliseat; 01-09-2019 at 02:34 PM.
Eliseat is offline   Reply With Quote
Old 01-09-2019, 03:40 PM   #15
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 826
Default

Okay, it seems this could be done by gathering every new string in a table and giving the whole table out after every new cycle. But I'm to tired for now. My head is close to an explosion.
Eliseat is offline   Reply With Quote
Old 01-10-2019, 01:01 AM   #16
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 826
Default

Okay, I need more help.

In every cycle (with every click) I get a new number and a new "timeString" (timestamp A or B).
If I now create a table and put in the "number" as key and the "timeString" as its value, it should add a new key with value every time.
[0](00:20:22-)
[1](00:21:06)
[2](00:35:17-)
for example.

Is this correct? And would the code look like this?
Code:
tpool{}
tpool[number]=timeString
Because then I could read out the table with ( table.concat( tpool ) )

But it doesn't work.
And this is frustrating.

++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++

Okay, now I get at least the actual timestamp but it doesn't add them to each other rather then only giving out one at the time. But why? Is the adding wrong or the reading?

Code:
if number % 2 == 0
          then
              timeString = string.format("%02d:%02d:%02d-",hours,minutes,seconds)
          else
              timeString = string.format("%02d:%02d:%02d,",hours,minutes,seconds)
        end
        tpool={}
        table.insert(tpool, timeString)
        w2:set_text(table.concat( tpool ))
        save_to_clipboard(table.concat( tpool ))
        number = number + 1

Last edited by Eliseat; 01-10-2019 at 01:27 AM.
Eliseat is offline   Reply With Quote
Old 01-10-2019, 01:32 AM   #17
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 2,404
Default

tpool = {} replaces the table with a new empty one every time. Move that to your initialization code (where number = 0 is) so that it's run only once (or whenever you want to clear all stored values).
cfillion is offline   Reply With Quote
Old 01-10-2019, 01:41 AM   #18
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 826
Default

Quote:
Originally Posted by cfillion View Post
tpool = {} replaces the table with a new empty one every time. Move that to your initialization code (where number = 0 is) so that it's run only once (or whenever you want to clear all stored values).
Ah, good to know. Many thanks.

++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++

That was it! Yeah, now it works.

Now I only need to know how to place a "," separator only every second output in concat.
But I guess it would be easier to remove the last unwanted "," from the whole final string with something like that.
Code:
table.insert(tpool, timeString)
        finalString = table.concat( tpool )
        finalString = finalString:sub(1, -2)
        w2:set_text(finalString)
        save_to_clipboard(finalString)
        number = number + 1
Okay, it works but I don't know why because it also cuts the last sign of the A timestamp but inserts it back if I add the B timestamp. Strange. But exactly what I wanted.

EDIT: Now I know what happens. The string gets cut after the table so every time the concat occurs it will load the whole string without cut. That fits perfectly to my needs. Awesome!

Last edited by Eliseat; 01-10-2019 at 02:45 AM.
Eliseat is offline   Reply With Quote
Old 01-10-2019, 02:28 AM   #19
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 826
Default

For now it works exactly as I wanted but without sending the data to mkvToolnix yet. That will be the next thing. Here is the code:

Code:
-- Time2Toolnix.lua -- VLC extension --
--[[
INSTALLATION:
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\
(create directories if they don't exist)
Restart the VLC.
Then you simply use the extension by going to the "View" menu and selecting it.
Note:
	This extension has been tested for VLC 2.0.1 on Win7 sp1.
	Because the function  save_to_clipboard needs clip.exe, you've to make sure your windows system has it (just type "echo a |clip" in the cmd prompt window to check whether letter "a" has been put in the system clipboard).
	If it doesn't exist, you can download it from here:
	http://www.labnol.org/software/tutorials/copy-dos-command-line-output-clipboard-clip-exe/2506/
--]]


function descriptor()
	return {
		title = "Timestamps to mkvToolnix";
		version = "1.0";
		author = "elisacol";
		url = '';
		shortdesc = "Time2Toolnix";
		description = "<div style=\"background-color:lightgreen;\"><b>Send timestamps to mkvToolnix for cutting videos.</b></div>";
}
end

function activate()
   local item = vlc.input.item()
   local uri = item:uri()
   uri = string.gsub(uri, '^file:///', '')
   uri = string.gsub(uri, '/', '\\')

--   strCmd = 'echo '..uri..' |clip'
--   os.execute(strCmd)
   create_dialog()
end
function deactivate()

end
function close()
	vlc.deactivate()
end


function create_dialog()
	w = vlc.dialog("Time2Clip")
	w1 = w:add_label("<b>Timestamp:</b>",1,1,1,1)
	w2 = w:add_text_input("0",2,1,1,1)
	w3 = w:add_button("jumpto", click_SEEK,1,2,1,1)
	w4 = w:add_button("Save_to_Clip", click_SAVE,2,2,1,1)
end
number = 0
tpool={}
function click_SAVE()
	local input = vlc.object.input()
	if input then
		local curtime=vlc.var.get(input, "time")
		local curtime=math.floor(curtime/1000)
		local curtime=curtime/1000
		local hours = math.floor(curtime/3600)
		local minutes = math.floor((curtime%3600)/60)
		local seconds = math.floor(curtime%60)

		if number % 2 == 0
          then
              timeString = string.format("%02d:%02d:%02d-",hours,minutes,seconds)
          else
              timeString = string.format("%02d:%02d:%02d,",hours,minutes,seconds)
        end

        table.insert(tpool, timeString)
        finalString = table.concat( tpool )
        finalString = finalString:sub(1, -2)
        w2:set_text(finalString)
        save_to_clipboard(finalString)
        number = number + 1
	end
end

function click_SEEK()
	local time_togo = w2:get_text()
	local input = vlc.object.input()
	if input then
		vlc.var.set(input, "time", time_togo)	--jump to specified time
	end
end

function save_to_clipboard(var)
	strCmd = 'echo | set /p dummyName='..var..'|clip'
--    strCmd = 'echo '..var..'|clip'
	os.execute(strCmd)
end
Eliseat is offline   Reply With Quote
Old 01-10-2019, 02:38 AM   #20
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 826
Default

Here is, what it does:


The output can now easily put into to mkvToolnix' video segmentation process without any adjustments.

Next thing will be to add a send button to automatically send the timestamps to mkvToolnix gui and start the cutting process. But there is a problem I see at the horizon: How do I know where mkvToolnix is installed at the user system as every user puts it somewhere else? (Maybe VLC can point there?) We will see!

Many thanks for the help. I will be back soon with new questions.
Eliseat is offline   Reply With Quote
Old 01-10-2019, 06:55 AM   #21
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 826
Default

HELP! New problem, new question. How can I get a ^ in a string without breaking it? mkvToolnix needs this to determine the path:
Code:
^"D:\path to movie\movie.mkv^"
But everything stops working if this ^ sign enters the string. Or to be more clear, it only returns the ^ sign and nothing more. How can I define it in an other way? Many thanks in advance.
Eliseat is offline   Reply With Quote
Old 01-10-2019, 07:48 AM   #22
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 7,527
Default

Quote:
Originally Posted by Eliseat View Post
HELP! New problem, new question. How can I get a ^ in a string without breaking it?
At least this works fine, but I don't know if there's some issue when you try to put the result into the clipboard or something...

Code:
local filename="foo.mkv"
local str = "^\""..filename.."\""
print(str)
outputs
Code:
^"foo.mkv"
__________________
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
http://www.sws-extension.org/
https://github.com/Jeff0S/sws
--
Xenakios blog (about HourGlass, Paul(X)Stretch and λ) :
http://xenakios.wordpress.com/
Xenakios is offline   Reply With Quote
Old 01-10-2019, 09:08 AM   #23
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 826
Default

Quote:
Originally Posted by Xenakios View Post
At least this works fine, but I don't know if there's some issue when you try to put the result into the clipboard or something...

Code:
local filename="foo.mkv"
local str = "^\""..filename.."\""
print(str)
outputs
Code:
^"foo.mkv"
I managed it finally. The ^ sign wasn't necessary at the end though mkvToolnix put it inside the example code. Anyway. The script runs now perfectly and sends the timeStamps to mkvToolnix which splits the videos as expected. I'm very happy and proud. And I needed nearly a whole work day to get the right result. But because I need to cut videos sometimes at work it was kind of a workflow optimisation for myself.

I learned a lot. And this is quasi the first script I ever made/optimized. It feels really great to see something like that running but I also see how much improvements it could have.

The plan was to some kind use this VLC project to start a similar project for Reaper. But I recognized a lot of problems which will make this nearly impossible out of Reaper.
  • First thing: mkvToolnix only splits/cuts at keyframes. This means its not possible to cut exactly at a desired frame which makes it impossible to trim a video the same in mkvToolnix as it can get trimmed in Reaper.
  • Next thing: Reaper is not able to reload/refresh items without reloading the whole project. So trimming, sending to mkvToolnix, splitting and refreshing with the new created files would be complicated.
  • And finally: I have no idea where to start in Reaper. Best thing would be to allow Reaper to use VLC extensions as this would already exist.

Many thanks for the help. The final VLC extension will be posted soon.
Eliseat is offline   Reply With Quote
Old 01-11-2019, 01:34 PM   #24
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 826
Default

Okay, I got stuck with a pretty stupid problem. I can't use system paths with spacing in between folder or file names. Has anybody an idea why this happens?

I split videos like hell and everything worked fine til I suddenly realized that one video just didn't work. If I pasted the code manually into mkvToolnix everything was fine. But not by sending it from VLC. After I recognized a second video it was obvious that the filename made the trouble. There was a space sign like "my video.mkv"

This code is used to get the uri and to bring it into a usable format. But why does it not read the space signs correctly?
Code:
   uri = item:uri()
   uri = string.gsub(uri, '^file:///', '')
   uri = string.gsub(uri, '/', '\\')
Hope someone can help as this is really frustrating.

EDIT: Could it be cmd which can't handle spaces? Because if I copy the path to the clipboard I get the correct path. But if I try to click on a created link to open an OS path it does nothing as long as the path contains a space. Is this common? Is there a work around?

EDIT2: This seems to be a problem of VLC. And I have no idea why. F**k!


(⊙︿⊙✿)
__________________
☆.。.:*・°☆.。.:*・°☆.。.:*・°☆.。.:*・°☆ REAPER ☆.。.:*・°☆.。.:*・°☆.。.:*・°☆.。.:*・°☆

Last edited by Eliseat; 01-11-2019 at 02:21 PM.
Eliseat is offline   Reply With Quote
Old 01-11-2019, 02:31 PM   #25
karbomusic
Human being with feelings
 
karbomusic's Avatar
 
Join Date: May 2009
Posts: 23,153
Default

Quote:
Originally Posted by Eliseat View Post
EDIT: Could it be cmd which can't handle spaces?
Yes because spaces are reserved for interpreting switches/arguments/paramsb being passed to the executable, but it is normally solved by making sure double quotes are surrounding the path:

C:\somefolder\some file.mp3 [no worky]

'C:\somefolder\some file.mp3' [no worky]

"C:\somefolder\some file.mp3" [should work fine]

Welcome to special character escaping hell. Should be solvable though. Personally, I very often just omit spaces anytime I'm working in code/scripts where this becomes fiddly and error prone - meaning if I have control over the filename at creation time, I'm likely to omit spaces and use camel case instead such as MyCoolFile.mp3.

Last edited by karbomusic; 01-11-2019 at 02:36 PM.
karbomusic is online now   Reply With Quote
Old 01-11-2019, 02:56 PM   #26
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 826
Default

Many thanks for your reply, karbomusic, but it does not help. And I'm afraid its VLC as it even can't handle it by itself. I made a dialog with text and a system link in it. The link does not open if a space character is in the path. But I can copy it with the context menu to realize that the path is absolutely correct.

I changed the sending parameters for mkvMerge to have every path in "". It does not help. I checked by copying it into the clipboard which also shows that the path is correct. It places %20 where the space should be. And I know from my webdesign days that this is the placeholder for spaces in URLs.

So there are two last chances: Whether its windows with some stupid safety handling or its VLC with some stupid "An URL is not allowed to have spaces!".
__________________
☆.。.:*・°☆.。.:*・°☆.。.:*・°☆.。.:*・°☆ REAPER ☆.。.:*・°☆.。.:*・°☆.。.:*・°☆.。.:*・°☆
Eliseat is offline   Reply With Quote
Old 01-11-2019, 03:10 PM   #27
karbomusic
Human being with feelings
 
karbomusic's Avatar
 
Join Date: May 2009
Posts: 23,153
Default

It may still be solvable however... that's the exact reason I avoid spaces in paths in these types of scripts when I see this issue (even outside of DAWs) - it really shouldn't be an issue in 2019 but it rears it's head from time to time, especially when passing filenames around programmatically. See if there is anything of value in the link below if you think it is VLC (sorry I didn't read the entire thread above if I missed the obvious)…

https://forum.videolan.org/viewtopic.php?t=86495
karbomusic is online now   Reply With Quote
Old 01-11-2019, 05:18 PM   #28
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 826
Default

It is still is solvable - but at what cost?

Code:
uri = string.gsub(uri, '%%20', '\032')
This was the solution. I already had the right direction by removing the %20 placeholder with a clean space character. But I didn't know I had to escape this with another % symbol. Holy sh**!

But you were a great help, karbomusic, as you pointed me to the double %% escape thing.

Now I'm at the same point as yesterday. The script runs perfect for me (this time with space characters in file and folder names.) But to share this with other users there need a lot to be done. Because now it gets really dirty as everybody places the mkvMerge.exe in a different directory.

Anyway. I'm all alone this weekend. The kids are gone. And I will make some music with videos and of course work on this script. Many thanks for now.

(❀◦‿◦)
__________________
☆.。.:*・°☆.。.:*・°☆.。.:*・°☆.。.:*・°☆ REAPER ☆.。.:*・°☆.。.:*・°☆.。.:*・°☆.。.:*・°☆
Eliseat is offline   Reply With Quote
Old 01-16-2019, 10:46 AM   #29
Eliseat
Human being with feelings
 
Eliseat's Avatar
 
Join Date: Mar 2018
Location: Cologne
Posts: 826
Default

Hi again,

this works now flawlessly. But I want to make it more beautiful and helpful. So I ran into a new issue, this time with tables.

Short description: The extension allows to create start and end timestamps for splitting a longer video into short clips without reencoding. Those A/B stamps can be created on the fly while watching or skipping thru a video. Everything works nice but it would be better to have a list of every clip (A/B range) created.

For this I planned to output a html list which should add a new <li> or line with every new clip created. Here it was it looks like:


I martyred my brain about how to achieve this. And the only thing I could imagine (after watching videos and reading lua manuals) is using a table to put a new line with every cycle as a value into it. In theory this looks awesome. But how could I get those values back out of the table without using print (k,v)?
Code:
if a % 2 ~= 0    --this is inside a function which get started if some one creates a timestamp
            then   -- show start point and auto split button  only if a start- AND end-stamp is there
    	        
                w4 = w:add_button("Create start point (".. a ..")", click_SAVE,2,2,1,1)
    	        w5 = w:add_button("> Auto Split ", send_Split,3,2,1,1)
    	        a = a + 1
                b = 1
                clip_line = "<li>Clip "..a/2-b.."</li>"  -- table clips is created outside of function
                table.insert(clips, clip_line)         -- I want to add a new line with every new cycle
                clip_list = table.concat( clips )  -- to put them in a clip_list variable

                w6 = w:add_html("<ol><li>Clip "..clips.." - 00:01:22 - 00:04:15 -> 02:47 min</li></ol>",4,1,1,4)

    	        w:update()
EDIT: Okay, I've found the error while posting it here. I put everything into the variable clip_list but used the whole table as the placeholder. How stupid ...
__________________
☆.。.:*・°☆.。.:*・°☆.。.:*・°☆.。.:*・°☆ REAPER ☆.。.:*・°☆.。.:*・°☆.。.:*・°☆.。.:*・°☆
Eliseat is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 11:12 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.