VLC同时显示两条Subtitle

这一篇很早之前就应该写好的,结果从5月拖到了7月……原因是!Lockdown!

这次Lockdown真的要把吾辈搞疯了,5月的时候吾辈感觉上还没什么问题。当时把这篇blog所需的材料都找齐后,然后就是例行拖延症……结果拖了一阵子后,发现整个人做什么事情都提不起兴趣,Switch都没有兴趣碰了。那阵子吾辈整天干的事情就是睡觉,和看Youtube木棉花TW的无限《ワンパンマン》马拉松……

最近作息稍稍恢复了点,虽然身体和心理状态没有恢复到Lockdown之前的状态,但好歹是能写一些字了。

其实今天吾辈会又想起要补上这篇是有个契机的。吾辈在写这些文字的时候其实已经是7/18了,昨天干了件很蠢的事情:本来想用~/来写winston的transports路径的,结果没得到想要的效果,看了眼结果在Source目录下新建了一个~目录;当时没动脑子,直接rm -rf ~ Enter一气呵成,结果执行了几秒发现还没结束,当时就发现不对了,赶紧Control+C……

rm执行了大概8s,还是删了不少东西的,由于没有日志,具体损失不明[爆哭],案发现场如下图:

经此一役,吾辈立下几个flag:

  1. 从今以后再敲rm -rf 剁手
  2. 从今以后出门一定穿袜子(MD,吾辈今天出门因为懒没穿袜子,脚又被磨破了)

好吧,第二条和上面说的事完全无关。

虽然这次误删的东西应该不涉及吾辈的生命财产安全,但是以防万一,还是有必要清理一下历史遗产。

好!开始说正题!

之前脑子抽风,想要看双语对照字幕,就像《丸子与银河龙》提供的那样,这就是本文的起源。

这次搞到的视频文件内嵌了多语字幕,原材料是不用再去找了,剩下的全是加工的问题了,本文分两步走:提取内嵌字幕、在VLC中显示两条字幕。

本文唯一指定播放器:VLC media player

提取内嵌字幕

啊,时间有点久了,我记得应该是这样吧:

1
2
3
4
5
6
7
ffmpeg -i Movie.mkv -map 0:s:0 subs.srt

# -i: Input file URL/path.
# -map: Designate one or more input streams as a source for the output file.
# s:0: Select the subtitle stream.
# This would download the first subtitle track. If there are several, use 0:s:1 to download the second one, 0:s:2 to download the third one, and so on.
# To extract more subtitles at once you have to duplicate the -map parameters for each file. Also include -c copy so that it just extracts the file without trying to process it: ffmpeg -i Movie.mkv -c copy -map 0:s:0 subs.01.srt -c copy -map 0:s:1 subs.02.srt. Anyway it will take long time because ffmpeg must read whole video file to find all parts of the subtitle streams.

如果还有问题请参考下面的Reference,当时这条解决了我的问题。

Reference

  1. How to extract subtitle from video using ffmpeg?

字幕插件:Subtitler lite mod

Source & Manual: Subtitler lite mod v1.3

从上面的链接下载Subtitler lite mod,并放到指定位置:

