Skip to content

Commit

Permalink
配置更新
Browse files Browse the repository at this point in the history
  • Loading branch information
dyphire committed Mar 9, 2024
1 parent 4897084 commit b158faf
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 38 deletions.
5 changes: 3 additions & 2 deletions mpv.conf
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ hwdec=d3d12va-copy,auto-copy # 指定应使用的硬件视频解码 API
## 硬解模式可能会遇到一些问题,推荐优先使用软解(官方手册不推荐使用硬解)
## 经测试发现--vo=gpu 下的 copy 硬解模式在 4K 及以上视频帧率>=60fps 时将会产生异常掉帧,建议使用软解模式或无 copy 硬解模式
#hwdec-codecs=all # 在选定范围内的编码格式尝试硬解,当前版本默认值为 --hwdec-codecs="h264,vc1,hevc,vp8,vp9,av1,prores"
#vd-lavc-dr=no # [当 gpu-api=d3d11 时] 启用直接渲染(默认:yes)。如果设置为 yes,视频将直接解码到 GPU 视频内存(或暂存缓冲区)
#vd-lavc-dr=no # [当 gpu-api=d3d11 时] 启用直接渲染(默认:auto)。如果设置为 yes,视频将直接解码到 GPU 视频内存(或暂存缓冲区)
# 如果设置为 no,视频将解码到系统内存,然后复制到 GPU 内存。这可能会导致性能下降,但可能会解决某些低端 intel GPU 上的问题
# 默认值 auto 会根据解码器和 GPU 的能力自动选择(即对于低端 intel GPU 设备自动禁用)
#vd-queue-enable=yes # 启用视频解码器队列(默认:no)。如果设置为 yes,视频解码器将在单独的线程上运行,这可能会导致性能下降,但可能会解决某些低端 intel GPU 上的问题
#vd-lavc-threads=8 # 用于解码的线程数。是否实际支持线程取决于编解码器(默认值:0)。0 表示自动检测机器上的内核数并使用它,最多为 16。您可以手动设置超过 16 个线程
#vd-lavc-assume-old-x264=yes # 假设视频是由旧的、有缺陷的 x264 版本编码的(默认:no)。仅当 x264 yuv444p10 格式的视频解码错误时尝试启用此项解决 ffmpeg 对旧的 x264 编码的兼容问题
Expand Down Expand Up @@ -809,7 +810,7 @@ profile=NNEDI3 # 适用于大多数场景(NNEDI

#[DoVi-P5]
#profile-desc=DoVi-P5 转换 HDR 直通
#profile-cond=p["video-out-params/max-luma"] > 203 and p["video-params/gamma"] == "bt.1886"
#profile-cond=get("video-params/colormatrix") == "dolbyvision" and get("video-params/colorlevels") == "full"
#profile-restore=copy
#target-trc=bt.2020
#target-gamut=dci-p3
Expand Down
4 changes: 2 additions & 2 deletions script-opts/fuzzydir.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## 指定查找的最大路径深度,默认值:3
#max_search_depth=3
## 指定查找的最大路径深度,默认值:1
max_search_depth=1
## 脚本将跳过大于此选项数量的目录的路径,默认值:10
#discovery_threshold=10
## 指定需忽略的共享盘(挂载盘)的路径。windows 示例:excluded_dir=["X:", "Z:", "F:/Download/", "Download"]
Expand Down
10 changes: 9 additions & 1 deletion scripts/autosubsync/autosubsync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ local function extract_to_file(subtitle_track)
end
local temp_sub_fp = utils.join_path(os_temp(), 'autosubsync_extracted.' .. ext)
notify("提取内封字幕...", nil, 3)
local screenx, screeny, aspect = mp.get_osd_size()
mp.set_osd_ass(screenx, screeny, "{\\an9}● ")
local ret = subprocess {
config.ffmpeg_path,
"-hide_banner",
Expand All @@ -224,6 +226,7 @@ local function extract_to_file(subtitle_track)
"-f", ext,
temp_sub_fp
}
mp.set_osd_ass(screenx, screeny, "")
if ret == nil or ret.status ~= 0 then
return notify("无法提取内封字幕.\n请先确保在脚本配置文件中为 ffmpeg 指定了正确的路径\n并确保视频有内封字幕.", "error", 7)
end
Expand Down Expand Up @@ -256,15 +259,20 @@ local function sync_subtitles(ref_sub_path)
notify(string.format("开始 %s...", engine_name), nil, 2)

