Skip to content

截图功能

本节介绍 mpv 的截图功能和配置选项。

基本截图

交互式截图

s 键截图,截图将保存到当前目录或配置的截图目录。

截图快捷键

快捷键功能
s截图(包含字幕)
S截图(不包含字幕)

截图配置

截图目录

bash
# 指定截图目录
screenshot-directory=~/Pictures/mpv

# 使用视频文件所在目录
screenshot-directory=.

截图文件名

bash
# 截图文件名模板
screenshot-template="%F-%P"

# 模板变量
# %F - 文件名(不含扩展名)
# %P - 时间戳(HH-MM-SS)
# %p - 时间戳(秒)
# %n - 截图序号
# %t - 时间戳(完整)

截图格式

bash
# PNG 格式
screenshot-format=png

# JPEG 格式
screenshot-format=jpg

# WebP 格式
screenshot-format=webp

截图质量

bash
# PNG 压缩级别 (0-9)
screenshot-png-compression=7

# JPEG 质量 (0-100)
screenshot-jpeg-quality=90

# WebP 质量 (0-100)
screenshot-webp-quality=90

高级截图功能

截图滤镜

bash
# 截图时应用滤镜
screenshot-filter=lavfi=[scale=1920:1080]

# 截图时应用色彩空间
screenshot-high-bit-depth=yes

截图模板

bash
# 使用模板变量
screenshot-template="%F_%t"

# 自定义模板
screenshot-template="screenshot_%n"

截图命名

bash
# 使用时间戳
screenshot-template="%F-%P"

# 使用序号
screenshot-template="%F-%n"

# 使用完整时间
screenshot-template="%F_%t"

批量截图

定时截图

bash
# 每 10 秒截图
mpv --screenshot-interval=10 video.mp4

范围截图

bash
# 截取特定时间范围
mpv --start=60 --end=120 --screenshot-interval=5 video.mp4

截图序列

bash
# 截取帧序列
mpv --screenshot-format=png --screenshot-interval=1 video.mp4

截图脚本

Lua 脚本示例

lua
-- 自动截图脚本
local mp = require 'mp'

mp.add_key_binding('ctrl+s', 'screenshot-sequence', function()
    local start_time = mp.get_property_number('time-pos')
    local end_time = mp.get_property_number('duration')
    
    for t = start_time, end_time, 10 do
        mp.commandv('screenshot-to-file', 
            string.format('frame_%05d.png', t),
            'subtitles')
    end
end)

JavaScript 脚本示例

javascript
// 自动截图脚本
mp.add_key_binding('ctrl+s', 'screenshot-sequence', function() {
    const start = mp.get_property_number('time-pos');
    const end = mp.get_property_number('duration');
    
    for (let t = start; t < end; t += 10) {
        mp.commandv('screenshot-to-file', 
            `frame_${t.toString().padStart(5, '0')}.png`,
            'subtitles');
    }
});

截图命令

命令行截图

bash
# 截图到文件
mpv --screenshot-to-file=frame.png video.mp4

# 截图到目录
mpv --screenshot-directory=~/Pictures video.mp4

交互式命令

bash
# 截图命令
screenshot-to-file frame.png
screenshot-to-file frame.png subtitles
screenshot-to-file frame.png video

截图格式选项

PNG 选项

bash
# PNG 压缩级别
screenshot-png-compression=7

# PNG 颜色深度
screenshot-high-bit-depth=yes

JPEG 选项

bash
# JPEG 质量
screenshot-jpeg-quality=90

# JPEG 优化
screenshot-jpeg-optimize=100

WebP 选项

bash
# WebP 质量
screenshot-webp-quality=90

# WebP 无损压缩
screenshot-webp-lossless=no

截图调试

查看截图信息

bash
# 显示截图信息
mpv --screenshot-format=png --screenshot-template="%F_%t" video.mp4

截图测试

bash
# 测试截图功能
mpv --screenshot-to-file=test.png --start=10 --frames=1 video.mp4

下一步