Page 1 of 1

Need help for a script I want to share (Timestamps to mkvToolnix)

Posted: 11 Jan 2019 17:55
by ElisaCol
Hi,

I have to say that I'm a complete noob in programming but I wanted to make this so badly that I didn't give up until it ran.

So what does it do? What is its all about?

I wanted to create timestamps (A/B) while watching a long video to then copy them to the clipboard or send them directly to mkvMerge to let it split the videos into clips. I had found a script called time2clip which did not work on my system and VLC version. But I liked the concept. So I tried my best to make it work the way I wanted in the first place. I managed to fix the time format, the copying to the clipboard and even the sending to mkvMerge. Everything works fine for me. But I wanted to share this extension what brought up new problems and question of how to handle different paths etc.
  1. I want to make it really simple for users to get the setup right. Hence I created a short description which I planned to display as long as the path to mkvMerge isn't set in mkvMerge_path. Would it be possible to point the user via os dialog to the mkvMerge.exe once and placing the path as string into mkvMerge_path?
  2. Because I have no idea about that I tried to point the user via a link in the description to my lua file which of course resides in the VLC/lua/extensions folder. How the heck can I get the VLC install directory to put it in an variable? I tried config.datadir() but it breaks the script completely.
  3. So I had no clue about this and tried to put at least the default install dir of VLC in my description but this does only work if I use my German folder "Programme" and not with the default placeholder "program files". Why? And how to get around with that?
  4. The script runs fine for me - however - I noticed that it kind of freezes if the movie is to big and the splitting duration gets to long. Could someone check if everything makes sense? Is there maybe a loop or something?
Please try it out and take a look over it.
Many thanks in advance :)

Re: Need help for a script I want to share (Timestamps to mkvToolnix)

Posted: 11 Jan 2019 17:58
by ElisaCol
I wanted to place the code between the bbcode tags but it was way to long. Why is it only allowed to post 2000 letters? And how can I attach my lua file so everybody can take a look at it?

Re: Need help for a script I want to share (Timestamps to mkvToolnix)

Posted: 11 Jan 2019 20:02
by ElisaCol
Okay, I guess I found out what makes it impossible to open the path to VLC. Its the space between program and files of "program files". Does it need to be formatted? Why? How? ;)

I will see if I find a work around. By the way. This also makes trouble when I try to split a video with a spacing character in its file name. mkvToolnix doesn't start then. ¯\_(ツ)_/¯

Edit: can anybody tell me if spaces in system/file paths aren't allowed for some reason? Though I'm not sure if its VLC sending the wrong uri to mkvToolnix or if its mkvMerge who can't read the path. Any help is very appreciated. :)

Edit 2: So the path gets written correctly into the dialog. I put it in a link add_html() and it works (opens the OS path) as long as no space character is in the path. But if I copy the path (context menu) it gets copied correctly into the clipboard. So whats the problem? Is it VLC that can't handle those paths? And why? :(

Re: Need help for a script I want to share (Timestamps to mkvToolnix)

Posted: 12 Jan 2019 01:25
by ElisaCol
Okay, I solved at least the sending to mkvMerge.

Code: Select all

uri = string.gsub(uri, '%%20', '\032')
... was the solution, but I didn't know I had to escape the %20 with another %.

Anyway. Not to much movement here in the forums. So this will be kind of a one girl show as I'm asking in other forums about VLC lua. :roll:

Re: Need help for a script I want to share (Timestamps to mkvToolnix)

Posted: 12 Jan 2019 11:55
by ElisaCol
Okay, there is only one thing left to do. I need a dialog to point the user to the mkvMerge directory.

I thought about two options:

1. Using the VLC file dialog to point the user to the mkvMerge.exe. This seems kind of ridicules as its not capable to open an .exe. But maybe I could get only the path and put it in a dialog text field. <-- found out its not possible.

2. I have found this thread about creating kind of a list browser. This would be really cool, but I'm not sure how to start there. How could I get a directory listing into a dialog list?

Hope someone reads this and at least could give a little sign that this forum even exists.

Many thanks

Re: Need help for a script I want to share (Timestamps to mkvToolnix)

Posted: 12 Jan 2019 15:42
by mederi
You are right about the current limitation: "The maximum number of allowed characters is 2000." You better write brief&clear posts and you increase a chance to get an answer. Patience is your friend :) You can split the code into several posts or use an external solution like https://pastebin.com/ Final scripts go to https://addons.videolan.org/ You should check some scripts for possible solutions (vlsub.lua). You have already found the answer how to create a file browser dialog. So far nobody tried to make one. You just use available VLC functions described in "README.txt" document and combine it with Lua stuff. Probably a simpler solution would be to drag&drop a file into VLC playlist and then you can simply read the playlist to find the mrl of the file and parse it. Then you need to store the relevant information somewhere. You can read/write files (VLC 3.0.2+) or simply use VLC config system (time_ext.lua). Search this forum first, as many questions could have already been answered.

