chapters_for_mpv icon indicating copy to clipboard operation
chapters_for_mpv copied to clipboard

edit sub function for image, video or audio for screenshot

Open mrfragger opened this issue 8 months ago • 1 comments

mpv if you use the buiiltin screenshot it doesn't match exactly the alignment. So best to use built-in screenshot for OS.

Image Image

mrfragger avatar Apr 29 '25 02:04 mrfragger

Ctrl+t cycle-values sub-line-spacing '-110' '-90' '-70' '-50' '-30' '-25' '-20' '-15' '-10' '-5' '0'  #! [Subtitles] > [Format] > Sub Line Spacing
-  cycle-values sub-align-x  'left' 'center' 'right'  #! [Subtitles] > [Format] > Subtitle left, center, right
=  cycle-values sub-justify  'left' 'center' 'right' 'auto'  #! [Subtitles] > [Format] > Subtitle justify left, center, right, auto
_  cycle-values sub-align-y  'bottom' 'center' 'top'  #! [Subtitles] > [Format] > Subtitle align-y bottom, center, top
Alt+t cycle-values sub-margin-x '19' '50' '100' '150' '200' '250' '300'  #! [Subtitles] > [Format] > Subtitle margin-x

Use the above for formatting subs and moving them around.

keybinding for chapters for mpv script d-SPACE script-binding chapters/edit_sub #! [Screenshots] > Edit Subs for Screenshot on image, audio or video

Just add the following function in chapters for mpv script

-- Editing editsubs.vtt of Subtitle text of an image, video or audio for a screenshot

local function edit_sub()
    local subtitle_path = utils.join_path(utils.join_path(os.getenv("HOME"), ".config/mpv/extrastuff"), "editsubs.vtt")    local dir = utils.split_path(subtitle_path)

    if not utils.file_info(dir) then
        mkdir(dir)
    end

    mp.commandv("sub-add", subtitle_path)

    local default_text = ""
    local file = io.open(subtitle_path, "r")
    if file then
        local content = file:read("*a") 
        file:close()

        local in_header = true
        for line in content:gmatch("[^\n]+") do
            if in_header then
                if line:match("^%d%d:%d%d:%d%d%.%d%d%d %-%-%> %d%d:%d%d:%d%d%.%d%d%d$") or line:match("^WEBVTT$") then
                else
                    in_header = false
                    default_text = default_text .. line .. "\n"
                end
            else
                default_text = default_text .. line .. "\n"
            end
        end
        default_text = default_text:gsub("\n$", "") 
    else
        msg.error("Subtitle file does not exist, starting with empty default text.")
    end

    local prompt = "Shift+Cmd+5 (mac)\nLoad an image, video or audio\nto take a screenshot of\nCtrl+U delete all text\nShift+Enter for newline\nEnter subtitle text:\n"

    input.get({
        prompt = prompt,
        submit = function(user_input)
            local file = io.open(subtitle_path, "w")
            if file then
                file:write("WEBVTT\n\n")
                file:write("00:00:00.000 --> 99:59:59.999\n")
                file:write(user_input or default_text)
                file:close()

                mp.commandv("sub-reload")
                msg.verbose("Subtitle saved to:", subtitle_path)
                mp.osd_message("Subtitle updated!", 1)
            else
                msg.error("Failed to create subtitle file:", subtitle_path)
            end
        end,
        default_text = default_text,
        cursor_position = #(default_text) + 1,
    })

    if options.pause_on_input then
        mp.set_property_bool("pause", true)
    end
end

mrfragger avatar Apr 29 '25 03:04 mrfragger