awacke1 commited on
Commit
ab5b911
Β·
verified Β·
1 Parent(s): daafe64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +123 -113
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
- # Function to save to history
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
- # Sidebar configuration
32
- st.sidebar.header("πŸ“Έ Configuration")
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
- # DTMF-style ping code input
45
- st.sidebar.subheader("πŸ”’ Device Ping Code")
46
- col1, col2, col3, col4 = st.sidebar.columns(4)
47
- with col1:
48
- digit1 = st.selectbox("D1", [str(i) for i in range(10)], key="d1")
49
- with col2:
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
- # Main UI
60
- st.title("πŸ“Έ Camera & Audio Capture Tool")
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
- # Outline with top 3 function examples
63
- st.header("πŸ“Έ Top Five Python Libraries")
64
 
65
- # 1. OpenCV
66
- with st.expander("1. πŸ“· OpenCV"):
67
- st.write("πŸŽ₯ *Best Feature*: Real-time image processing and video capture.")
68
- st.subheader("Top 3 Function Examples")
69
 
70
- st.write("1. `cv2.VideoCapture()` - Capture and display video")
71
- if st.button("Run VideoCapture", key="opencv_1"):
 
72
  cap = cv2.VideoCapture(0)
73
  frame_placeholder = st.empty()
74
- for _ in range(50): # 50 frames
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("2. `cv2.imwrite()` - Save processed image")
81
- if st.button("Run imwrite", key="opencv_2"):
 
82
  cap = cv2.VideoCapture(0)
83
  ret, frame = cap.read()
84
  if ret:
85
- gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Convert to grayscale
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="Grayscale Image")
90
  cap.release()
91
 
92
- st.write("3. `cv2.Canny()` - Edge detection")
93
- if st.button("Run Canny", key="opencv_3"):
 
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 Detection")
102
  cap.release()
103
 
104
- # 2. PyAudio
105
- with st.expander("2. πŸŽ™οΈ PyAudio"):
106
- st.write("πŸ”Š *Best Feature*: Low-level audio input/output control.")
107
- st.subheader("Top 3 Function Examples")
108
 
109
- st.write("1. `PyAudio.open()` - Record audio")
110
- if st.button("Run Audio Record", key="pyaudio_1"):
 
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))] # 3 seconds
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("2. `PyAudio.get_device_info_by_index()` - List audio devices")
127
- if st.button("Run Device Info", key="pyaudio_2"):
 
128
  p = pyaudio.PyAudio()
129
  devices = [p.get_device_info_by_index(i) for i in range(p.get_device_count())]
130
- st.write("Available Audio Devices:", devices)
131
  p.terminate()
132
 
133
- st.write("3. `stream.read()` - Real-time audio data")
134
- if st.button("Run Stream Read", key="pyaudio_3"):
 
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("Sample audio data length:", len(data))
139
  stream.stop_stream()
140
  stream.close()
141
  p.terminate()
142
 
143
- # 3. ImageIO
144
- with st.expander("3. πŸ“Ή ImageIO"):
145
- st.write("πŸŽ₯ *Best Feature*: Simple and efficient image/video I/O.")
146
- st.subheader("Top 3 Function Examples")
147
 
148
- st.write("1. `imageio.get_reader()` - Read webcam frames")
149
- if st.button("Run get_reader", key="imageio_1"):
 
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("2. `imageio.imwrite()` - Save image with compression")
158
- if st.button("Run imwrite", key="imageio_2"):
 
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) # Compressed
163
  save_to_history("Image", file_path)
164
- st.image(file_path, caption="Compressed Image")
165
 
166
- st.write("3. `imageio.mimwrite()` - Create GIF")
167
- if st.button("Run mimwrite", key="imageio_3"):
 
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. 🎬 PyAV"):
177
- st.write("πŸŽ₯ *Best Feature*: Powerful FFmpeg-based AV processing.")
178
- st.subheader("Top 3 Function Examples")
179
 
180
- st.write("1. `av.open()` - Capture video")
181
- if st.button("Run av.open", key="pyav_1"):
 
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("2. `container.decode()` - Extract audio")
197
- if st.button("Run decode", key="pyav_2"):
 
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 # Limit size
208
  output.close()
209
  container.close()
210
  save_to_history("Audio", file_path)
211
  st.audio(file_path)
212
 
213
- st.write("3. `av.filter()` - Apply video filter")
214
- if st.button("Run filter", key="pyav_3"):
 
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") # Invert colors
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="Negated Video")
231
 
232
- # 5. MoviePy
233
- with st.expander("5. πŸ“Ό MoviePy"):
234
- st.write("πŸŽ₯ *Best Feature*: High-level video editing.")
235
- st.subheader("Top 3 Function Examples")
236
 
237
- st.write("1. `ImageSequenceClip()` - Video from frames")
238
- if st.button("Run ImageSequenceClip", key="moviepy_1"):
 
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.write_videofile(file_path)
245
- save_to_history("Video", file_path)
 
246
  st.video(file_path)
247
 
248
- st.write("2. `VideoFileClip()` - Load and resize video")
249
- if st.button("Run VideoFileClip", key="moviepy_2"):
 
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="Resized Video")
260
 
261
- st.write("3. `concatenate_videoclips()` - Combine clips")
262
- if st.button("Run concatenate", key="moviepy_3"):
 
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="Concatenated Video")
274
 
275
- # Media Upload Section
276
- st.header("πŸ“‚ Upload Media Files")
277
- uploaded_files = st.file_uploader("Upload Images, Audio, or Video", accept_multiple_files=True, type=['jpg', 'png', 'mp4', 'wav', 'mp3'])
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
- # Galleries and Players
291
- st.header("πŸ–ΌοΈ Media Gallery")
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("Images")
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("Audio")
306
  for audio in audios:
307
  st.audio(audio['Path'], format=f"audio/{audio['Name'].split('.')[-1]}")
308
- st.write(f"Name: {audio['Name']}")
309
 
310
  if videos:
311
- st.subheader("Videos")
312
  for video in videos:
313
  st.video(video['Path'])
314
- st.write(f"Name: {video['Name']}")
315
  else:
316
- st.write("No media uploaded yet.")
317
 
318
- # File History Display
319
- st.header("πŸ“œ File History")
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("No files captured yet.")
 
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!")