You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在MPV播放器实现YouTube式按百分比跳转(10%-90%)?

实现MPV数字键跳转对应视频百分比位置的Lua脚本方案

完全可以通过Lua脚本实现该功能,以下是具体的实现代码和使用步骤:

脚本代码

创建一个名为jump-by-percent.lua的文件,写入以下内容:

-- 覆盖数字键1-9默认绑定,实现YouTube式百分比跳转
for i = 1, 9 do
    local key = tostring(i)
    mp.add_forced_key_binding(key, "jump-to-" .. i .. "0-percent", function()
        local duration = mp.get_property_number("duration")
        if duration and duration > 0 then
            local target_pos = duration * (i * 0.1)
            mp.set_property_number("time-pos", target_pos)
        end
    end)
end

代码说明

  • 循环遍历1-9的数字,为每个数字键创建强制绑定(add_forced_key_binding),直接覆盖MPV默认的数字键功能
  • 获取视频总时长duration,验证时长有效后,计算目标播放位置:总时长 × 数字对应的百分比(如按键4对应40%即0.4)
  • 通过set_property_number将视频播放位置设置到计算出的目标点

使用方法

  • 将脚本文件放入MPV的脚本目录:
    • Windows:%APPDATA%\mpv\scripts\
    • Linux/macOS:~/.config/mpv/scripts/
  • 重启MPV即可生效,按下数字键1-9就会跳转到对应百分比的位置,逻辑与YouTube完全一致

内容的提问来源于stack exchange,提问作者Crabgrass0899

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 22:30:29