Guest User

slicing lua windows fix

a guest
Dec 21st, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.83 KB | None | 0 0
  1. local msg = require "mp.msg"
  2. local utils = require "mp.utils"
  3. local options = require "mp.options"
  4.  
  5. local cut_pos = nil
  6. local copy_audio = false
  7.  
  8. local o = {
  9.     command_template = [[
  10.        
  11.         ffmpeg -y -ss $shift -i "$in"  -t $duration
  12.          $sub $video $audio $pixfmt $options
  13.          $quality "$dir$out.webm"
  14.     ]],
  15. } -- ffmpeg base argument
  16.  
  17. options.read_options(o)
  18.  
  19. function timestamp(duration)
  20.     local hours = duration / 3600
  21.     local minutes = duration % 3600 / 60
  22.     local seconds = duration % 60
  23.     return string.format("%02d:%02d:%02.03f", hours, minutes, seconds)
  24. end
  25.  
  26. function osd(str)
  27.     return mp.osd_message(str, 3)
  28. end
  29.  
  30.  
  31. function escape(str)
  32.     return str:gsub("'", "'\\''")
  33. end
  34.  
  35. function trim(str)
  36.     return str:gsub("^%s+", ""):gsub("%s+$", "")
  37. end
  38.  
  39.  
  40. function cut(shift, endpos)
  41.     local cmd = trim(o.command_template:gsub("%s+", " "))
  42.     local inpath = escape(utils.join_path(
  43.         utils.getcwd(),
  44.         mp.get_property("stream-path")))
  45.     local outpath = os.time() --- file names will be named according to unix timestamp
  46.  
  47.  
  48.     cmd = cmd:gsub("$shift", shift)
  49.     cmd = cmd:gsub("$duration", endpos - shift)
  50.     cmd = cmd:gsub("$audio", copy_audio and "-c:a libvorbis " or "-an") --audio codec
  51.     cmd = cmd:gsub("$video", "-c:v libvpx") -- vpx8 for webm 4ch compatible
  52.     cmd = cmd:gsub("$sub", "-sn") --disabled sub because reasons
  53.  
  54.     cmd = cmd:gsub("$pixfmt", "-pix_fmt yuv420p") --color
  55.     cmd = cmd:gsub("$options", "-threads 8 -slices 4") --threads option
  56.     cmd = cmd:gsub("$quality", "-qmin 0 -crf 10 -b:v 1500K -qmax 30 -qcomp 0") --quality options
  57.     cmd = cmd:gsub("$dir", "A:\\") --- output directory change here
  58.     cmd = cmd:gsub("$out", outpath)
  59.     cmd = cmd:gsub("$in", inpath, 1)
  60.  
  61.  
  62.    
  63.     msg.info(cmd)
  64.     os.execute(cmd)
  65. end
  66.  
  67. function toggle_mark()
  68.     local pos = mp.get_property_number("time-pos")
  69.     if cut_pos then
  70.         local shift, endpos = cut_pos, pos
  71.         if shift > endpos then
  72.             shift, endpos = endpos, shift
  73.         end
  74.         if shift == endpos then
  75.             osd("Cut fragment is empty")
  76.         else
  77.             cut_pos = nil
  78.             osd(string.format("Cut fragment: %s - %s",
  79.                 timestamp(shift),
  80.                 timestamp(endpos)))
  81.             cut(shift, endpos)
  82.         end
  83.     else
  84.         cut_pos = pos
  85.         osd(string.format("Marked %s as start position", timestamp(pos)))
  86.     end
  87. end
  88.  
  89. function toggle_audio()
  90.     copy_audio = not copy_audio
  91.     osd("Audio capturing is " .. (copy_audio and "enabled" or "disabled"))
  92. end
  93.  
  94. function toggle_subtitle()
  95.     copy_subtitle = not copy_subtitle
  96.     osd("Subtitle is " .. (copy_subtitle and "enabled" or "disabled"))
  97. end
  98.  
  99.  
  100. mp.add_key_binding("c", "slicing_mark", toggle_mark)
  101. mp.add_key_binding("a", "slicing_audio", toggle_audio)
Add Comment
Please, Sign In to add comment