-
Notifications
You must be signed in to change notification settings - Fork 0
/
addsubs.sh
executable file
·77 lines (64 loc) · 1.63 KB
/
addsubs.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
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
67
68
69
70
71
#!/bin/bash
confirm () {
read -r -p "${1:-Are you sure you want to continue? [Y/n]} " response </dev/tty
case $response in
[yY][eE][sS]|[yY]|"")
true
;;
*)
false
;;
esac
}
usage () {
echo "Usage: "
echo " addsubs [video file] [subs file] [output file]"
echo "NOTE: only mkv and mp4 files are supported."
echo " The output filetype must be the same as the input filetype"
exit
}
function cleanup {
exit
}
trap cleanup SIGHUP SIGINT SIGKILL SIGTERM SIGSTOP
for i in "$@"; do
case $i in
# -f=*|--format=*)
# f="${i#*=}"
# shift # past argument=value
# ;;
-h=*|--help=*)
usage
shift # past argument=value
;;
esac
done
vidfile="$1"
subs="$2"
output="$3"
filetype="$(sed 's/.*\(\....\).*/\1/'<<<$vidfile)"
echo $vidfile $subs $output $filetype
# if [ -z "$f" ]; then
# echo "You must specify a type using -f=[type]";
if [ -z "$vidfile" ] || [ -z "$subs" ] || [ -z "$output" ]; then
echo "You must specify a video file, a subtitles file, and an output file."
usage
elif [ "$vidfile" = "$output" ]; then
echo "You must use a different filename for the output file!"
elif [ "$filetype" = ".mkv" ]; then
echo "You are adding"
echo " $subs to"
echo " $vidfile,"
echo " and outputting to"
echo " $output."
confirm &&
ffmpeg -i "$vidfile" -f srt -i "$subs" \
-map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy \
-c:s srt "$output"
elif [ "$filetype" = ".mp4" ]; then
ffmpeg -i "$vidfile" -f srt -i "$subs" \
-map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy \
-c:s mov_text "$output"
else
echo "something went wrong"
fi