-
Notifications
You must be signed in to change notification settings - Fork 0
/
danmakuBurning.sh
executable file
·81 lines (66 loc) · 2.49 KB
/
danmakuBurning.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
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
# DESCRIPTION:
# The script mainly burns danmaku into new video and delete original files, along with starting video uploading.
#
# PARAMETERS:
# INPUT:
# $1 - the full path of the video
# OUTPUT:
# $formatVideoName - eg:/path/to/video/roomid_YYYY-MM-DD-HH.mp4
while read key value; do
export $key="$value"
done < ./path.txt
# check if the filename is provided.
if [ $# -ne 1 ]; then
echo "Usage: $0 filename"
exit 1
fi
# obtain full path
fullPath=$1
# delete json files
filenameWithoutExt="${fullPath%.*}"
jsonlPath="${filenameWithoutExt}.jsonl"
rm $jsonlPath
# use dirname to obtain the path,along with basename to obtain filename.
path=$(dirname "$fullPath")
filename=$(basename "$fullPath")
# extract the extonsion name.
extension="${filename##*.}"
roomid=$(echo "$filename" | cut -d'_' -f1)
timestamp=$(echo "$filename" | cut -d'_' -f2)
# retrieve parameters.
year=${timestamp:0:4}
month=${timestamp:4:2}
day=${timestamp:6:2}
hour=${timestamp:9:2}
# format the file name
formatVideoName="${path}/${roomid}_${year}-${month}-${day}-${hour}.${extension}"
# generate the converted subtitle file name
assPath="${path}/${roomid}_${year}-${month}-${day}-${hour}.ass"
# use DanmakuFactory to convert the xml file
xmlPath="${filenameWithoutExt}.xml"
if [ -f "$xmlPath" ]; then
$rootPath/DanmakuFactory -o "$assPath" -i "$xmlPath" --ignore-warnings
rm $xmlPath
echo “danmaku convert success!”
export ASS_PATH="$assPath"
python3 $rootPath/removeEmojis.py >> $rootPath/logs/removeEmojis.log 2>&1
fi
# Burn danmaku into video.
if [ -f "$assPath" ]; then
# The only cpu version
# ffmpeg -y -i $fullPath -vf ass=$assPath -preset ultrafast $formatVideoName > $rootPath/logs/burningLog/burn-$(date +%Y%m%d%H%M%S).log 2>&1
# The Nvidia GPU accelerating version
ffmpeg -y -hwaccel cuda -c:v h264_cuvid -i $fullPath -c:v h264_nvenc -vf ass=$assPath $formatVideoName > $rootPath/logs/burningLog/burn-$(date +%Y%m%d%H%M%S).log 2>&1
rm $assPath
else
# The only cpu version
# ffmpeg -y -i $fullPath -vf -preset ultrafast $formatVideoName > $rootPath/logs/burningLog/burn-$(date +%Y%m%d%H%M%S).log 2>&1
# The Nvidia GPU acceleting version
ffmpeg -y -hwaccel cuda -c:v h264_cuvid -i $fullPath -c:v h264_nvenc $formatVideoName > $rootPath/logs/burningLog/burn-$(date +%Y%m%d%H%M%S).log 2>&1
fi
echo "ffmpeg successfully complete!"
# Delete the original video.
rm $fullPath
# Upload video.
echo "$formatVideoName" >> $rootPath/uploadVideoQueue.txt