Мой видеоплеер не поддерживает формат .ass, поэтому мне нужно извлечь субтитры .ass и преобразовать их в формат .srt. .
И, конечно, я хочу сделать это с помощью сценария.
Это то, что я сделал на данный момент (по большей части это сценарий, который я нашел где-то еще и настроил для моих нужд).
Код: Выделить всё
#!/bin/bash
# Convert subtitles from each MKV file in the given directory from .ass to .srt
# If no directory is given, work in local dir
if [ "$1" = "" ]; then
DIR="."
else
DIR="$1"
fi
echo "Directory $DIR"
# Get all the MKV files in this dir and its subdirs
find "$DIR" -type f -name '*.mkv' | sort | while read filename
do
# Get base name for subtitle
subtitlename=${filename%.*}
# Skip processed files
if [ -e "$subtitlename.srt" ]; then
echo "Skipping $filename"
continue
fi
# If no tracknumber is given, find out which tracks contain the subtitles
if [ "$2" = "" ]; then
TN=`mkvmerge -i "$filename" | grep 'subtitles' | head -1 | egrep -o "[0-9]{1,2}"`
else
TN="$2"
fi
# Extract the track to a .ass file and convert to a .srt file
echo "Processing $filename"
mkvextract tracks "$filename" $TN:"$subtitlename.ass" && \
ffmpeg -i "$subtitlename.ass" "$subtitlename.srt" && \
rm "$subtitlename.ass"
done
Это соответствующая часть журнала:
Код: Выделить всё
Processing ./S01E01.mkv
Processing /S01E02.mkv
Error: (mkvextract) This file could not be opened or parsed.
Processing ./S01E03.mkv
Processing /S01E04.mkv
Error: (mkvextract) This file could not be opened or parsed.
Почему это происходит?
Подробнее здесь: https://stackoverflow.com/questions/782 ... t-filename