Update app.py
Browse files
app.py
CHANGED
@@ -1,41 +1,32 @@
|
|
1 |
-
import cv2
|
2 |
import gradio as gr
|
|
|
3 |
import numpy as np
|
4 |
import librosa
|
5 |
-
# Load the video file
|
6 |
-
cap = cv2.VideoCapture('video_file.mp4')
|
7 |
-
# Check if the video has audio
|
8 |
-
if cap.get(cv2.CAP_PROP_AUDIO_STATUS):
|
9 |
-
# Read the video frames
|
10 |
-
while True:
|
11 |
-
ret, frame = cap.read()
|
12 |
-
# Convert the frame to grayscale and apply thresholding
|
13 |
-
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
14 |
-
_, thresh = cv2.threshold(gray, 100, 255, cv2.THRESH_BINARY)
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
24 |
|
25 |
-
#
|
26 |
-
|
27 |
|
28 |
-
#
|
29 |
-
|
30 |
|
31 |
-
|
32 |
-
new_audio = np.zeros((len(frame), sr))
|
33 |
-
for i in range(len(frame)):
|
34 |
-
# Calculate the time stamp for each pixel in the frame
|
35 |
-
t = (i * framerate) + start_time
|
36 |
-
|
37 |
-
# Add the corresponding value from the audio signal to the new audio array
|
38 |
-
new_audio[i] = audio[int(t)]
|
39 |
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import cv2
|
3 |
import numpy as np
|
4 |
import librosa
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
def process_video(video_file):
|
7 |
+
# Read the video file
|
8 |
+
cap = cv2.VideoCapture(video_file)
|
9 |
+
frames = []
|
10 |
+
while True:
|
11 |
+
ret, frame = cap.read()
|
12 |
+
if not ret:
|
13 |
+
break
|
14 |
+
frames.append(frame)
|
15 |
+
cap.release()
|
16 |
|
17 |
+
# Process the video frames and generate audio
|
18 |
+
# Your video processing and audio generation logic here
|
19 |
|
20 |
+
# Save the new audio file
|
21 |
+
# Example: librosa.output.write_wav('output_audio.wav', new_audio, sr)
|
22 |
|
23 |
+
return "Audio generated successfully"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
+
iface = gr.Interface(
|
26 |
+
fn=process_video,
|
27 |
+
inputs="file",
|
28 |
+
outputs="text",
|
29 |
+
title="Video to Audio Generator",
|
30 |
+
description="Upload a video, analyze it, and generate audio"
|
31 |
+
)
|
32 |
+
iface.launch()
|