Spaces:
Runtime error
Runtime error
Update Moviepy.py
Browse files- Moviepy.py +12 -10
Moviepy.py
CHANGED
|
@@ -38,7 +38,7 @@ def get_explosion_segments(json_data):
|
|
| 38 |
return result
|
| 39 |
|
| 40 |
def create_final_audio(current_audio_path, explosion_segments):
|
| 41 |
-
current_audio = AudioFileClip(current_audio_path)# location of the uploaded video
|
| 42 |
# define the segments for the audio clips
|
| 43 |
final_audio_segments = []
|
| 44 |
haptic_audio_path = 'https://audiolibrary.blob.core.windows.net/audiolibrary/3_second_audio.flac'
|
|
@@ -46,17 +46,19 @@ def create_final_audio(current_audio_path, explosion_segments):
|
|
| 46 |
|
| 47 |
# Iterate through each explosion occurrence and create audio segments
|
| 48 |
for explosion in explosion_segments:
|
| 49 |
-
|
| 50 |
-
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
# Adjust the duration of the haptic audio to match the duration between start and end explosion times
|
| 56 |
-
haptic_audio_duration = end_explosion_time - start_explosion_time
|
| 57 |
haptic_audio_clip = haptic_audio.subclip(0, haptic_audio_duration)
|
| 58 |
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
final_audio_segments.append(final_audio)
|
| 61 |
|
| 62 |
# concatenate final audio segments
|
|
@@ -64,7 +66,7 @@ def create_final_audio(current_audio_path, explosion_segments):
|
|
| 64 |
# Match the audio duration with the video duration
|
| 65 |
final_audio = final_audio.set_duration(current_audio.duration)
|
| 66 |
return final_audio
|
| 67 |
-
|
| 68 |
def master_audio(audio_clip):
|
| 69 |
# Apply audio mastering techniques here
|
| 70 |
# Example: loudness normalization, equalization, compression, etc.
|
|
|
|
| 38 |
return result
|
| 39 |
|
| 40 |
def create_final_audio(current_audio_path, explosion_segments):
|
| 41 |
+
current_audio = AudioFileClip(current_audio_path) # location of the uploaded video
|
| 42 |
# define the segments for the audio clips
|
| 43 |
final_audio_segments = []
|
| 44 |
haptic_audio_path = 'https://audiolibrary.blob.core.windows.net/audiolibrary/3_second_audio.flac'
|
|
|
|
| 46 |
|
| 47 |
# Iterate through each explosion occurrence and create audio segments
|
| 48 |
for explosion in explosion_segments:
|
| 49 |
+
best_explosion_time = explosion[2]
|
| 50 |
+
best_explosion_time_seconds = sum(x * int(t) for x, t in zip([3600, 60, 1], best_explosion_time.split(":")))
|
| 51 |
|
| 52 |
+
# Adjust the duration of the haptic audio to match the duration of the explosion
|
| 53 |
+
haptic_audio_duration = haptic_audio.duration
|
|
|
|
|
|
|
|
|
|
| 54 |
haptic_audio_clip = haptic_audio.subclip(0, haptic_audio_duration)
|
| 55 |
|
| 56 |
+
# Create an audio clip starting from the best explosion time
|
| 57 |
+
explosion_audio_clip = current_audio.subclip(best_explosion_time_seconds - 1,
|
| 58 |
+
best_explosion_time_seconds + haptic_audio_duration)
|
| 59 |
+
|
| 60 |
+
# Concatenate the haptic audio clip with the explosion audio clip
|
| 61 |
+
final_audio = concatenate_audioclips([explosion_audio_clip, haptic_audio_clip])
|
| 62 |
final_audio_segments.append(final_audio)
|
| 63 |
|
| 64 |
# concatenate final audio segments
|
|
|
|
| 66 |
# Match the audio duration with the video duration
|
| 67 |
final_audio = final_audio.set_duration(current_audio.duration)
|
| 68 |
return final_audio
|
| 69 |
+
|
| 70 |
def master_audio(audio_clip):
|
| 71 |
# Apply audio mastering techniques here
|
| 72 |
# Example: loudness normalization, equalization, compression, etc.
|