-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse-subs.sh
37 lines (33 loc) · 1.09 KB
/
parse-subs.sh
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
31
32
33
34
35
36
37
#!/bin/bash
pubdir="web/public/presentation/$2"
echo "Parsing Subtitles from source"
index="-1"
streamtype="na"
NL=$'\n'
subtitlesFile="$pubdir/subtitles.txt"
rm $subtitlesFile
ffprobe -loglevel fatal -show_streams "$1" > mediainfo.txt
while read line; do
if echo "$line" | grep -q "index="; then
index=`echo "$line" | grep --only-matching "[0-9]"`;
fi
if echo "$line" | grep -q "codec_type="; then
streamtype=`echo "$line" | sed -n -e 's/^.*codec_type=//p'`
fi
if echo "$line" | grep -q "TAG:language="; then
sublang=`echo "$line" | sed -n -e 's/^.*TAG:language=//p'`
fi
if echo "$line" | grep -q "\[/STREAM\]"; then
echo "Track $index is $streamtype and language is $sublang"
if [[ $streamtype = "subtitle" ]]; then
#submaps="$submaps -map 0:$index"
echo "stream_subtitles_${index}.vtt=${sublang}" >> $subtitlesFile
echo "extracting $sublang subtitles..."
ffmpeg -nostats -loglevel error -i "$1" -map "0:$index" -y "$pubdir/stream_subtitles_$index.vtt"
fi
index="-1"
streamtype="na"
sublang="na"
fi
done <mediainfo.txt
rm mediainfo.txt