local ret
local screenx, screeny, aspect = mp.get_osd_size()
if engine_name == "ffsubsync" then
local args = { config.ffsubsync_path, reference_file_path, "-i", subtitle_path, "-o", retimed_subtitle_path }
if not ref_sub_path then
table.insert(args, '--reference-stream')
table.insert(args, '0:' .. get_active_track('audio'))
end
mp.set_osd_ass(screenx, screeny, "{\\an9}● ")
ret = subprocess(args)
mp.set_osd_ass(screenx, screeny, "")
else
mp.set_osd_ass(screenx, screeny, "{\\an9}● ")
ret = subprocess { config.alass_path, reference_file_path, subtitle_path, retimed_subtitle_path }
mp.set_osd_ass(screenx, screeny, "")
end

if ret == nil then
Expand All @@ -283,7 +291,7 @@ local function sync_subtitles(ref_sub_path)
notify("错误: 不能添加同步字幕.", "error", 3)
end
else
notify(string.format("字幕同步失败.\n请确保在脚本配置文件中为 %s 指定了正确的路径.", engine_name), "error", 3)
notify(string.format("字幕同步失败.\n请确保在脚本配置文件中为 %s 指定了正确的路径.\n或音轨提取失败", engine_name), "error", 3)
end
end

Expand Down
2 changes: 1 addition & 1 deletion scripts/fuzzydir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ local utils = require 'mp.utils'
local options = require 'mp.options'

