occivink / mpv-scripts

Various scripts for mpv
The Unlicense
417 stars 38 forks source link

[Encode] Wrong stream clip format #45

Open dardo82 opened 3 years ago

dardo82 commented 3 years ago

When trying to clip a stream the output format is set by the file extension but not existing it always defaults to mkv.

occivink commented 3 years ago

You're talking about $x, right? It does indeed default to mkv if it cannot recognize the input format, should this be configurable?

dardo82 commented 3 years ago

Should be the same as the stream format; i've modified the code:

function get_extension(path)
    local is_stream = not file_exists(path)
    local format = mp.get_property("file-format")
    local candidate = string.match(path, "%.([^.]+)$")
    if candidate then
        for _, ext in ipairs({ "mkv", "webm", "mp4", "avi" }) do
            if candidate == ext then
                return candidate
            else
                if is_stream then
                    if format == "mov,mp4,m4a,3gp,3g2,mj2" then
                        return "mp4"
                    end
                end
            end
        end
    end
    return "mkv"
end
occivink commented 3 years ago

mh yeah thinking about it we probably should just use the real format instead of trying to parse it from a filename.

dardo82 commented 3 years ago

Right,the fix worked for me but it isn't general...