Skip to content

Instantly share code, notes, and snippets.

@Shudouken
Last active September 6, 2017 16:29
Show Gist options
  • Save Shudouken/52a6908f54ef3dd1696557901bface75 to your computer and use it in GitHub Desktop.
Save Shudouken/52a6908f54ef3dd1696557901bface75 to your computer and use it in GitHub Desktop.
-- Simple hook that converts .bpg files as you open them with mpv
-- libbpg needs to be installed on your system
-- You can specify the output format (.ppm or .png) but conversion
-- to .png is slower. You can also increase the bit depth for .png
-- by passing "-b 16" and it supports transparency.
-- It seems animated files are not yet supported by bpgdec.
local msg = require 'mp.msg'
function convert_bpg()
local file_in = mp.get_property_osd("stream-open-filename")
local file_in = string.gsub(file_in, "'", "'\\''")
if file_in:sub(file_in:len()-3,file_in:len()) == ".bpg" then
local file_out = os.tmpname() .. ".ppm"
if os.execute("bpgdec " .. file_in .. " -o " .. file_out) then
mp.set_property("stream-open-filename", file_out)
else
msg.info("Failed to convert " .. file_in)
end
end
end
mp.add_hook("on_load", 50, convert_bpg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment