-
Notifications
You must be signed in to change notification settings - Fork 0
/
gentile.sh
executable file
·52 lines (40 loc) · 1.29 KB
/
gentile.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
#!/bin/bash
anime_path=/mnt/data/anime/
thumb_path=/mnt/data/anime_thumb/
tmp_path="/tmp/thumb/${1//$anime_path/}/"
if [[ "$1" == "$anime_path"*.mp4 ]] ; then
relative_path="${1//$anime_path/}"
else
echo "Invalid input file"
exit
fi
file="$1"
thumbxxx="${file%.mp4}.jpg"
thumbfile="${thumbxxx//$anime_path/$thumb_path}"
thumbpath=$(dirname "$thumbfile")
echo "${file}"
if [ ! -f "$thumbfile" ] || [ "$2" == "-f" ]; then
# Froce remove old temp folder (e.g. due to unclean exit)
if [[ -d $tmp_path ]] && [ "$3" == "-f" ]; then
echo Removing old files
rm -rf "${tmp_path}"
elif [[ -d $tmp_path ]] ; then
echo "Another process is working on this file, exiting"
exit
fi
echo Creating temp directory
mkdir -p "${tmp_path}" || exit
echo Counting total frames
total_frame=$(ffmpeg -i "$file" -map 0:v:0 -c copy -f null -y /dev/null 2>&1 | grep -Eo 'frame= *[0-9]+ *' | grep -Eo '[0-9]+' | tail -1)
echo $total_frame
echo Calculating n
n=$(expr $total_frame / 144 + 1)
echo $n
echo Creating output directory
mkdir -p "$thumbpath"
echo Generating thumbnail map
ffmpeg -threads 2 -y -ss 00:00:00 -i "$file" -frames 1 -vf "select=not(mod(n\,"$n")),scale=160:90,tile=12x12" -qscale:v 2 "$thumbfile"
echo Removing temp files
rm -rf "${tmp_path}"
echo Completed
fi