Re: Need help for a script I want to share (Timestamps to mkvToolnix)

Posted: 12 Jan 2019 17:01
by ElisaCol
Many thanks for your answer.

Drag and drop into VLC would be okay but not for an .exe file I guess. My plan is to make kind of a first run dialog of the extension where people have to point to the mkvMerge.exe as this is it all about. I also could use a text input to let people copy the text (path) in but that seems to be a bit spartan.

Anyway. I will think about it. This is the first time I ever made a script so most things you point at don't make much sense to me. I will take a look at the extension to see if someone maybe has something similar to my needs.

Many thanks for your reply.
Eli

Re: Need help for a script I want to share (Timestamps to mkvToolnix)

Posted: 12 Jan 2019 17:36
by ElisaCol
Here you can find the code on pastebin: https://pastebin.com/egzY2625

Everything stands in the description. And I will add a gif animation shortly to show you what it does. :)

Re: Need help for a script I want to share (Timestamps to mkvToolnix)

Posted: 12 Jan 2019 17:56
by ElisaCol
Here you can see it in action:
Image

You watch a movie or your own video records and enter timestamps where you want the video to get split. mkvMerge automatically does the job without re-encoding. But it only can cut on keyframes what makes it not too precise. Anyway. It works great and helps to create clips of longer videos.

:)

Re: Need help for a script I want to share (Timestamps to mkvToolnix)

Posted: 15 Jan 2019 11:34
by ElisaCol
Hi,

I got stuck while implementing an external file read function. A directory listing is way to much for me as a newbie so I just planned to let the user input the path in a text field to save it in an external file (next to the script). This should be kind of a first run routine that checks if the file or the path to mkvMerge exists or not. The problem is, I don't get it to run. I can't even read from files next to the script file.

Code: Select all

extfile = io.open("mkvMergePath.txt", "r") mkvMerge_path = extfile:read ("*all") extfile:close()
This should give me a string of the content of mkvMergePath.txt. But it doesn't get anything. (attempt value of global ... is Nil) Is it even possible to read file content out with VLC? Any help would be great.

Many thanks :)

Re: Need help for a script I want to share (Timestamps to mkvToolnix)

Posted: 15 Jan 2019 15:01
by mederi
"mkvMergePath.txt" is not the path to a file next to the script file. It is the "vlc.exe" dir. You better use "vlc.config.userdatadir()" for your config file. Then VLC 3.0.2+ has implemented its own io functionality (vlc.io.open...) solving the issue with non-ASCII characters in a path.

Code: Select all

extfile = io.open(vlc.config.userdatadir().."\\mkvMergePath.txt", "r") if extfile then mkvMerge_path = extfile:read("*all") extfile:close() end

Re: Need help for a script I want to share (Timestamps to mkvToolnix)

Posted: 15 Jan 2019 23:43
by ElisaCol
Many, many thanks mederi! :)
Though I can't believe you are the lonesome knight who fights alone in this forum. Where are the millions and millions of people who use VLC? It seems you are the only one who helps newbies like me. That's a bit ridiculous for such a big player like VideoLan. But its also very honorable how you keep this running. Many thanks for your efforts.

By the way: you helped me out again. But I have to correct you. The (mkvMergePath.txt) points NOT to the VLC directory but to the Windows desktop! No joke! I was wondering why the heck no changes were made if I saved various txt versions to check which belongs to which directory. And I forgot that the base txt file was saved at the desktop. That was another hour of my life wasted for nothing. :D

vlc.config.userdatadir() points to the VLC directory what made it simple to just expand the path to the lua extensions folder. The routine works for now. I'm very happy. But one last thing needs to be done and I hope you can help me only once again. /(✿´‿`)

See next post!

Re: Need help for a script I want to share (Timestamps to mkvToolnix)

Posted: 15 Jan 2019 23:57
by ElisaCol
The routine:
-function activate() looks if mkvMergePath.txt is there and has text.
-if yes, it starts create_dialog (main program)
-if not, first_dialog starts, opens mkvMergePath.txt and wants a text input
-after input, a button starts a save_path function which stores the data into .txt (works great)

I want the dialog to change to the main program but it gives me an error (only one dialog is allowed). Here the relevant code:

Code: Select all

