Guest User

Untitled

a guest
Jan 12th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.14 KB | None | 0 0
  1. -- SplitWithMkvMerge.lua -- VLC extension --
  2. --[[
  3. INSTALLATION:
  4. Put the file in the VLC subdir /lua/extensions, by default:
  5. * Windows (all users): %ProgramFiles%\VideoLAN\VLC\lua\extensions\
  6. * Windows (current user): %APPDATA%\VLC\lua\extensions\
  7. (create directories if they don't exist)
  8. Restart the VLC.
  9. Then you simply use the extension by going to the "View" menu and selecting it.
  10. USAGE:
  11. Clicking the create button while playing a movie allows you to write a "start timestamp", clicking a second time adds an "end timestamp". You can add more of such time ranges but you have to make sure the last stamp is an "end timestamp".
  12. If you have the needed time ranges that you want to have split out of the movie simply click on the "> split tool" button to send it to mkvMerge.
  13. If everything is set up correctly it shoul create the video clips automatically.
  14. You could use the "> Clipboard" button to copy the timestamps only into the clipboard to insert then manually into mkvToolnix gui (output/split with timestamps) for more options.
  15. Note:
  16.     This extension has been tested for VLC 3.0.4 on Win7 x64 sp1.
  17.     It needs mkvMerge.exe which is part of the mkvToolnix set. Download: https://mkvtoolnix.download/downloads.html#windows
  18.     Once installed, paste your path to mkvMerge.exe between the "" of mkvMerge_path in this extension.
  19.  
  20.     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).
  21.     If it doesn't exist, you can download it from here:
  22.     http://www.labnol.org/software/tutorials/copy-dos-command-line-output-clipboard-clip-exe/2506/
  23.  
  24.  
  25. --]]
  26.  
  27.  
  28. function descriptor()
  29.     return {
  30.         title = "Timestamps to mkvToolnix";
  31.         version = "1.0 not released";
  32.         author = "elisacol";
  33.         url = '';
  34.         shortdesc = "Timestamps to mkvToolnix";
  35.         description = "<div style=\"background-color:lightgreen;\"><b>Send timestamps to mkvToolnix for cutting/splitting videos. (Based on Time2Clip extension.)</b></div>";
  36. }
  37. end
  38.  
  39. function activate()
  40.    local item = vlc.input.item()
  41.    uri = item:uri()
  42.    uri = string.gsub(uri, '^file:///', '')
  43.    uri = string.gsub(uri, '/', '\\')
  44.    uri = string.gsub(uri, '%%20', '\032')
  45.    mkvMerge_path = "D:/PortablePrograms/mkvtoolnix/mkvmerge.exe"
  46. --   vlc_path = "C:\\Program Files\\VideoLAN\\VLC\\lua\\extensions\\"
  47. --   vlc_path = string.gsub (vlc_path, '%%20', '\032')
  48.    create_dialog()
  49. end
  50. function deactivate()
  51.  
  52. end
  53. function close()
  54.     vlc.deactivate()
  55. end
  56.  
  57.  
  58. function create_dialog()
  59.     w = vlc.dialog("Stamps2Toolnix")
  60.     w1 = w:add_label("<b>Timestamps:</b>",1,1,1,1)
  61.     w2 = w:add_text_input("0",2,1,1,1)
  62.     w3 = w:add_button("> Clipboard", send_Clip,3,1,1,1)
  63.     w4 = w:add_button("Create", click_SAVE,2,2,1,1)
  64.     w5 = w:add_button("> Auto Split ", send_Split,3,2,1,1)
  65.  
  66. --[[ For testing only
  67.     w6 = w:add_html("<ul><li>Make sure the path to mkvMerge is set in the lua script! <a href=\""..vlc_path.."\">Open the script</a>, search for <b>mkvMerge_path =</b> and insert the path between the <b>\" \"</b>. Save the script! Restart VLC!</li><li>While watching the video click once on <b>Create</b> to create a start timestamp. Click a second time to create an end stamp. This time range will be used by mkvMerge to cut out your clip.</li><li>You can click as often as you want to mark time ranges but you have to make sure your last click is an end timestamp.</li><li>Click on the <b>Clipboard</b> button to copy all timestamps to the clipboard. You can paste them manually into mkvToolnix gui's output splitting dialog if you want to make specific adjustments.</li><li>If you have set the path to mkvMerge correctly you can also send it directly by clicking the <b>Auto Split</b> button. MkvMerge will try to split your videos depending on the timestamps with the most useful settings.</li></ul>",1,3,3,3)
  68.     w7 = w:add_label( vlc_path , send_Clip, 1,4,4,1)
  69. --]]
  70. end
  71. number = 0
  72. tpool={}
  73.  
  74.  
  75. function click_SAVE()
  76.     local input = vlc.object.input()
  77.     if input then
  78.         local curtime=vlc.var.get(input, "time")
  79.         local curtime=math.floor(curtime/1000)
  80.         local curtime=curtime/1000
  81.         local hours = math.floor(curtime/3600)
  82.         local minutes = math.floor((curtime%3600)/60)
  83.         local seconds = math.floor(curtime%60)
  84.  
  85.         if number % 2 == 0
  86.           then
  87.               timeString = string.format("%02d:%02d:%02d-",hours,minutes,seconds)
  88.           else
  89.               timeString = string.format("%02d:%02d:%02d,",hours,minutes,seconds)
  90.         end
  91.  
  92.         table.insert(tpool, timeString)
  93.         finalString = table.concat( tpool )
  94.         finalString = finalString:sub(1, -2)
  95.         w2:set_text(finalString)
  96.  
  97.         number = number + 1
  98.  
  99.     end
  100. end
  101.  
  102. function send_Clip()
  103.     timeStamps = w2:get_text()
  104.     input = vlc.object.input()
  105.     if input then
  106.         strCmd = 'echo | set /p dummyName='..timeStamps..'|clip'
  107.         os.execute(strCmd)
  108.     end
  109.  
  110. end
  111. function send_Split()
  112.     timeStamps = w2:get_text()
  113.     input = vlc.object.input()
  114.     if input then
  115.         strCmd = mkvMerge_path..' --output "'..uri..'.mkv" "'..uri..'" --split parts:'..timeStamps
  116.         os.execute(strCmd)
  117.     end
  118.  
  119. end
Add Comment
Please, Sign In to add comment