-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert-background.sh
84 lines (70 loc) · 2.39 KB
/
convert-background.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
82
83
84
#!/bin/bash
set -e
teams_v1_path="$HOME/Library/Application Support/Microsoft/Teams/Backgrounds/Uploads"
teams_v2_path="$HOME/Library/Containers/com.microsoft.teams2/Data/Library/Application Support/Microsoft/MSTeams/Backgrounds/Uploads"
if [[ -d "${teams_v1_path}" ]]; then
export target_dir="${teams_v1_path}"
fi
if [[ -d "${teams_v2_path}" ]]; then
export target_dir="${teams_v2_path}"
fi
echo "Teams directory: ${target_dir}"
BOLD=$(tput bold)
NORMAL=$(tput sgr0)
input=$1
bg_uuid=$(uuidgen | tr "[:upper:]" "[:lower:]")
check_if_ffmpeg_is_installed () {
if [[ ! $(which ffmpeg) ]]; then
echo "You don't have the ffmpeg converter installed!"
read -p "Do you want ffmpeg automatically installed using brew? [y/n]: " brew_install_ffmpeg
if [[ ${brew_install_ffmpeg} == "y" ]]; then
echo "Installing ffmpeg. This may take a while..."
brew install ffmpeg --quiet
else
echo "You need ffmpeg installed to convert the video! Exiting now!"
exit 1
fi
fi
}
information_before_installation () {
echo "${BOLD}Convert Background:${NORMAL}"
echo "Input File: $input"
}
convert_mp4_to_gif () {
echo "Convert video to gif..."
ffmpeg -i "$input" -loop 0 -f gif "$bg_uuid.png" > /dev/null 2>&1
}
extract_thumbnail_from_gif () {
echo "Extract thumbnail..."
ffmpeg -i "$bg_uuid.png" -vf "select=eq(n\,0)" -vframes 1 "${bg_uuid}_thumb.png" > /dev/null 2>&1
}
move_gif_files_to_teams_folder () {
mv ${bg_uuid}*.png "${target_dir}"
}
information_after_installation () {
echo "Background File: $bg_uuid.png"
echo "Thumbnail File: ${bg_uuid}_thumb.png"
}
install_instructions () {
display_name=$1
echo ""
echo "${BOLD}Manual installation:${NORMAL}"
echo "Copy all generated files into the backgrounds folder of your Teams installation."
echo "If a terams installation is detected, there are automatic instructions below."
echo ""
echo "${BOLD}$display_name:${NORMAL}"
echo "cp ${bg_uuid}*.png \"$target_dir/\""
}
information_before_installation
check_if_ffmpeg_is_installed
convert_mp4_to_gif
extract_thumbnail_from_gif
information_after_installation
read -p "Do you want that your gif is moved automatically into the teams folder? [y/n]: " direct_move
if [[ ${direct_move} == "y" ]]; then
echo "Moving gif to teams backgrounds folder..."
move_gif_files_to_teams_folder
exit 0
fi
install_instructions "Teams v1 on macOS"
install_instructions "Teams v2 on macOS"