function activate() ... extfile = io.open(vlc.config.datadir().."\\lua\\extensions\\mkvMergePath.txt", "r") if extfile then mkvMerge_path = extfile:read("*all") extfile:close() if mkvMerge_path == "" then first_dialog() else create_dialog() end end end function deactivate() end function meta_changed() end function close() vlc.deactivate() end function first_dialog() w = vlc.dialog("First run routine") w1 = w:add_label("<b>Insert path to mkvMerge:</b>",1,1,5,1) w2 = w:add_label("Example: c:/program files/mkvtoolnix/mkvmerge.exe",1,2,5,1) uinput = w:add_text_input("",1,3,19,1) w3 = w:add_button("Save", save_path,15,4,5,1) create_dialog() end function save_path() mpath = uinput:get_text() input = vlc.object.input() if input then extfile = io.output(vlc.config.datadir().."\\lua\\extensions\\mkvMergePath.txt", "w") io.write(mpath) extfile:close() end end function create_dialog() w = vlc.dialog("Split video with mkvToolnix") w1 = w:add_label("<b>Timestamps:</b>",1,1,1,1) w2 = w:add_text_input("0",2,1,1,1) w3 = w:add_button("> Clipboard", send_Clip,3,1,1,1) w4 = w:add_button("Create", click_SAVE,2,2,1,1) w5 = w:add_button("> Auto Split ", send_Split,3,2,1,1) w6 = w:add_list ( 1,3,4,1) end

Re: Need help for a script I want to share (Timestamps to mkvToolnix)

Posted: 16 Jan 2019 00:02
by ElisaCol
Do you have an idea of how to manage that after the first run it saves and changes to the main program? Many thanks! :)

Re: Need help for a script I want to share (Timestamps to mkvToolnix)

Posted: 16 Jan 2019 11:31
by ElisaCol
I got it. I had to delete the w variable and to update the dialog. :)

Re: Need help for a script I want to share (Timestamps to mkvToolnix)

Posted: 16 Jan 2019 14:30
by mederi
You could have only 1 simple dialog containing also a row with an mkvMerge text input field with a saving button. You could read the mkvMerge_path into this field during activation of the extension if the "mkvMergePath.txt" file exists and then always read this field on Auto Split.

Code: Select all

mkvMerge: [ ] [ Save ] Timestamps: [ ] [ > Clipboard ] [ Create ] [ > Auto Split]
If you want 2 dialogs then you should properly check conditions in activate(): if mkvMergePath.txt exists and mkvMerge_path is valid then create_dialog() else first_dialog().

Code: Select all

function activate() ... extfile = io.open(vlc.config.datadir().."\\lua\\extensions\\mkvMergePath.txt", "r") if extfile then mkvMerge_path = extfile:read("*all") extfile:close() create_dialog() else first_dialog() end end function first_dialog() if w then w:delete() end w = vlc.dialog("First run routine") ... w:add_button("Cancel", cancel,,,,) end function save_path() ... create_dialog() end function cancel() create_dialog() end function create_dialog() if w then w:delete() end w = vlc.dialog("Split video with mkvToolnix") ... w:add_button("mkvMerge ", first_dialog,,,,) end

Re: Need help for a script I want to share (Timestamps to mkvToolnix)

Posted: 17 Jan 2019 11:08
by ElisaCol
I finished it!

https://pastebin.com/BWDTvUzr

Feel free to test and use it. Maybe someone wants to port it to apple or linux.

Greetings
Eli

Re: Need help for a script I want to share (Timestamps to mkvToolnix)

Posted: 19 Jan 2019 11:36
by ElisaCol
https://pastebin.com/gkAFMiad

Here is a newer version with better path handling (spaces work now) and an new "Delete all" button to delete the timestamps if changing the input video without closing the dialog.

Greetings
Eli

Here it is in action:

First run routine demands the path to mkvMerge.exe which gets saved into mkvMergePath.txt next to the extension script.

Image


Clicking the Create start/end point button adds new timestamps to the list. Those time ranges will be displayed as clips in the clip list.

Image


Sending the timestamps to mkvMerge with one click. It saves all clips next to the source video.

Image

I have no idea of how compatible this lua script is. I only tested it on win 7 64 bit and VLC v 3.04 which works flawlessly. But I'm pretty sure there are still many traps that I didn't think about. If someone wants to test it and runs into trouble I will try to fix that. Though I'm not experienced. :)

So please try it out. Put the lua file into the VLC directory/lua/extensions directory and start the extension in the menu -> view Split Video with mkvMerge

Re: Need help for a script I want to share (Timestamps to mkvToolnix)

Posted: 19 Jan 2019 19:16
by mederi
You could try to split videos in VLC. Converting/Streaming wizards (Media > Convert/Save.../Stream...) contains Start-Stop Time options (under "[v] Show more options" in Open Media dialog). Then you could use VLC with CLI options in your script (check the "Audio CD ripping helper" extension).