From 7364323cb664ce24fbc382234d35bb363278cf7f Mon Sep 17 00:00:00 2001 From: Erik Sandström Date: Mon, 8 Jun 2015 22:55:12 +0200 Subject: Updated directories and config files. --- mpv/config | 40 ++++-- mpv/input.conf | 9 +- mpv/lua/convert_script.lua | 319 ----------------------------------------- mpv/mvtools.vpy | 15 -- mpv/scripts/convert_script.lua | 319 +++++++++++++++++++++++++++++++++++++++++ mpv/shaders/deband.glsl | 42 ++++++ 6 files changed, 395 insertions(+), 349 deletions(-) delete mode 100644 mpv/lua/convert_script.lua delete mode 100755 mpv/mvtools.vpy create mode 100644 mpv/scripts/convert_script.lua create mode 100644 mpv/shaders/deband.glsl diff --git a/mpv/config b/mpv/config index c68c008..99c1536 100644 --- a/mpv/config +++ b/mpv/config @@ -1,32 +1,52 @@ # misc settings +title="MPV" no-osc -hwdec=vaapi -vo=opengl-hq:srgb:approx-gamma -#vo=opengl-hq:lscale=lanczos:cscale=lanczos:lradius=8.0:cradius=4.0:dither-depth=auto:temporal-dither:scaler-resizes-only:fancy-downscaling:pbo:fbo-format=rgba32f:srgb:approx-gamma -#vf=format=yuv420p,vapoursynth=/home/zephcom/.mpv/mvtools.vpy:2:4 +no-osd +no-osd-bar + +#hwdec=vaapi +#vo=vaapi + +#Mitchell +vo=opengl-hq:interpolation:tscale=mitchell:dither-depth=8:temporal-dither:pbo:target-prim=bt.709:target-trc=bt.1886:source-shader=/home/zephcom/.mpv/shaders/deband.glsl:gamma-auto + framedrop=vo -cache=262144 +cache=10000 geometry=50%:50% -autofit=1152x648 +autofit-larger=90%x90% +audio-channels=2 save-position-on-quit=yes +softvol=yes +ao=pulse +alang=en,eng,English,jpn,jap,Japanese + +ytdl +ytdl-format=bestvideo+bestaudio # Pretty srt font! +slang=en,eng,English osd-font="Liberation Sans" -sub-text-font="Liberation Sans" -sub-text-font-size=64 -sub-text-margin-y=36 +sub-text-font="Helvetica" +sub-text-font-size=38 +#sub-text-margin-y=14 sub-text-color="#ffffffff" sub-text-border-color="#ff000000" -sub-text-border-size=5.5 +sub-text-border-size=2.5 sub-text-shadow-offset=1 sub-text-shadow-color="#00000000" sub-text-spacing=-0.2 +ass-force-style=Kerning=yes +demuxer-mkv-subtitle-preroll +sub-use-margins +ass-force-margins # screenshots screenshot-format="png" screenshot-png-filter=0 screenshot-png-compression=4 +#really-quiet + # loop weebums [extension.webm] loop-file=inf diff --git a/mpv/input.conf b/mpv/input.conf index 502d7ff..1622822 100644 --- a/mpv/input.conf +++ b/mpv/input.conf @@ -1,5 +1,4 @@ -F1 set aspect 1.3333 -F2 set aspect 1.6 -F3 set aspect 1.7777 -F4 set aspect 1.85 -F5 set aspect 0 +- add volume -2 ++ add volume 2 +o ignore +F2 cycle_values video-aspect "16:9" "16:10" "4:3" "2.35:1" "-1" diff --git a/mpv/lua/convert_script.lua b/mpv/lua/convert_script.lua deleted file mode 100644 index 04fa508..0000000 --- a/mpv/lua/convert_script.lua +++ /dev/null @@ -1,319 +0,0 @@ --- README: --- original version by Zehkul https://gist.github.com/Zehkul/25ea7ae77b30af959be0 --- needs: yad, libnotify (and --ytdl if you want to encode from streams) --- press any of alt + w, g or x to set the start frame --- press again to set the end frame and use --- alt + w to make a webm --- alt + g to make a gif --- alt + x to make a x264 encoded mkv - --- Note: encoding a webm to a specific filesize will only work if audio is disabled --- and including subs will make them lose their styling - -local msg = require 'mp.msg' -local opt = require 'mp.options' -local mputils = require 'mp.utils' - --- default options, convert_script.conf is read -local options = { - bitrate_multiplier = 0.975, -- to make sure the file won’t go over the target file size, set it to 1 if you don’t care -} - -read_options(options, "convert_script_webm") -read_options(options, "convert_script_gif") -read_options(options, "convert_script_x264") - ------------------ --- Main script -- ------------------ - -function set_timepos(func) - - if timepos1 then - - timepos2 = mp.get_property("time-pos") - timepos2_humanreadable = mp.get_property_osd("time-pos") - - if tonumber(timepos1) > tonumber(timepos2) then - - length = timepos1-timepos2 - start = timepos2 - start_humanreadable = timepos2_humanreadable - end_humanreadable = timepos1_humanreadable - msg.info("End frame set") - - elseif tonumber(timepos2) > tonumber(timepos1) then - - length = timepos2-timepos1 - start = timepos1 - start_humanreadable = timepos1_humanreadable - end_humanreadable = timepos2_humanreadable - msg.info("End frame set") - - else - - msg.error("Both frames are the same, ignoring the second one") - mp.osd_message("Both frames are the same, ignoring the second one") - timepos2 = nil - return - - end - - timepos1 = nil - func.call_gui() - - else - - timepos1 = mp.get_property("time-pos") - timepos1_humanreadable = mp.get_property_osd("time-pos") - msg.info("Start frame set") - mp.osd_message("Start frame set") - - end - -end - -function convert_script_hotkey_call_webm () - - func = { - call_gui = call_gui_webm - } - - set_timepos(func) - -end - -function convert_script_hotkey_call_gif () - - func = { - call_gui = call_gui_gif - } - - set_timepos(func) - -end - -function convert_script_hotkey_call_x264 () - - func = { - call_gui = call_gui_x264 - } - - set_timepos(func) - -end - ------------- --- Encode -- ------------- - -function generate_filenames(ext) - - local filename_ext = mp.get_property_osd("filename") - filename_ext = string.gsub(filename_ext, "'", "'\\''") - local filename = string.gsub(filename_ext, "%....$","") - - if string.len(filename) > 230 then - - filename = mp.get_property("options/title") - if filename == 'mpv - ${media-title}' or string.len(filename) > 230 then - filename = 'output' - end - - end - - local path = mp.get_property("path", "") - local dir, fil = mputils.split_path(path) - - file_in = dir .. fil - file_out = dir .. filename .. "-out." .. ext - - file_in = string.gsub(file_in, "'", "'\\''") - file_out = string.gsub(file_out, "'", "'\\''") - - if string.sub(file_in,1,string.len("http")) == "http" then - - file_in = mp.get_property("stream-open-filename") - file_out = os.getenv("HOME") .. "/" .. mp.get_property("media-title") .. "-out." .. ext - file_out = string.gsub(file_out, "'", "'\\''") - - end - -end - -function encode_webm () - - generate_filenames("webm") - - local full_command = '(ffmpeg -ss ' .. start .. ' -i \'' .. file_in .. '\' -t ' .. length .. ' -b:v ' .. bitrate .. bitsize .. ' -vf scale=' .. scale .. ':-1 -quality good -cpu-used 0 -pass 1 ' .. audio .. ' ' .. subs .. ' -f webm /dev/null -y' - - full_command = full_command .. ' && ffmpeg -ss ' .. start .. ' -i \'' .. file_in .. '\' -t ' .. length .. ' -b:v ' .. bitrate .. bitsize .. ' -vf scale=' .. scale .. ':-1 -quality good -cpu-used 0 -pass 2 ' .. audio .. ' ' .. subs .. ' -f webm \'' .. file_out .. '\' -y' - - full_command = full_command .. ') && notify-send "Encode done!"' - - msg.info(full_command) - os.execute(full_command) - -end - -function encode_gif () - - generate_filenames("gif") - - local full_command = '(ffmpeg -ss ' .. start .. ' -i \'' .. file_in .. '\' -t ' .. length .. ' -vf scale=' .. scale .. ':-1 -r ' .. fps .. ' \'' .. file_out .. '\' -y' - - full_command = full_command .. ') && notify-send "Encode done!"' - - msg.info(full_command) - os.execute(full_command) - -end - -function encode_x264 () - - generate_filenames("mkv") - - local full_command = '(ffmpeg -ss ' .. start .. ' -i \'' .. file_in .. '\' -t ' .. length .. ' -c:v libx264 -vf scale=' .. sheight .. ':' .. swidth .. ' -preset slow -qp ' .. quality .. ' -c:a copy -c:s copy -map 0 \'' .. file_out .. '\' -y' - - full_command = full_command .. ') && notify-send "Encode done! (' .. quality .. ')"' - - msg.info(full_command) - os.execute(full_command) - -end - ---------- --- GUI -- ---------- - -function call_gui_webm () - - mp.resume_all() - local handle = io.popen('yad --title="Convert Script" --center --form --separator="\n" --field="Resize to:NUM" "720" --field="Don’t resize at all:CHK" "false" --field="Include audio:CHK" "false" --field="Include subs:CHK" "false" --field="Bitrate/Filesize (M):NUM" "3" --field="Filesize > Bitrate:CHK" "true" --button="gtk-cancel:2" --button="gtk-ok:0" && echo "$?"') - local yad = handle:read("*a") - handle:close() - - if yad == "" then - return - end - - local yad_table = {} - - local i = 0 - for k in string.gmatch(yad, "[%a%d]+") do - yad_table[i] = k - i = i + 1 - end - - if (yad_table[2] == "FALSE") then - scale = yad_table[0] - else - scale = "-1" - end - - if yad_table[3] == "FALSE" then - audio = '-an' - else - audio = "" - end - - if yad_table[4] == "FALSE" then - subs = '-sn' - else - subs = "" - end - - if yad_table[7] == "TRUE" then - bitrate = math.floor(yad_table[5]*1024*8/length*options.bitrate_multiplier) - bitsize = "K" - else - bitrate = yad_table[5] - bitsize = "M" - end - - if yad_table[8] == "0" then - encode_webm() - end - -end - -function call_gui_gif () - - mp.resume_all() - local handle = io.popen('yad --title="Convert Script" --center --form --separator="\n" --field="Resize to:NUM" "320" --field="Don’t resize at all:CHK" "false" --field="FPS:NUM" "24" --button="gtk-cancel:2" --button="gtk-ok:0" && echo "$?"') - local yad = handle:read("*a") - handle:close() - - if yad == "" then - return - end - - local yad_table = {} - - local i = 0 - for k in string.gmatch(yad, "[%a%d]+") do - yad_table[i] = k - i = i + 1 - end - - if (yad_table[2] == "FALSE") then - scale = yad_table[0] - else - scale = "-1" - end - - fps = yad_table[3] - - if yad_table[5] == "0" then - encode_gif() - end - -end - -function call_gui_x264 () - - mp.resume_all() - local handle = io.popen('yad --title="Convert Script" --center --form --separator="\n" --field="Resize height:NUM" "720" --field="Resize width:NUM" "480" --field="Don’t resize at all:CHK" "true" --field="Quality (0-51):NUM" "18" --button="gtk-cancel:2" --button="gtk-ok:0" && echo "$?"') - local yad = handle:read("*a") - handle:close() - - if yad == "" then - return - end - - local yad_table = {} - - local i = 0 - for k in string.gmatch(yad, "[%a%d]+") do - yad_table[i] = k - i = i + 1 - end - - if (yad_table[4] == "FALSE") then - sheight = yad_table[0] - else - sheight = "-1" - end - - if (yad_table[4] == "FALSE") then - swidth = yad_table[2] - else - swidth = "-1" - end - - if ((sheight ~= "-1" and swidth ~= "-1") and (tonumber(sheight)%2 ~= 0 or tonumber(swidth)%2 ~= 0)) then - os.execute('notify-send "' .. sheight ..':' .. swidth .. '"') - return - end - - quality = yad_table[5]; - - if yad_table[7] == "0" then - encode_x264() - end - -end - -mp.add_key_binding("alt+w", "convert_script_webm", convert_script_hotkey_call_webm) -mp.add_key_binding("alt+g", "convert_script_gif", convert_script_hotkey_call_gif) -mp.add_key_binding("alt+x", "convert_script_x264", convert_script_hotkey_call_x264) diff --git a/mpv/mvtools.vpy b/mpv/mvtools.vpy deleted file mode 100755 index 8fe5c5a..0000000 --- a/mpv/mvtools.vpy +++ /dev/null @@ -1,15 +0,0 @@ -import vapoursynth as vs -core = vs.get_core() - -clip = video_in - -if clip.width > 1920 or clip.height > 1080: - # Skip interpolation due to performance - clip.set_output() -else: - sup = core.mv.Super(clip, pel=2, hpad=0, vpad=0) - bvec = core.mv.Analyse(sup, blksize=16, isb=True , chroma=True, search=5, searchparam=1) - fvec = core.mv.Analyse(sup, blksize=16, isb=False, chroma=True, search=5, searchparam=1) -# clip = core.mv.BlockFPS(clip, sup, bvec, fvec, num=60, den=1, mode=3, thscd2=13) - - clip.set_output() diff --git a/mpv/scripts/convert_script.lua b/mpv/scripts/convert_script.lua new file mode 100644 index 0000000..04fa508 --- /dev/null +++ b/mpv/scripts/convert_script.lua @@ -0,0 +1,319 @@ +-- README: +-- original version by Zehkul https://gist.github.com/Zehkul/25ea7ae77b30af959be0 +-- needs: yad, libnotify (and --ytdl if you want to encode from streams) +-- press any of alt + w, g or x to set the start frame +-- press again to set the end frame and use +-- alt + w to make a webm +-- alt + g to make a gif +-- alt + x to make a x264 encoded mkv + +-- Note: encoding a webm to a specific filesize will only work if audio is disabled +-- and including subs will make them lose their styling + +local msg = require 'mp.msg' +local opt = require 'mp.options' +local mputils = require 'mp.utils' + +-- default options, convert_script.conf is read +local options = { + bitrate_multiplier = 0.975, -- to make sure the file won’t go over the target file size, set it to 1 if you don’t care +} + +read_options(options, "convert_script_webm") +read_options(options, "convert_script_gif") +read_options(options, "convert_script_x264") + +----------------- +-- Main script -- +----------------- + +function set_timepos(func) + + if timepos1 then + + timepos2 = mp.get_property("time-pos") + timepos2_humanreadable = mp.get_property_osd("time-pos") + + if tonumber(timepos1) > tonumber(timepos2) then + + length = timepos1-timepos2 + start = timepos2 + start_humanreadable = timepos2_humanreadable + end_humanreadable = timepos1_humanreadable + msg.info("End frame set") + + elseif tonumber(timepos2) > tonumber(timepos1) then + + length = timepos2-timepos1 + start = timepos1 + start_humanreadable = timepos1_humanreadable + end_humanreadable = timepos2_humanreadable + msg.info("End frame set") + + else + + msg.error("Both frames are the same, ignoring the second one") + mp.osd_message("Both frames are the same, ignoring the second one") + timepos2 = nil + return + + end + + timepos1 = nil + func.call_gui() + + else + + timepos1 = mp.get_property("time-pos") + timepos1_humanreadable = mp.get_property_osd("time-pos") + msg.info("Start frame set") + mp.osd_message("Start frame set") + + end + +end + +function convert_script_hotkey_call_webm () + + func = { + call_gui = call_gui_webm + } + + set_timepos(func) + +end + +function convert_script_hotkey_call_gif () + + func = { + call_gui = call_gui_gif + } + + set_timepos(func) + +end + +function convert_script_hotkey_call_x264 () + + func = { + call_gui = call_gui_x264 + } + + set_timepos(func) + +end + +------------ +-- Encode -- +------------ + +function generate_filenames(ext) + + local filename_ext = mp.get_property_osd("filename") + filename_ext = string.gsub(filename_ext, "'", "'\\''") + local filename = string.gsub(filename_ext, "%....$","") + + if string.len(filename) > 230 then + + filename = mp.get_property("options/title") + if filename == 'mpv - ${media-title}' or string.len(filename) > 230 then + filename = 'output' + end + + end + + local path = mp.get_property("path", "") + local dir, fil = mputils.split_path(path) + + file_in = dir .. fil + file_out = dir .. filename .. "-out." .. ext + + file_in = string.gsub(file_in, "'", "'\\''") + file_out = string.gsub(file_out, "'", "'\\''") + + if string.sub(file_in,1,string.len("http")) == "http" then + + file_in = mp.get_property("stream-open-filename") + file_out = os.getenv("HOME") .. "/" .. mp.get_property("media-title") .. "-out." .. ext + file_out = string.gsub(file_out, "'", "'\\''") + + end + +end + +function encode_webm () + + generate_filenames("webm") + + local full_command = '(ffmpeg -ss ' .. start .. ' -i \'' .. file_in .. '\' -t ' .. length .. ' -b:v ' .. bitrate .. bitsize .. ' -vf scale=' .. scale .. ':-1 -quality good -cpu-used 0 -pass 1 ' .. audio .. ' ' .. subs .. ' -f webm /dev/null -y' + + full_command = full_command .. ' && ffmpeg -ss ' .. start .. ' -i \'' .. file_in .. '\' -t ' .. length .. ' -b:v ' .. bitrate .. bitsize .. ' -vf scale=' .. scale .. ':-1 -quality good -cpu-used 0 -pass 2 ' .. audio .. ' ' .. subs .. ' -f webm \'' .. file_out .. '\' -y' + + full_command = full_command .. ') && notify-send "Encode done!"' + + msg.info(full_command) + os.execute(full_command) + +end + +function encode_gif () + + generate_filenames("gif") + + local full_command = '(ffmpeg -ss ' .. start .. ' -i \'' .. file_in .. '\' -t ' .. length .. ' -vf scale=' .. scale .. ':-1 -r ' .. fps .. ' \'' .. file_out .. '\' -y' + + full_command = full_command .. ') && notify-send "Encode done!"' + + msg.info(full_command) + os.execute(full_command) + +end + +function encode_x264 () + + generate_filenames("mkv") + + local full_command = '(ffmpeg -ss ' .. start .. ' -i \'' .. file_in .. '\' -t ' .. length .. ' -c:v libx264 -vf scale=' .. sheight .. ':' .. swidth .. ' -preset slow -qp ' .. quality .. ' -c:a copy -c:s copy -map 0 \'' .. file_out .. '\' -y' + + full_command = full_command .. ') && notify-send "Encode done! (' .. quality .. ')"' + + msg.info(full_command) + os.execute(full_command) + +end + +--------- +-- GUI -- +--------- + +function call_gui_webm () + + mp.resume_all() + local handle = io.popen('yad --title="Convert Script" --center --form --separator="\n" --field="Resize to:NUM" "720" --field="Don’t resize at all:CHK" "false" --field="Include audio:CHK" "false" --field="Include subs:CHK" "false" --field="Bitrate/Filesize (M):NUM" "3" --field="Filesize > Bitrate:CHK" "true" --button="gtk-cancel:2" --button="gtk-ok:0" && echo "$?"') + local yad = handle:read("*a") + handle:close() + + if yad == "" then + return + end + + local yad_table = {} + + local i = 0 + for k in string.gmatch(yad, "[%a%d]+") do + yad_table[i] = k + i = i + 1 + end + + if (yad_table[2] == "FALSE") then + scale = yad_table[0] + else + scale = "-1" + end + + if yad_table[3] == "FALSE" then + audio = '-an' + else + audio = "" + end + + if yad_table[4] == "FALSE" then + subs = '-sn' + else + subs = "" + end + + if yad_table[7] == "TRUE" then + bitrate = math.floor(yad_table[5]*1024*8/length*options.bitrate_multiplier) + bitsize = "K" + else + bitrate = yad_table[5] + bitsize = "M" + end + + if yad_table[8] == "0" then + encode_webm() + end + +end + +function call_gui_gif () + + mp.resume_all() + local handle = io.popen('yad --title="Convert Script" --center --form --separator="\n" --field="Resize to:NUM" "320" --field="Don’t resize at all:CHK" "false" --field="FPS:NUM" "24" --button="gtk-cancel:2" --button="gtk-ok:0" && echo "$?"') + local yad = handle:read("*a") + handle:close() + + if yad == "" then + return + end + + local yad_table = {} + + local i = 0 + for k in string.gmatch(yad, "[%a%d]+") do + yad_table[i] = k + i = i + 1 + end + + if (yad_table[2] == "FALSE") then + scale = yad_table[0] + else + scale = "-1" + end + + fps = yad_table[3] + + if yad_table[5] == "0" then + encode_gif() + end + +end + +function call_gui_x264 () + + mp.resume_all() + local handle = io.popen('yad --title="Convert Script" --center --form --separator="\n" --field="Resize height:NUM" "720" --field="Resize width:NUM" "480" --field="Don’t resize at all:CHK" "true" --field="Quality (0-51):NUM" "18" --button="gtk-cancel:2" --button="gtk-ok:0" && echo "$?"') + local yad = handle:read("*a") + handle:close() + + if yad == "" then + return + end + + local yad_table = {} + + local i = 0 + for k in string.gmatch(yad, "[%a%d]+") do + yad_table[i] = k + i = i + 1 + end + + if (yad_table[4] == "FALSE") then + sheight = yad_table[0] + else + sheight = "-1" + end + + if (yad_table[4] == "FALSE") then + swidth = yad_table[2] + else + swidth = "-1" + end + + if ((sheight ~= "-1" and swidth ~= "-1") and (tonumber(sheight)%2 ~= 0 or tonumber(swidth)%2 ~= 0)) then + os.execute('notify-send "' .. sheight ..':' .. swidth .. '"') + return + end + + quality = yad_table[5]; + + if yad_table[7] == "0" then + encode_x264() + end + +end + +mp.add_key_binding("alt+w", "convert_script_webm", convert_script_hotkey_call_webm) +mp.add_key_binding("alt+g", "convert_script_gif", convert_script_hotkey_call_gif) +mp.add_key_binding("alt+x", "convert_script_x264", convert_script_hotkey_call_x264) diff --git a/mpv/shaders/deband.glsl b/mpv/shaders/deband.glsl new file mode 100644 index 0000000..1b2f047 --- /dev/null +++ b/mpv/shaders/deband.glsl @@ -0,0 +1,42 @@ +// vim: set ft=glsl: + +// roughly corresponds to f3kdb parameters, which this algorithm is +// loosely inspired by +#define threshold 64 +#define range 16 +#define grain 24 + +float rand(vec2 co){ + return fract(sin(dot(co.yx, vec2(12.9898,78.233))) * 43758.5453); +} + +vec4 sample(sampler2D tex, vec2 pos, vec2 tex_size) +{ + // Compute a random angle and distance + float dist = rand(pos + vec2(random)) * range; + vec2 pt = dist / image_size; + float dir = rand(pos.yx - vec2(random)) * 6.2831853; + vec2 o = vec2(cos(dir), sin(dir)); + + // Sample at quarter-turn intervals around the source pixel + vec4 ref[4]; + ref[0] = texture(tex, pos + pt * vec2( o.x, o.y)); + ref[1] = texture(tex, pos + pt * vec2(-o.y, o.x)); + ref[2] = texture(tex, pos + pt * vec2(-o.x, -o.y)); + ref[3] = texture(tex, pos + pt * vec2( o.y, -o.x)); + + // Average and compare with the actual sample + vec4 avg = cmul*(ref[0] + ref[1] + ref[2] + ref[3])/4.0; + vec4 col = cmul*texture(tex, pos); + vec4 diff = abs(col - avg); + + // Use the average if below the threshold + col = mix(avg, col, greaterThan(diff, vec4(threshold/16384.0))); + + // Add some random noise to the output + vec3 noise = vec3(rand(2*pos + vec2(random)), + rand(3*pos + vec2(random)), + rand(4*pos + vec2(random))); + col.rgb += (grain/8192.0) * (noise - vec3(0.5)); + return col; +} -- cgit v1.2.3-70-g09d2