-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenerateGameHighlights.sh
executable file
·122 lines (106 loc) · 4.44 KB
/
GenerateGameHighlights.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/sh
#================================================================================
# AUTHOR
# Clint Box
# https://www.youtube.com/bearcatjamboree
#
# FUNCTION
# Implement audio jump cut against a folder of mp4 files to generate a single
# game highlights video
#
# DETAILS
# This script loop through a folder of mp4 files and execute Jumpcutter using
# the audio jump cut method. After execution of loop, all outputs will be
# merged into a single highlights video.
#
# USAGE
# ${SCRIPT_NAME} "<path to input *.mp4>" "<output folder>"
#================================================================================
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
CYGWIN*) machine=Cygwin;;
MINGW*) machine=MinGw;;
*) machine="UNKNOWN:${unameOut}"
esac
echo "${machine}"
input_folder="$1"
output_folder="$2"
##############################################################################
# Prompt for input folder
###############################################################################
if ! [ -d "$input_folder" ]; then
if [[ "$machine" == "Mac" ]]; then
input_folder=$(osascript -e 'tell application (path to frontmost application as text)
set input_folder to choose folder with prompt "Please choose an input folder"
POSIX path of input_folder
end')
elif [[ "$machine" == "Linux" ]]; then
input_folder=$(dialog --title "Choose a folder" --stdout --title "Please choose an input folder" --fselect ~/ 14 48)
elif [[ "$machine" == "Cygwin" ]]; then
input_folder=$(dialog --title "Choose a folder" --stdout --title "Please choose an input folder" --fselect ~/ 14 48)
else
echo "Usage: $0 input_file input_folder format"
exit 1
fi
fi
if ! [ -d "$input_folder" ]; then
echo "Usage: $0 input_folder output_folder"
exit 1
fi
# Remove trailing slash for path
input_folder="${input_folder%/}"
##############################################################################
# Prompt for output folder
###############################################################################
if ! [ -d "$output_folder" ]; then
if [[ "$machine" == "Mac" ]]; then
output_folder=$(osascript -e 'tell application (path to frontmost application as text)
set output_folder to choose folder with prompt "Please choose an output folder"
POSIX path of output_folder
end')
elif [[ "$machine" == "Linux" ]]; then
output_folder=$(dialog --title "Choose a folder" --stdout --title "Please choose an output folder" --fselect ~/ 14 48)
elif [[ "$machine" == "Cygwin" ]]; then
output_folder=$(dialog --title "Choose a folder" --stdout --title "Please choose an output folder" --fselect ~/ 14 48)
else
echo "Usage: $0 input_file output_folder format"
exit 1
fi
fi
if ! [ -d "$output_folder" ]; then
echo "Usage: $0 input_folder output_folder"
exit 1
fi
# Remove trailing slash for path
output_folder="${output_folder%/}"
###################################
# Process each input folder file
###################################
for filename in $input_folder/*.*; do
# Get filiename pieces
file="${filename##*/}"
ext="${file##*.}"
name=""${file%.*}"_highlights"
# Construct output file name
output_name="$output_folder/$name.$ext"
python VideoJumpcutter.py --input_file "$filename" --output_file "$output_name" --audio_method 1 --volume_selection "max" --audio_threshold 0.90 --frame_margin 600
done
# Make temp directory
tmp_dir=$(mktemp -d -t ci-$(date +%Y-%m-%d-%H-%M-%S)-XXXXXXXXXX)
###########################################################################
# Standardize the audio frequence and then build list of videos to combine
###########################################################################
for filename in $output_folder/*_highlights.*; do
file="${filename##*/}"
ffmpeg -i $filename -af "aformat=sample_rates=48000" -c:v copy $output_folder/fix_$file
mv $output_folder/fix_$file $output_folder/$file
echo "file '$output_folder/$file'" >> $tmp_dir/file_list.txt;
done
###########################################################################
# Combine output files into one video
###########################################################################
ffmpeg -loglevel error -f concat -safe 0 -i $tmp_dir/file_list.txt -c copy "$output_folder/Highlights.$ext"
# Cleanup
rm -rf $tmp_dir