-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecord.sh
More file actions
executable file
·197 lines (174 loc) · 5.2 KB
/
record.sh
File metadata and controls
executable file
·197 lines (174 loc) · 5.2 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
# Batch recording script for Advanced Sorting Algorithm Visualizer
echo "🎬 Advanced Sorting Algorithm Visualizer - Recording Script"
echo "======================== 10)
echo "👋 Goodbye!"
break
;;
*)
echo "❌ Invalid choice. Please enter 1-10."
;;============================"
echo
# Check if Python is available
if ! command -v python3 &> /dev/null; then
echo "❌ Python 3 is not installed or not in PATH"
exit 1
fi
# Check if demo.py exists
if [ ! -f "demo.py" ]; then
echo "❌ demo.py not found. Please run this script from the project directory."
exit 1
fi
# Function to show menu
show_menu() {
echo "Please choose an option:"
echo "1. Run demo without recording"
echo "2. Run demo in EXPRESS mode (ultra-fast)"
echo "3. Record frames only"
echo "4. Record frames and create GIFs"
echo "5. Express mode with recording"
echo "6. Show recording help"
echo "7. Create videos from existing recordings (requires ffmpeg)"
echo "8. Fix existing GIFs (repair corrupted GIFs)"
echo "9. Clean up recordings folder"
echo "10. Exit"
echo
}
# Function to fix GIFs
fix_gifs() {
if [ ! -f "fix_gifs.py" ]; then
echo "❌ fix_gifs.py not found"
return 1
fi
echo "🔧 Fixing existing GIFs..."
python3 fix_gifs.py --fix-all
if [ $? -eq 0 ]; then
echo "✅ GIF fixing completed!"
else
echo "❌ GIF fixing failed!"
fi
}
# Function to create videos
create_videos() {
if ! command -v ffmpeg &> /dev/null; then
echo "❌ ffmpeg is not installed. Please install it first:"
echo " macOS: brew install ffmpeg"
echo " Ubuntu: sudo apt install ffmpeg"
echo " Windows: Download from https://ffmpeg.org/"
return 1
fi
if [ ! -d "recordings" ]; then
echo "❌ No recordings folder found. Please record demos first."
return 1
fi
echo "🎥 Creating videos from recordings..."
for dir in recordings/*/; do
if [ -d "$dir" ]; then
name=$(basename "$dir")
echo "Creating video for $name..."
# Check if frames exist
if ls "$dir"frame_*.png 1> /dev/null 2>&1; then
ffmpeg -y -framerate 30 -i "$dir/frame_%06d.png" \
-c:v libx264 -pix_fmt yuv420p \
-crf 23 "${name}.mp4" 2>/dev/null
if [ $? -eq 0 ]; then
echo "✅ ${name}.mp4 created successfully"
else
echo "❌ Failed to create ${name}.mp4"
fi
else
echo "❌ No frames found in $dir"
fi
fi
done
echo "🎉 Video creation completed!"
}
# Function to clean up recordings
cleanup_recordings() {
echo "🧹 Cleaning up recordings..."
if [ -d "recordings" ]; then
read -p "Are you sure you want to delete all recordings? (y/N): " confirm
if [[ $confirm =~ ^[Yy]$ ]]; then
rm -rf recordings/
echo "✅ Recordings folder deleted"
else
echo "❌ Cleanup cancelled"
fi
else
echo "ℹ️ No recordings folder found"
fi
}
# Function to install dependencies
install_dependencies() {
echo "📦 Installing dependencies..."
if [ -f "requirements.txt" ]; then
python3 -m pip install -r requirements.txt
echo "✅ Dependencies installed"
else
echo "❌ requirements.txt not found"
return 1
fi
}
# Check dependencies
echo "🔍 Checking dependencies..."
if ! python3 -c "import pygame" 2>/dev/null; then
echo "❌ pygame not found. Installing dependencies..."
install_dependencies
fi
if ! python3 -c "from PIL import Image" 2>/dev/null; then
echo "⚠️ Pillow not found. GIF creation will not work."
echo "📦 Installing Pillow..."
python3 -m pip install Pillow
fi
# Main loop
while true; do
show_menu
read -p "Enter your choice (1-10): " choice
echo
case $choice in
1)
echo "🎯 Running demo without recording..."
python3 demo.py
;;
2)
echo "⚡ Running EXPRESS mode demo..."
python3 demo.py --express
;;
3)
echo "🎬 Recording frames during demo..."
python3 demo.py --record
;;
4)
echo "🎬 Recording frames and creating GIFs..."
python3 demo.py --record --gif
;;
5)
echo "⚡ Express mode with recording..."
python3 demo.py --express --record
;;
6)
echo "📖 Showing recording help..."
python3 demo.py --help-recording
;;
7)
create_videos
;;
8)
fix_gifs
;;
9)
cleanup_recordings
;;
10)
echo "👋 Goodbye!"
break
;;
*)
echo "❌ Invalid choice. Please enter 1-8."
;;
esac
echo
echo "Press Enter to continue..."
read
echo
done