Advertisement
Guest User

capture.lua

a guest
Apr 26th, 2014
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | None | 0 0
  1. -- save as ~/.mpv/lua/capture.lua
  2. -- usage: press «a» at start and at end of fragment
  3. -- will print commands for ffmpeg and mpv
  4.  
  5. capture = {}
  6. function capture.handler()
  7.     local gp = mp.get_property
  8.     local gpn = mp.get_property_number
  9.     local sp = mp.set_property
  10.     local c = capture
  11.     local filesize = 6144
  12.     local maxfps = 35
  13.     if c.start == nil then
  14.         c.start = gp("time-pos")
  15.     elseif c.finish == nil then
  16.         c.finish = gp("time-pos")
  17.         local ffopts = ""
  18.         local length = c.finish - c.start
  19.         local br = filesize * 8 / length - 100
  20.         if gpn("fps") > maxfps then
  21.             local fps = gpn("fps") / 2
  22.         end
  23.         local h = gp("height")
  24.         local w = gp("width")
  25.         if w * h / br > 1000 then
  26.             ffopts = ffopts .. string.format("-vf scale=%d:-1 ",
  27.                 0.0017)
  28.         end
  29.  
  30.         print(string.format("ffmpeg -ss %f -i '%s' -t %f -b:v %dk %s -pass 1",
  31.             c.start, gp("path"), length, br,
  32.             fps and "-r " .. fps or ""))
  33.         print(string.format("mpv --start %f '%s' --length %f --ovcopts b=%dk",
  34.             c.start, gp("path"), length, br))
  35.         c.start = nil
  36.         c.finish = nil
  37.     end
  38. end
  39. mp.add_key_binding("a", "capture", capture.handler)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement