Skip to content

恢复播放

本节介绍 mpv 的恢复播放功能,帮助您从上次中断的位置继续播放。

基本恢复播放

退出时保存位置

Q 键退出 mpv,播放位置将被保存:

bash
# 按 Q 键退出(保存位置)
Q

恢复播放

下次播放同一文件时,mpv 将自动从上次位置继续:

bash
# 自动恢复播放
mpv video.mp4

恢复播放配置

启用恢复播放

bash
# 启用恢复播放
save-position-on-quit=yes

# 禁用恢复播放
save-position-on-quit=no

恢复播放选项

bash
# 恢复播放时显示提示
osd-on-seek=yes

# 恢复播放时自动播放
keep-open=yes

恢复播放文件

播放历史文件

mpv 将播放位置保存在以下文件:

  • Windows: %APPDATA%/mpv/watch_later/
  • macOS: ~/.config/mpv/watch_later/
  • Linux: ~/.config/mpv/watch_later/

文件格式

每个文件的播放位置保存为独立的文件,文件名基于视频文件的哈希值。

清除历史

bash
# 清除所有播放历史
rm -rf ~/.config/mpv/watch_later/*

# 清除特定文件的历史
rm ~/.config/mpv/watch_later/HASH

高级恢复功能

恢复播放命令

bash
# 恢复播放
revert-seek

# 标记当前位置
revert-seek mark

# 恢复到标记位置
revert-seek

恢复播放快捷键

快捷键功能
Shift+Backspace撤销上次跳转
Shift+Ctrl+Backspace标记当前位置

恢复播放脚本

lua
-- 自动恢复播放脚本
local mp = require 'mp'

local history_file = mp.get_property('config-dir') .. '/history.txt'

-- 保存播放位置
mp.register_event('shutdown', function()
    local path = mp.get_property('path')
    local time = mp.get_property_number('time-pos')
    
    if path and time then
        local file = io.open(history_file, 'a')
        file:write(string.format('%s\t%.2f\n', path, time))
        file:close()
    end
end)

-- 恢复播放位置
mp.register_event('file-loaded', function()
    local path = mp.get_property('path')
    
    local file = io.open(history_file, 'r')
    if file then
        for line in file:lines() do
            local saved_path, time = line:match('^(.-)\t(.-)$')
            if saved_path == path then
                mp.set_property_number('time-pos', tonumber(time))
                mp.osd_message(string.format('已恢复到 %.2f 秒', tonumber(time)))
                break
            end
        end
        file:close()
    end
end)

恢复播放选项

详细配置

bash
# 保存位置时保存更多状态
save-position-on-quit=yes

# 恢复播放时显示 OSD
osd-on-seek=yes

# 恢复播放时保持窗口
keep-open=yes

# 恢复播放时自动播放
pause=no

恢复播放范围

bash
# 恢复播放时的精度
hr-seek=yes

# 恢复播放时的延迟
hr-seek-framedrop=yes

恢复播放调试

查看播放历史

bash
# 列出播放历史
ls ~/.config/mpv/watch_later/

# 查看特定文件的播放位置
cat ~/.config/mpv/watch_later/HASH

调试恢复播放

bash
# 显示恢复播放信息
mpv --msg-level=all=v video.mp4

# 显示播放位置
mpv --osd-level=2 video.mp4

恢复播放故障排除

常见问题

  1. 播放位置未保存

    • 确保按 Q 键退出
    • 检查 save-position-on-quit 选项
  2. 播放位置未恢复

    • 检查 watch_later 目录是否存在
    • 检查文件权限
  3. 播放位置不准确

    • 启用精确跳转:hr-seek=yes
    • 调整跳转精度:hr-seek-framedrop=yes

调试命令

bash
# 显示播放位置
mpv --osd-level=2 video.mp4

# 显示播放信息
mpv --stats video.mp4

下一步