1
2
3
4
5
6
7
8
9
10
INSTALLATION:
- extract (unzip) the .lua file and put it in the VLC subdir /lua/extensions, by default:
* Windows (all users): %ProgramFiles%\VideoLAN\VLC\lua\extensions\
* Windows (current user): %APPDATA%\VLC\lua\extensions\
* Linux (all users): /usr/lib/vlc/lua/extensions/
* Linux (current user): ~/.local/share/vlc/lua/extensions/
* Mac OS X (all users): /Applications/VLC.app/Contents/MacOS/share/lua/extensions/
* Mac OS X (current user): /Users/%your_name%/Library/Application Support/org.videolan.vlc/lua/extensions/
(create directories if they don't exist)
- Restart VLC or just reload extensions (Tools > Plugins and extensions > Active Extensions tab: Reload extensions button).

至此,Subtitler lite mod安装完毕,使用方法如下:

1
2
3
4
5
Then you simply start the extension in VLC menu "View" or "Vlc > Extensions" on Mac OS.

The extension will try to load SRT subtitle file of the same name and location as a playing media ("d:\films\film.avi" --> "d:\films\film.srt").

Then you need to keep pressing the [Refresh] button in the dialog box.

如果插件显示的文字是乱码的话,用户需要根据需求改一下插件的lua脚本。脚本开头定义了编码格式参数,默认应该是Windows-1250

但是,一直按「Refresh」也太蠢了吧!

所以,插件的Description中,作者贴心地提供了各种系统下的Key Sender:

1
2
3
4
5
6
7
8
9
You rather use some button presser / key sender. Following ones are included in the package:
- "keypresser(Windows).vbs", a simple VBScript for Windows users;
- "buttonpresser(Mac).applescript", a simple AppleScript for Mac OS X users
http://addons.videolan.org/content/show.php?content=152364&forumpage=1#c473169
- "keeping-press-enter(Linux).sh" - Linux, xdotool - A shell script:
http://wikiwiki.jp/disklessfun/?misc1#e976f4fa
"sleep 0.1" or "usleep 100000" instead of "sleep 1"?
- "subtitlerlite.ahk" - AutoHotkey script for Windows:
https://forum.videolan.org/viewtopic.php?f=29&t=97791&start=40#p407054

下面讲一下Linux下的操作。

作者提供的Linux下的脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh
TITLE="Subtitler \(lite\) mod"
MSG="Pressing Enter key"
FLG=true

zenity --progress --pulsate --no-cancel --text="${MSG}" \
--title="${MSG}" &
SPID=$!

while true
do

if test `ps --pid ${SPID}|wc -l` -le 1; then
break
fi

xdotool search --name "${TITLE}" windowactivate
if test $? -eq 0 && $FLG; then
xdotool getactivewindow windowmove 0 0
FLG=false
fi

xdotool search --name "${TITLE}" key "Return"
if test $? -ne 0; then
kill ${SPID} 2>/dev/null
break
fi

sleep 1
done

将脚本下载到任意位置(因为以后也不会直接运行这个脚本,Manjaro下直接在Terminal运行这个脚本的话,Terminal会不停地变成最前面的窗口,这还怎么看视频?),并为这个脚本创建launcher。

Create *.desktop file, location depends on if it is for personal use or all users. If these directories do not exist, create them.

For personal use, ~/.local/share/applications

1
gedit ~/.local/share/applications/subtitler.desktop

然后编辑该文件,贴上以下内容:

1
2
3
4
5
6
7
8
9
10
11
12
[Desktop Entry]
Categories=AudioVideo;Player;Recorder;
Comment=Use with Subtitler (lite) mod. Keep pressing the [Refresh] button in the dialog box.
Exec=~/Desktop/subtitler-keeping-press-enter.sh
GenericName=Use with Subtitler (lite) mod. Keep pressing the [Refresh] button in the dialog box.
Icon=map-globe
Keywords=Player;Subtitle;
Name=Subtitler Press
StartupNotify=true
Terminal=false
Type=Application
Version=1.0

Edit Icon= and Exec=
Exec填上刚刚脚本下载到的路径;Icon嘛,有兴趣的话选上自己喜欢的Icon,其实也可以不填。

至此,大功告成!

然后就可以愉快的打开视频,在VLC内选好第一条与视频文件名不一样的字幕,打开Subtitler lite mod,再打开刚才创建的launcher,再次愉快的看视频了(原谅吾辈的辞藻匮乏,用了两次愉快……)

Reference

  1. A shell script for Subtitler (lite) mod (VLC 2.1+ extention)
  2. How to add a shell script to launcher as shortcut