duelmas commited on
Commit
3e1fb17
·
1 Parent(s): 90c21e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -33
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
- # Display the resulting image
17
- imshow("Thresholded Image", thresh)
18
- # Check if the user presses the 'q' key
19
- if cv2.waitKey(1) & 0xFF == ord('q'):
20
- # Break out of the loop
21
- break
22
- else:
23
- print("No Audio Found")
 
 
24
 
25
- # Release the video capture
26
- cap.release()
27
 
28
- # Load the audio file
29
- audio, sr = librosa.load('audio_file.wav')
30
 
31
- # Generate a new audio file with the same duration as the video
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
- # Save the new audio file
41
- librosa.save('output_file.wav', new_audio, sr)
 
 
 
 
 
 
 
 
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()