linux下的mplayer只能加载一个字幕,看The Big Bang Theory时不爽.看到网上说使用 cat subtitle_1.srt subtitle_2.srt > newsubtitle.srt 的方法即可合并字幕,使mplayer显示两个字幕.当然还要加上 "-overlapsub" 参数.
但是对每个字幕都这样cat一下,还是有些麻烦的,所以写这个perl脚本,自动合并中英文字幕.我下载的mkv版带的外挂字幕,英文字幕文件以en.srt结尾,中文字幕以gb.srt或者ch.srt结尾.使用perl将两个文件合并成.srt结尾的字幕.当然使用shell处理更简单,但是shell不怎么用,忘了...
#!/usr/bin/perl # use strict; my $dir = \'.\'; opendir DIR, $dir or die "Can not open $dir: $!"; foreach my $filename (readdir DIR){ next unless $filename =~ /(.*).en.srt$/; my $name = $1; print LOG $1."n"; open ENSUB, "<", $filename or die "Can not open $filename: $!"; open NEWSUB, ">","$name.srt"; while (<ENSUB>){ print NEWSUB $_; } open CNSUB, "<", "$name.gb.srt" or open CNSUB, "<", "$name.ch.srt" or die "Can not open $name.gb.srt: $!"; while (<CNSUB>){ print NEWSUB $_; } open LOG, ">", "LOG.LOG"; }另外,如果mplayer不能正确识别字幕编码,可以使用" -subcp enca:zh:CP936 " 参数. 如果是Gnome Mplayer,可以在Preferences - MPlayer - Extra Options to MPlayer 添加以上参数.