Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local msg = require "mp.msg"
- local utils = require "mp.utils"
- local options = require "mp.options"
- local cut_pos = nil
- local copy_audio = false
- local o = {
- command_template = [[
- ffmpeg -y -ss $shift -i "$in" -t $duration
- $sub $video $audio $pixfmt $options
- $quality "$dir$out.webm"
- ]],
- } -- ffmpeg base argument
- options.read_options(o)
- function timestamp(duration)
- local hours = duration / 3600
- local minutes = duration % 3600 / 60
- local seconds = duration % 60
- return string.format("%02d:%02d:%02.03f", hours, minutes, seconds)
- end
- function osd(str)
- return mp.osd_message(str, 3)
- end
- function escape(str)
- return str:gsub("'", "'\\''")
- end
- function trim(str)
- return str:gsub("^%s+", ""):gsub("%s+$", "")
- end
- function cut(shift, endpos)
- local cmd = trim(o.command_template:gsub("%s+", " "))
- local inpath = escape(utils.join_path(
- utils.getcwd(),
- mp.get_property("stream-path")))
- local outpath = os.time() --- file names will be named according to unix timestamp
- cmd = cmd:gsub("$shift", shift)
- cmd = cmd:gsub("$duration", endpos - shift)
- cmd = cmd:gsub("$audio", copy_audio and "-c:a libvorbis " or "-an") --audio codec
- cmd = cmd:gsub("$video", "-c:v libvpx") -- vpx8 for webm 4ch compatible
- cmd = cmd:gsub("$sub", "-sn") --disabled sub because reasons
- cmd = cmd:gsub("$pixfmt", "-pix_fmt yuv420p") --color
- cmd = cmd:gsub("$options", "-threads 8 -slices 4") --threads option
- cmd = cmd:gsub("$quality", "-qmin 0 -crf 10 -b:v 1500K -qmax 30 -qcomp 0") --quality options
- cmd = cmd:gsub("$dir", "A:\\") --- output directory change here
- cmd = cmd:gsub("$out", outpath)
- cmd = cmd:gsub("$in", inpath, 1)
- msg.info(cmd)
- os.execute(cmd)
- end
- function toggle_mark()
- local pos = mp.get_property_number("time-pos")
- if cut_pos then
- local shift, endpos = cut_pos, pos
- if shift > endpos then
- shift, endpos = endpos, shift
- end
- if shift == endpos then
- osd("Cut fragment is empty")
- else
- cut_pos = nil
- osd(string.format("Cut fragment: %s - %s",
- timestamp(shift),
- timestamp(endpos)))
- cut(shift, endpos)
- end
- else
- cut_pos = pos
- osd(string.format("Marked %s as start position", timestamp(pos)))
- end
- end
- function toggle_audio()
- copy_audio = not copy_audio
- osd("Audio capturing is " .. (copy_audio and "enabled" or "disabled"))
- end
- function toggle_subtitle()
- copy_subtitle = not copy_subtitle
- osd("Subtitle is " .. (copy_subtitle and "enabled" or "disabled"))
- end
- mp.add_key_binding("c", "slicing_mark", toggle_mark)
- mp.add_key_binding("a", "slicing_audio", toggle_audio)
Add Comment
Please, Sign In to add comment