Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ import os
|
|
11 |
import numpy as np
|
12 |
from io import BytesIO
|
13 |
|
14 |
-
# Initialize session state
|
15 |
if 'file_history' not in st.session_state:
|
16 |
st.session_state['file_history'] = []
|
17 |
if 'ping_code' not in st.session_state:
|
@@ -19,7 +19,7 @@ if 'ping_code' not in st.session_state:
|
|
19 |
if 'uploaded_files' not in st.session_state:
|
20 |
st.session_state['uploaded_files'] = []
|
21 |
|
22 |
-
#
|
23 |
def save_to_history(file_type, file_path):
|
24 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
25 |
st.session_state['file_history'].append({
|
@@ -28,69 +28,66 @@ def save_to_history(file_type, file_path):
|
|
28 |
"Path": file_path
|
29 |
})
|
30 |
|
31 |
-
#
|
32 |
-
st.
|
33 |
-
library_choice = st.sidebar.selectbox(
|
34 |
-
"Select Library",
|
35 |
-
["OpenCV", "PyAudio", "ImageIO", "PyAV", "MoviePy"]
|
36 |
-
)
|
37 |
-
resolution = st.sidebar.select_slider(
|
38 |
-
"Resolution",
|
39 |
-
options=["320x240", "640x480", "1280x720"],
|
40 |
-
value="640x480"
|
41 |
-
)
|
42 |
-
fps = st.sidebar.slider("FPS", 1, 60, 30)
|
43 |
|
44 |
-
#
|
45 |
-
st.sidebar
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
digit2 = st.selectbox("D2", [str(i) for i in range(10)], key="d2")
|
51 |
-
with col3:
|
52 |
-
digit3 = st.selectbox("D3", [str(i) for i in range(10)], key="d3")
|
53 |
-
with col4:
|
54 |
-
digit4 = st.selectbox("D4", [str(i) for i in range(10)], key="d4")
|
55 |
-
ping_code = digit1 + digit2 + digit3 + digit4
|
56 |
-
st.session_state['ping_code'] = ping_code
|
57 |
-
st.sidebar.write(f"Ping Code: {ping_code}")
|
58 |
|
59 |
-
#
|
60 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
-
#
|
63 |
-
st.header("
|
64 |
|
65 |
-
# 1. OpenCV
|
66 |
-
with st.expander("1
|
67 |
-
st.write("π₯
|
68 |
-
st.subheader("Top
|
69 |
|
70 |
-
st.write("
|
71 |
-
if st.button("
|
|
|
72 |
cap = cv2.VideoCapture(0)
|
73 |
frame_placeholder = st.empty()
|
74 |
-
for _ in range(50):
|
75 |
ret, frame = cap.read()
|
76 |
if ret:
|
77 |
frame_placeholder.image(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
|
78 |
cap.release()
|
79 |
|
80 |
-
st.write("
|
81 |
-
if st.button("
|
|
|
82 |
cap = cv2.VideoCapture(0)
|
83 |
ret, frame = cap.read()
|
84 |
if ret:
|
85 |
-
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
86 |
file_path = f"opencv_gray_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg"
|
87 |
cv2.imwrite(file_path, gray)
|
88 |
save_to_history("Image", file_path)
|
89 |
-
st.image(file_path, caption="
|
90 |
cap.release()
|
91 |
|
92 |
-
st.write("
|
93 |
-
if st.button("
|
|
|
94 |
cap = cv2.VideoCapture(0)
|
95 |
ret, frame = cap.read()
|
96 |
if ret:
|
@@ -98,19 +95,20 @@ with st.expander("1. π· OpenCV"):
|
|
98 |
file_path = f"opencv_edges_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg"
|
99 |
cv2.imwrite(file_path, edges)
|
100 |
save_to_history("Image", file_path)
|
101 |
-
st.image(file_path, caption="Edge
|
102 |
cap.release()
|
103 |
|
104 |
-
# 2. PyAudio
|
105 |
-
with st.expander("2
|
106 |
-
st.write("π
|
107 |
-
st.subheader("Top
|
108 |
|
109 |
-
st.write("
|
110 |
-
if st.button("
|
|
|
111 |
p = pyaudio.PyAudio()
|
112 |
stream = p.open(format=pyaudio.paInt16, channels=1, rate=44100, input=True, frames_per_buffer=1024)
|
113 |
-
frames = [stream.read(1024) for _ in range(int(44100 / 1024 * 3))]
|
114 |
stream.stop_stream()
|
115 |
stream.close()
|
116 |
p.terminate()
|
@@ -123,30 +121,33 @@ with st.expander("2. ποΈ PyAudio"):
|
|
123 |
save_to_history("Audio", file_path)
|
124 |
st.audio(file_path)
|
125 |
|
126 |
-
st.write("
|
127 |
-
if st.button("
|
|
|
128 |
p = pyaudio.PyAudio()
|
129 |
devices = [p.get_device_info_by_index(i) for i in range(p.get_device_count())]
|
130 |
-
st.write("
|
131 |
p.terminate()
|
132 |
|
133 |
-
st.write("
|
134 |
-
if st.button("
|
|
|
135 |
p = pyaudio.PyAudio()
|
136 |
stream = p.open(format=pyaudio.paInt16, channels=1, rate=44100, input=True, frames_per_buffer=1024)
|
137 |
data = stream.read(1024)
|
138 |
-
st.write("
|
139 |
stream.stop_stream()
|
140 |
stream.close()
|
141 |
p.terminate()
|
142 |
|
143 |
-
# 3. ImageIO
|
144 |
-
with st.expander("3
|
145 |
-
st.write("π₯
|
146 |
-
st.subheader("Top
|
147 |
|
148 |
-
st.write("
|
149 |
-
if st.button("
|
|
|
150 |
reader = imageio.get_reader('<video0>')
|
151 |
frame = reader.get_next_data()
|
152 |
file_path = f"imageio_frame_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg"
|
@@ -154,31 +155,34 @@ with st.expander("3. πΉ ImageIO"):
|
|
154 |
save_to_history("Image", file_path)
|
155 |
st.image(file_path)
|
156 |
|
157 |
-
st.write("
|
158 |
-
if st.button("
|
|
|
159 |
reader = imageio.get_reader('<video0>')
|
160 |
frame = reader.get_next_data()
|
161 |
file_path = f"imageio_comp_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg"
|
162 |
-
imageio.imwrite(file_path, frame, quality=85)
|
163 |
save_to_history("Image", file_path)
|
164 |
-
st.image(file_path, caption="
|
165 |
|
166 |
-
st.write("
|
167 |
-
if st.button("
|
|
|
168 |
reader = imageio.get_reader('<video0>')
|
169 |
frames = [reader.get_next_data() for _ in range(10)]
|
170 |
file_path = f"imageio_gif_{datetime.now().strftime('%Y%m%d_%H%M%S')}.gif"
|
171 |
imageio.mimwrite(file_path, frames, fps=5)
|
172 |
save_to_history("GIF", file_path)
|
173 |
-
st.image(file_path, caption="GIF")
|
174 |
|
175 |
-
# 4. PyAV
|
176 |
-
with st.expander("4
|
177 |
-
st.write("π₯
|
178 |
-
st.subheader("Top
|
179 |
|
180 |
-
st.write("
|
181 |
-
if st.button("
|
|
|
182 |
container = av.open('/dev/video0')
|
183 |
stream = container.streams.video[0]
|
184 |
file_path = f"pyav_vid_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"
|
@@ -193,8 +197,9 @@ with st.expander("4. π¬ PyAV"):
|
|
193 |
save_to_history("Video", file_path)
|
194 |
st.video(file_path)
|
195 |
|
196 |
-
st.write("
|
197 |
-
if st.button("
|
|
|
198 |
container = av.open('/dev/video0', 'r', format='v4l2')
|
199 |
file_path = f"pyav_audio_{datetime.now().strftime('%Y%m%d_%H%M%S')}.wav"
|
200 |
output = av.open(file_path, 'w')
|
@@ -204,21 +209,22 @@ with st.expander("4. π¬ PyAV"):
|
|
204 |
if frame.is_corrupt: continue
|
205 |
if hasattr(frame, 'to_ndarray'):
|
206 |
output.mux(out_stream.encode(frame))
|
207 |
-
if os.path.getsize(file_path) > 100000: break
|
208 |
output.close()
|
209 |
container.close()
|
210 |
save_to_history("Audio", file_path)
|
211 |
st.audio(file_path)
|
212 |
|
213 |
-
st.write("
|
214 |
-
if st.button("
|
|
|
215 |
container = av.open('/dev/video0')
|
216 |
stream = container.streams.video[0]
|
217 |
file_path = f"pyav_filter_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"
|
218 |
output = av.open(file_path, 'w')
|
219 |
out_stream = output.add_stream('h264', rate=30)
|
220 |
graph = av.filter.Graph()
|
221 |
-
filt = graph.add("negate")
|
222 |
for i, frame in enumerate(container.decode(stream)):
|
223 |
if i > 30: break
|
224 |
filt.push(frame)
|
@@ -227,26 +233,29 @@ with st.expander("4. π¬ PyAV"):
|
|
227 |
output.close()
|
228 |
container.close()
|
229 |
save_to_history("Video", file_path)
|
230 |
-
st.video(file_path, caption="
|
231 |
|
232 |
-
# 5. MoviePy
|
233 |
-
with st.expander("5
|
234 |
-
st.write("π₯
|
235 |
-
st.subheader("Top
|
236 |
|
237 |
-
st.write("
|
238 |
-
if st.button("
|
|
|
239 |
cap = cv2.VideoCapture(0)
|
240 |
frames = [cv2.cvtColor(cap.read()[1], cv2.COLOR_BGR2RGB) for _ in range(30)]
|
241 |
cap.release()
|
242 |
file_path = f"moviepy_seq_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"
|
243 |
clip = mp.ImageSequenceClip(frames, fps=15)
|
244 |
-
clip.
|
245 |
-
save_to_history("Video", file_path)
|
|
|
246 |
st.video(file_path)
|
247 |
|
248 |
-
st.write("
|
249 |
-
if st.button("
|
|
|
250 |
cap = cv2.VideoCapture(0)
|
251 |
frames = [cv2.cvtColor(cap.read()[1], cv2.COLOR_BGR2RGB) for _ in range(30)]
|
252 |
cap.release()
|
@@ -256,10 +265,11 @@ with st.expander("5. πΌ MoviePy"):
|
|
256 |
file_path = f"moviepy_resized_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"
|
257 |
clip.write_videofile(file_path)
|
258 |
save_to_history("Video", file_path)
|
259 |
-
st.video(file_path, caption="
|
260 |
|
261 |
-
st.write("
|
262 |
-
if st.button("
|
|
|
263 |
cap = cv2.VideoCapture(0)
|
264 |
frames1 = [cv2.cvtColor(cap.read()[1], cv2.COLOR_BGR2RGB) for _ in range(15)]
|
265 |
frames2 = [cv2.cvtColor(cap.read()[1], cv2.COLOR_BGR2RGB) for _ in range(15)]
|
@@ -270,11 +280,11 @@ with st.expander("5. πΌ MoviePy"):
|
|
270 |
file_path = f"moviepy_concat_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"
|
271 |
final_clip.write_videofile(file_path)
|
272 |
save_to_history("Video", file_path)
|
273 |
-
st.video(file_path, caption="
|
274 |
|
275 |
-
#
|
276 |
-
st.header("
|
277 |
-
uploaded_files = st.file_uploader("
|
278 |
if uploaded_files:
|
279 |
for uploaded_file in uploaded_files:
|
280 |
file_type = uploaded_file.type.split('/')[0]
|
@@ -287,38 +297,38 @@ if uploaded_files:
|
|
287 |
"Path": file_path
|
288 |
})
|
289 |
|
290 |
-
#
|
291 |
-
st.header("
|
292 |
if st.session_state['uploaded_files']:
|
293 |
images = [f for f in st.session_state['uploaded_files'] if f['Type'] == 'image']
|
294 |
audios = [f for f in st.session_state['uploaded_files'] if f['Type'] == 'audio']
|
295 |
videos = [f for f in st.session_state['uploaded_files'] if f['Type'] == 'video']
|
296 |
|
297 |
if images:
|
298 |
-
st.subheader("
|
299 |
cols = st.columns(3)
|
300 |
for i, img in enumerate(images):
|
301 |
with cols[i % 3]:
|
302 |
st.image(img['Path'], caption=img['Name'], use_column_width=True)
|
303 |
|
304 |
if audios:
|
305 |
-
st.subheader("
|
306 |
for audio in audios:
|
307 |
st.audio(audio['Path'], format=f"audio/{audio['Name'].split('.')[-1]}")
|
308 |
-
st.write(f"
|
309 |
|
310 |
if videos:
|
311 |
-
st.subheader("
|
312 |
for video in videos:
|
313 |
st.video(video['Path'])
|
314 |
-
st.write(f"
|
315 |
else:
|
316 |
-
st.write("No
|
317 |
|
318 |
-
#
|
319 |
-
st.header("
|
320 |
if st.session_state['file_history']:
|
321 |
df = pd.DataFrame(st.session_state['file_history'])
|
322 |
st.dataframe(df)
|
323 |
else:
|
324 |
-
st.write("
|
|
|
11 |
import numpy as np
|
12 |
from io import BytesIO
|
13 |
|
14 |
+
# ππ₯ Initialize session state like a galactic DJ spinning tracks!
|
15 |
if 'file_history' not in st.session_state:
|
16 |
st.session_state['file_history'] = []
|
17 |
if 'ping_code' not in st.session_state:
|
|
|
19 |
if 'uploaded_files' not in st.session_state:
|
20 |
st.session_state['uploaded_files'] = []
|
21 |
|
22 |
+
# ππΎ Save to history like a time-traveling scribe! | π
β¨ save_to_history("Image", "pic.jpg") - Stamps a pic in the history books like a boss!
|
23 |
def save_to_history(file_type, file_path):
|
24 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
25 |
st.session_state['file_history'].append({
|
|
|
28 |
"Path": file_path
|
29 |
})
|
30 |
|
31 |
+
# ππ¨ Main UI kicks off like a cosmic art show!
|
32 |
+
st.title("πΈποΈ Capture Craze")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
+
# ποΈ Sidebar config like a spaceship control panel!
|
35 |
+
with st.sidebar:
|
36 |
+
st.header("ποΈπΈ Tune-Up Zone")
|
37 |
+
library_choice = st.selectbox("π Pick a Tool", ["OpenCV", "PyAudio", "ImageIO", "PyAV", "MoviePy"])
|
38 |
+
resolution = st.select_slider("π Snap Size", options=["320x240", "640x480", "1280x720"], value="640x480")
|
39 |
+
fps = st.slider("β±οΈ Speed Snap", 1, 60, 30)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
+
# π’ DTMF ping code like a retro phone hacker!
|
42 |
+
st.subheader("π Ping-a-Tron")
|
43 |
+
col1, col2, col3, col4 = st.columns(4)
|
44 |
+
with col1:
|
45 |
+
digit1 = st.selectbox("1οΈβ£", [str(i) for i in range(10)], key="d1")
|
46 |
+
with col2:
|
47 |
+
digit2 = st.selectbox("2οΈβ£", [str(i) for i in range(10)], key="d2")
|
48 |
+
with col3:
|
49 |
+
digit3 = st.selectbox("3οΈβ£", [str(i) for i in range(10)], key="d3")
|
50 |
+
with col4:
|
51 |
+
digit4 = st.selectbox("4οΈβ£", [str(i) for i in range(10)], key="d4")
|
52 |
+
ping_code = digit1 + digit2 + digit3 + digit4
|
53 |
+
st.session_state['ping_code'] = ping_code
|
54 |
+
st.write(f"π Code: {ping_code}")
|
55 |
|
56 |
+
# πΈπ Library showcase like a tech talent show!
|
57 |
+
st.header("πΈποΈ Tool Titans")
|
58 |
|
59 |
+
# 1. OpenCV - π· Pixel party time!
|
60 |
+
with st.expander("1οΈβ£ π· OpenCV Fiesta"):
|
61 |
+
st.write("π₯ Snap Star: Real-time pixel magic!")
|
62 |
+
st.subheader("π₯ Top Tricks")
|
63 |
|
64 |
+
st.write("πΈπ₯ Video Snap")
|
65 |
+
if st.button("π¬ Go Live", key="opencv_1"):
|
66 |
+
# π·π₯ Snags webcam like a paparazzi pro! | πΈ cap = cv2.VideoCapture(0) - Grabs live feed faster than gossip spreads!
|
67 |
cap = cv2.VideoCapture(0)
|
68 |
frame_placeholder = st.empty()
|
69 |
+
for _ in range(50):
|
70 |
ret, frame = cap.read()
|
71 |
if ret:
|
72 |
frame_placeholder.image(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
|
73 |
cap.release()
|
74 |
|
75 |
+
st.write("ποΈβ¨ Gray Snap")
|
76 |
+
if st.button("π· Save Gray", key="opencv_2"):
|
77 |
+
# ποΈβ¨ Saves grayscale like an artsy ghost! | π cv2.imwrite("gray.jpg", cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)) - Ditches color like a moody poet!
|
78 |
cap = cv2.VideoCapture(0)
|
79 |
ret, frame = cap.read()
|
80 |
if ret:
|
81 |
+
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
82 |
file_path = f"opencv_gray_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg"
|
83 |
cv2.imwrite(file_path, gray)
|
84 |
save_to_history("Image", file_path)
|
85 |
+
st.image(file_path, caption="π€ Gray Vibes")
|
86 |
cap.release()
|
87 |
|
88 |
+
st.write("π΅οΈββοΈπ Edge Snap")
|
89 |
+
if st.button("πͺ Edge It", key="opencv_3"):
|
90 |
+
# π΅οΈββοΈπ Finds edges sharper than a detectiveβs wit! | πΌοΈ edges = cv2.Canny(frame, 100, 200) - Outlines like a crime scene sketch!
|
91 |
cap = cv2.VideoCapture(0)
|
92 |
ret, frame = cap.read()
|
93 |
if ret:
|
|
|
95 |
file_path = f"opencv_edges_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg"
|
96 |
cv2.imwrite(file_path, edges)
|
97 |
save_to_history("Image", file_path)
|
98 |
+
st.image(file_path, caption="π Edge Lord")
|
99 |
cap.release()
|
100 |
|
101 |
+
# 2. PyAudio - ποΈ Soundwave showdown!
|
102 |
+
with st.expander("2οΈβ£ ποΈ PyAudio Party"):
|
103 |
+
st.write("π Audio Ace: Sound control ninja!")
|
104 |
+
st.subheader("π₯ Top Tricks")
|
105 |
|
106 |
+
st.write("π€π©οΈ Record Jam")
|
107 |
+
if st.button("π΅ Grab Sound", key="pyaudio_1"):
|
108 |
+
# π€π©οΈ Records like a storm-chasing bard! | ποΈ stream = pyaudio.PyAudio().open(...) - Captures audio like thunder in a bottle!
|
109 |
p = pyaudio.PyAudio()
|
110 |
stream = p.open(format=pyaudio.paInt16, channels=1, rate=44100, input=True, frames_per_buffer=1024)
|
111 |
+
frames = [stream.read(1024) for _ in range(int(44100 / 1024 * 3))]
|
112 |
stream.stop_stream()
|
113 |
stream.close()
|
114 |
p.terminate()
|
|
|
121 |
save_to_history("Audio", file_path)
|
122 |
st.audio(file_path)
|
123 |
|
124 |
+
st.write("π΅οΈββοΈπ‘ Mic Spy")
|
125 |
+
if st.button("π List Mics", key="pyaudio_2"):
|
126 |
+
# π΅οΈββοΈπ‘ Spies mics like a gossip queen! | π‘ info = pyaudio.PyAudio().get_device_info_by_index(0) - Sniffs out devices like a tech bloodhound!
|
127 |
p = pyaudio.PyAudio()
|
128 |
devices = [p.get_device_info_by_index(i) for i in range(p.get_device_count())]
|
129 |
+
st.write("ποΈ Mic Squad:", devices)
|
130 |
p.terminate()
|
131 |
|
132 |
+
st.write("πΆπΎ Sound Bite")
|
133 |
+
if st.button("π§ Quick Grab", key="pyaudio_3"):
|
134 |
+
# πΆπΎ Snags audio like a DJ mid-set! | π΅ data = stream.read(1024) - Bites sound faster than a snack attack!
|
135 |
p = pyaudio.PyAudio()
|
136 |
stream = p.open(format=pyaudio.paInt16, channels=1, rate=44100, input=True, frames_per_buffer=1024)
|
137 |
data = stream.read(1024)
|
138 |
+
st.write("π΅ Bytes Nabbed:", len(data))
|
139 |
stream.stop_stream()
|
140 |
stream.close()
|
141 |
p.terminate()
|
142 |
|
143 |
+
# 3. ImageIO - πΌοΈ Pixel playtime!
|
144 |
+
with st.expander("3οΈβ£ πΉ ImageIO Bash"):
|
145 |
+
st.write("π₯ Easy Snap: Pixel lightweight champ!")
|
146 |
+
st.subheader("π₯ Top Tricks")
|
147 |
|
148 |
+
st.write("πΉπ Frame Peek")
|
149 |
+
if st.button("πΈ Snap It", key="imageio_1"):
|
150 |
+
# πΉπ Grabs frames like a shy stalker! | π· reader = imageio.get_reader('<video0>') - Sneaks a peek at your cam!
|
151 |
reader = imageio.get_reader('<video0>')
|
152 |
frame = reader.get_next_data()
|
153 |
file_path = f"imageio_frame_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg"
|
|
|
155 |
save_to_history("Image", file_path)
|
156 |
st.image(file_path)
|
157 |
|
158 |
+
st.write("π¨οΈπ Crunch Snap")
|
159 |
+
if st.button("π Slim Pic", key="imageio_2"):
|
160 |
+
# π¨οΈπ Compresses like a diet guru! | πΌοΈ imageio.imwrite("pic.jpg", frame, quality=85) - Shrinks pics like a tight squeeze!
|
161 |
reader = imageio.get_reader('<video0>')
|
162 |
frame = reader.get_next_data()
|
163 |
file_path = f"imageio_comp_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg"
|
164 |
+
imageio.imwrite(file_path, frame, quality=85)
|
165 |
save_to_history("Image", file_path)
|
166 |
+
st.image(file_path, caption="π Slim Fit")
|
167 |
|
168 |
+
st.write("ποΈπ€‘ GIF Blast")
|
169 |
+
if st.button("π GIF It", key="imageio_3"):
|
170 |
+
# ποΈπ€‘ Makes GIFs like a circus juggler! | π₯ imageio.mimwrite("gif.gif", [f1, f2], fps=5) - Flips frames into fun!
|
171 |
reader = imageio.get_reader('<video0>')
|
172 |
frames = [reader.get_next_data() for _ in range(10)]
|
173 |
file_path = f"imageio_gif_{datetime.now().strftime('%Y%m%d_%H%M%S')}.gif"
|
174 |
imageio.mimwrite(file_path, frames, fps=5)
|
175 |
save_to_history("GIF", file_path)
|
176 |
+
st.image(file_path, caption="π€‘ GIF Party")
|
177 |
|
178 |
+
# 4. PyAV - π¬ AV rock fest!
|
179 |
+
with st.expander("4οΈβ£ π¬ PyAV Rave"):
|
180 |
+
st.write("π₯ AV King: FFmpeg-powered chaos!")
|
181 |
+
st.subheader("π₯ Top Tricks")
|
182 |
|
183 |
+
st.write("π₯π₯ Video Jam")
|
184 |
+
if st.button("π¬ Roll It", key="pyav_1"):
|
185 |
+
# π₯π₯ Captures like a rockstar shredding! | πΉ container = av.open('/dev/video0') - Rocks the cam like a live gig!
|
186 |
container = av.open('/dev/video0')
|
187 |
stream = container.streams.video[0]
|
188 |
file_path = f"pyav_vid_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"
|
|
|
197 |
save_to_history("Video", file_path)
|
198 |
st.video(file_path)
|
199 |
|
200 |
+
st.write("π¬πΏ Audio Rip")
|
201 |
+
if st.button("π΅ Snag Sound", key="pyav_2"):
|
202 |
+
# π¬πΏ Pulls audio like a popcorn thief! | ποΈ frames = [f for f in av.open('vid.mp4').decode()] - Steals sound like a ninja!
|
203 |
container = av.open('/dev/video0', 'r', format='v4l2')
|
204 |
file_path = f"pyav_audio_{datetime.now().strftime('%Y%m%d_%H%M%S')}.wav"
|
205 |
output = av.open(file_path, 'w')
|
|
|
209 |
if frame.is_corrupt: continue
|
210 |
if hasattr(frame, 'to_ndarray'):
|
211 |
output.mux(out_stream.encode(frame))
|
212 |
+
if os.path.getsize(file_path) > 100000: break
|
213 |
output.close()
|
214 |
container.close()
|
215 |
save_to_history("Audio", file_path)
|
216 |
st.audio(file_path)
|
217 |
|
218 |
+
st.write("π€β¨ Flip Snap")
|
219 |
+
if st.button("π Twist It", key="pyav_3"):
|
220 |
+
# π€β¨ Flips colors like a rebel teen! | π¨ graph = av.filter.Graph().add("negate").pull() - Inverts like a goth makeover!
|
221 |
container = av.open('/dev/video0')
|
222 |
stream = container.streams.video[0]
|
223 |
file_path = f"pyav_filter_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"
|
224 |
output = av.open(file_path, 'w')
|
225 |
out_stream = output.add_stream('h264', rate=30)
|
226 |
graph = av.filter.Graph()
|
227 |
+
filt = graph.add("negate")
|
228 |
for i, frame in enumerate(container.decode(stream)):
|
229 |
if i > 30: break
|
230 |
filt.push(frame)
|
|
|
233 |
output.close()
|
234 |
container.close()
|
235 |
save_to_history("Video", file_path)
|
236 |
+
st.video(file_path, caption="π€ Flip Vibes")
|
237 |
|
238 |
+
# 5. MoviePy - π₯ Editing extravaganza!
|
239 |
+
with st.expander("5οΈβ£ πΌ MoviePy Gala"):
|
240 |
+
st.write("π₯ Edit Queen: Video diva vibes!")
|
241 |
+
st.subheader("π₯ Top Tricks")
|
242 |
|
243 |
+
st.write("ποΈπ Frame Dance")
|
244 |
+
if st.button("π¬ Spin It", key="moviepy_1"):
|
245 |
+
# ποΈπ Twirls frames like a dance diva! | π₯ clip = mp.ImageSequenceClip([f1, f2], fps=15) - Makes vids like a pro choreographer!
|
246 |
cap = cv2.VideoCapture(0)
|
247 |
frames = [cv2.cvtColor(cap.read()[1], cv2.COLOR_BGR2RGB) for _ in range(30)]
|
248 |
cap.release()
|
249 |
file_path = f"moviepy_seq_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"
|
250 |
clip = mp.ImageSequenceClip(frames, fps=15)
|
251 |
+
clip.write - init_block_and_save_video_file(file_path)
|
252 |
+
save_to_history("VideoΨ―ΫΩ st.session_state['file_history'].append({"Timestamp": timestamp, "Type": "Video", "Path": file_path})
|
253 |
+
st.session_state['file_history'].append({"Timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "Type": "Video", "Path": file_path})
|
254 |
st.video(file_path)
|
255 |
|
256 |
+
st.write("ππ Size Snap")
|
257 |
+
if st.button("βοΈ Trim It", key="moviepy_2"):
|
258 |
+
# ππ Resizes like a royal tailor! | βοΈ clip = mp.VideoFileClip("vid.mp4").resize((320, 240)) - Fits vids like a bespoke suit!
|
259 |
cap = cv2.VideoCapture(0)
|
260 |
frames = [cv2.cvtColor(cap.read()[1], cv2.COLOR_BGR2RGB) for _ in range(30)]
|
261 |
cap.release()
|
|
|
265 |
file_path = f"moviepy_resized_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"
|
266 |
clip.write_videofile(file_path)
|
267 |
save_to_history("Video", file_path)
|
268 |
+
st.video(file_path, caption="π Tiny King")
|
269 |
|
270 |
+
st.write("π¬π€ Join Jam")
|
271 |
+
if st.button("π Link It", key="moviepy_3"):
|
272 |
+
# π¬π€ Stitches clips like a love guru! | π₯ final = mp.concatenate_videoclips([clip1, clip2]) - Hooks up vids like a matchmaker!
|
273 |
cap = cv2.VideoCapture(0)
|
274 |
frames1 = [cv2.cvtColor(cap.read()[1], cv2.COLOR_BGR2RGB) for _ in range(15)]
|
275 |
frames2 = [cv2.cvtColor(cap.read()[1], cv2.COLOR_BGR2RGB) for _ in range(15)]
|
|
|
280 |
file_path = f"moviepy_concat_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"
|
281 |
final_clip.write_videofile(file_path)
|
282 |
save_to_history("Video", file_path)
|
283 |
+
st.video(file_path, caption="π€ Duo Dance")
|
284 |
|
285 |
+
# π Upload zone like a media drop party!
|
286 |
+
st.header("π₯π Drop Zone")
|
287 |
+
uploaded_files = st.file_uploader("πΈπ΅π₯ Toss Media", accept_multiple_files=True, type=['jpg', 'png', 'mp4', 'wav', 'mp3'])
|
288 |
if uploaded_files:
|
289 |
for uploaded_file in uploaded_files:
|
290 |
file_type = uploaded_file.type.split('/')[0]
|
|
|
297 |
"Path": file_path
|
298 |
})
|
299 |
|
300 |
+
# πΌοΈπ΅π₯ Gallery like a media circus!
|
301 |
+
st.header("πͺ Media Mania")
|
302 |
if st.session_state['uploaded_files']:
|
303 |
images = [f for f in st.session_state['uploaded_files'] if f['Type'] == 'image']
|
304 |
audios = [f for f in st.session_state['uploaded_files'] if f['Type'] == 'audio']
|
305 |
videos = [f for f in st.session_state['uploaded_files'] if f['Type'] == 'video']
|
306 |
|
307 |
if images:
|
308 |
+
st.subheader("πΌοΈ Pic Parade")
|
309 |
cols = st.columns(3)
|
310 |
for i, img in enumerate(images):
|
311 |
with cols[i % 3]:
|
312 |
st.image(img['Path'], caption=img['Name'], use_column_width=True)
|
313 |
|
314 |
if audios:
|
315 |
+
st.subheader("π΅ Sound Splash")
|
316 |
for audio in audios:
|
317 |
st.audio(audio['Path'], format=f"audio/{audio['Name'].split('.')[-1]}")
|
318 |
+
st.write(f"π€ {audio['Name']}")
|
319 |
|
320 |
if videos:
|
321 |
+
st.subheader("π₯ Vid Vortex")
|
322 |
for video in videos:
|
323 |
st.video(video['Path'])
|
324 |
+
st.write(f"π¬ {video['Name']}")
|
325 |
else:
|
326 |
+
st.write("π« No loot yet!")
|
327 |
|
328 |
+
# π History log like a time machine!
|
329 |
+
st.header("β³ Snap Saga")
|
330 |
if st.session_state['file_history']:
|
331 |
df = pd.DataFrame(st.session_state['file_history'])
|
332 |
st.dataframe(df)
|
333 |
else:
|
334 |
+
st.write("π³οΈ Nothing snapped yet!")
|