问题在于Ubuntu中的视频播放器在集成中欧字幕时存在问题,解决方案是提取字幕。有谁知道终端中是否有命令或程序从mkv文件中提取字幕?
问题在于Ubuntu中的视频播放器在集成中欧字幕时存在问题,解决方案是提取字幕。有谁知道终端中是否有命令或程序从mkv文件中提取字幕?
Answers:
安装mkvtoolnix
使用sudo apt-get install mkvtoolnix
。
从终端运行: mkvextract tracks <your_mkv_video> <track_numer>:<subtitle_file.srt>
使用mkvinfo
以获取有关轨道的信息。
使用此实用程序,您可以提取任何轨道,甚至音频或视频。
您可以使用mkvtoolnix。
sudo apt-get install mkvtoolnix
现在的另一个技巧是,由于mkv文件可能包含许多字幕,因此该技巧是您可以搜索所需语言的脚本,例如,如果要使用英语,它将仅下载英语。
剧本:
#!/bin/bash
# Extract subtitles from each MKV file in the given directory
# If no directory is given, work in local dir
if [ "$1" = "" ]; then
DIR="."
else
DIR="$1"
fi
# Get all the MKV files in this dir and its subdirs
find "$DIR" -type f -name '*.mkv' | while read filename
do
# Find out which tracks contain the subtitles
mkvmerge -i "$filename" | grep 'subtitles' | while read subline
do
# Grep the number of the subtitle track
tracknumber=`echo $subline | egrep -o "[0-9]{1,2}" | head -1`
# Get base name for subtitle
subtitlename=${filename%.*}
# Extract the track to a .tmp file
`mkvextract tracks "$filename" $tracknumber:"$subtitlename.srt.tmp" > /dev/null 2>&1`
`chmod g+rw "$subtitlename.srt.tmp"`
# Do a super-primitive language guess: ENGLISH
langtest=`egrep -ic ' you | to | the ' "$subtitlename".srt.tmp`
trimregex=""
# Check if subtitle passes our language filter (10 or more matches)
if [ $langtest -ge 10 ]; then
# Regex to remove credits at the end of subtitles (read my reason why!)
`sed 's/\r//g' < "$subtitlename.srt.tmp" \
| sed 's/%/%%/g' \
| awk '{if (a){printf("\t")};printf $0; a=1; } /^$/{print ""; a=0;}' \
| grep -iv "$trimregex" \
| sed 's/\t/\r\n/g' > "$subtitlename.srt"`
`rm "$subtitlename.srt.tmp"`
`chmod g+rw "$subtitlename.srt"`
else
# Not our desired language: add a number to the filename and keep anyway, just in case
`mv "$subtitlename.srt.tmp" "$subtitlename.$tracknumber.srt" > /dev/null 2>&1`
fi
done
done
保存此脚本名称youwant.sh并使其可执行
现在在终端中将目录更改为脚本文件夹并写入
./nameyouwant.sh /pathtosave
mkvinfo
“ Track number:2(mkvmerge&mkvextract:1的轨道ID)”之类的令人困惑的东西。使用mkvmerge -i <filename>