o = {
max_search_depth = 3,
max_search_depth = 1,
discovery_threshold = 10,
excluded_dir = [[
[]
Expand Down
69 changes: 37 additions & 32 deletions scripts/subtitle-lines.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- subtitle-lines 1.1.0 - 2024-Feb-02
-- subtitle-lines 1.1.1 - 2024-Mar-08
-- https://github.com/christoph-heinrich/mpv-subtitle-lines
--
-- List and search subtitle lines of the selected subtitle track.
Expand Down Expand Up @@ -50,7 +50,7 @@ local sub_strings_available = {
}
}

---@alias Subtitle {start:number;stop:number;line:string}
---@alias Subtitle {start:number;stop:number;line:string;timespan:string}

local sub_strings = sub_strings_available.primary
local function get_current_subtitle_lines()
Expand All @@ -68,14 +68,14 @@ end

---Merge lines with already collected subtitles
---removes merged lines from the lines array
---@param subtitles Subtitle[]
---@param prev_subs_visible Subtitle[]
---@param start number
---@param stop number
---@param lines string[]
---@return string[]
local function merge_subtitle_lines(subtitles, start, stop, lines)
local function merge_subtitle_lines(prev_subs_visible, start, stop, lines)
-- merge identical lines that overlap or are right after each other
for _, subtitle in ipairs(subtitles) do
for _, subtitle in ipairs(prev_subs_visible) do
if subtitle.stop >= start or same_time(subtitle.stop, start) then
for i = #lines, 1, -1 do
if lines[i] == subtitle.line then
Expand All @@ -91,13 +91,12 @@ end

---Fix end time of already collected subtitles and finds the currect start time
---for current lines
---@param subtitles Subtitle[]
---@param prev_lines string[]
---@param prev_subs_visible Subtitle[]
---@param lines string[]
---@param start number
---@param prev_start number
---@return number
local function fix_line_timing(subtitles, prev_lines, lines, start, prev_start)
local function fix_line_timing(prev_subs_visible, lines, start, prev_start)
-- detect subtitles appearing after their reported sub-start time
if start == prev_start then
local start_approx = mp.get_property_number('time-pos', 0) - mp.get_property_number(sub_strings.delay) - SUB_SEEK_OFFSET
Expand All @@ -106,21 +105,17 @@ local function fix_line_timing(subtitles, prev_lines, lines, start, prev_start)
start = start_approx
end
end
-- detect subtitle lines disappearing before their reported sub-end time.
for j = #prev_lines, 1, -1 do
local prev_line = prev_lines[j]
for _, line in ipairs(lines) do
if prev_line == line then
table.remove(prev_lines, j)
for _, subtitle in ipairs(prev_subs_visible) do
if subtitle.stop > start then
local still_visible = false
for _, line in ipairs(lines) do
if subtitle.line == line then
still_visible = true
break
end
end
end
end
for j = #prev_lines, 1, -1 do
local prev_line = prev_lines[j]
for _, subtitle in ipairs(subtitles) do
if subtitle.line == prev_line and subtitle.stop > start then
if not still_visible then
subtitle.stop = start
break
end
end
end
Expand Down Expand Up @@ -156,12 +151,13 @@ local function acquire_subtitles()
local prev_start = -1
local prev_stop = -1
local prev_text = nil
local prev_lines = {}
---@type Subtitle[]
local prev_subs_visible = {}

retry_delay = nil
while true do
local start, stop, text, lines = get_current_subtitle_lines()
if start and (text ~= prev_text or not same_time(start, prev_start) or not same_time(stop, prev_stop)) then
if start and stop and text and (text ~= prev_text or start ~= prev_start or stop ~= prev_stop) then
-- remove empty lines
for j = #lines, 1, -1 do
if not lines[j]:find('[^%s]') then
Expand All @@ -180,19 +176,23 @@ local function acquire_subtitles()
---mpv reports the earliest sub-start and the latest sub-end of all
---current lines, so a line that's there for a long time
---can mess up the timing of all other current lines
local start_fixed = fix_line_timing(subtitles, prev_lines, lines, start, prev_start)
local start_fixed = fix_line_timing(prev_subs_visible, lines, start, prev_start)

for j = #prev_lines, 1, -1 do
prev_lines[j] = nil
end
for j, line in ipairs(lines) do
prev_lines[j] = line
merge_subtitle_lines(prev_subs_visible, start_fixed, stop, lines)

for j = #prev_subs_visible, 1, -1 do
if prev_subs_visible[j].stop <= start_fixed then
table.remove(prev_subs_visible, j)
end
end

merge_subtitle_lines(subtitles, start_fixed, stop, lines)
local j = #prev_subs_visible
for _, line in ipairs(lines) do
i = i + 1
subtitles[i] = { start = start_fixed, stop = stop, line = line }
j = j + 1
local subtitle = { start = start_fixed, stop = stop, line = line }
subtitles[i] = subtitle
prev_subs_visible[j] = subtitle
end
else
local delay = mp.get_property_number(sub_strings.delay)
Expand All @@ -209,6 +209,11 @@ local function acquire_subtitles()

mp.set_property_number(sub_strings.delay, sub_delay)
mp.set_property_bool(sub_strings.visibility, sub_visibility)

for _, subtitle in ipairs(subtitles) do
subtitle.timespan = mp.format_time(subtitle.start) .. '-' .. mp.format_time(subtitle.stop)
end

return subtitles
end

Expand Down Expand Up @@ -252,7 +257,7 @@ local function show_subtitle_list(subtitles)
local is_active = has_started and not has_ended
menu.items[i] = {
title = subtitle.line,
hint = mp.format_time(subtitle.start) .. '-' .. mp.format_time(subtitle.stop),
hint = subtitle.timespan,
active = is_active,
value = {
'seek',
Expand Down

0 comments on commit b158faf

Please sign in to comment.