-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert-jponly
executable file
·66 lines (53 loc) · 1.79 KB
/
convert-jponly
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
[ ! -d out ] && mkdir out
case $1 in
"--auto")
MODE="auto"
shift
;;
esac
audio_default=$(ffmpeg -i "$1" 2>&1 | grep "(jpn): Audio" | cut -d':' -f 2 | cut -d '(' -f 1)
# here be dragons
sub_default=$(ffmpeg -i "$1" 2>&1 | \
grep -A 2 --group-separator='~' "(\(eng\|enm\)): Subtitle" | \
tr '~' '\0' | \
grep -z -v Signs | grep -z -v Songs | grep -z -v S\&S | \
grep -a "(\(eng\|enm\)): Subtitle" | \
cut -d':' -f 2 | cut -d'(' -f 1 | \
tr '\n' ',' | sed 's|,$|\n|')
echo -n "$sub_default" | od -x
if [ -z "$sub_default" ]; then
echo "no eng subs found. checking if file uses broken language tags"
sub_default=$(ffmpeg -i "$1" 2>&1 | \
grep -A 2 --group-separator='~' "(jpn): Subtitle" | \
tr '~' '\0' | \
grep -z -v Signs | grep -z -v Songs | grep -z -v S\&S | \
grep -a "(jpn): Subtitle" | \
cut -d':' -f 2 | cut -d'(' -f 1 | \
tr '\n' ',' | sed 's|,$|\n|')
fi
if [ "$MODE" == "auto" ]; then
audio=$audio_default
sub=$sub_default
if [ -z "$audio" ] || [ -z "$sub" ]; then
echo "Auto mode failed, exiting"
exit 1
fi
else
ffmpeg -i "$1" 2>&1 | grep -A2 '\(Video\|Audio\|Subtitle\)'
echo -ne "JPN audio track(${audio_default}): "
read -r audio
[ -z "$audio" ] && audio=$audio_default
echo -ne "ENG sub track(${sub_default}): "
read -r sub
[ -z "$sub" ] && sub=$sub_default
fi
# for multiple sub tracks
subflag="-map 0:${sub//,/ -map 0:}"
ffmpeg -i "$1" -c copy \
-map 0:v -map 0:$audio $subflag -map 0:d? -map 0:t? \
-disposition:s:0 default -disposition:a:0 default -metadata:s:s:0 language=en -metadata:s:a:0 language=jpn \
out/tmp.mkv
# mkvmerge makes smaller files somehow?
mkvmerge -o out/"$1" out/tmp.mkv
rm out/tmp.mkv