Spaces:
Runtime error
Runtime error
Update Moviepy
#6
by Shashika-HF - opened
Moviepy
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from moviepy.editor import *
|
| 2 |
+
|
| 3 |
+
current_video_path=r"C:\Users\ASUS\Downloads\Introducing the New Range Rover Sport-gWS1wLfiDVU-480pp-1703424984.mp4"
|
| 4 |
+
current_video=VideoFileClip(current_video_path) #location of the uploaded video
|
| 5 |
+
|
| 6 |
+
current_audio_path="current_audio.mp3"
|
| 7 |
+
if current_video.audio is not None:
|
| 8 |
+
current_video.audio.write_audiofile(current_audio_path) #location of the audio clip
|
| 9 |
+
print("Audio file has been extracted from the video")
|
| 10 |
+
else:
|
| 11 |
+
print("No audio found in the video.")
|
| 12 |
+
|
| 13 |
+
current_audio=AudioFileClip(current_audio_path) #location of the whole audio clip from the uloaded video
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
#define the segements for the audio clips
|
| 17 |
+
start_explosion_time=3 # Define the start time of the explosion part
|
| 18 |
+
end_explosion_time = 6 # Define the end time of the explosion part
|
| 19 |
+
|
| 20 |
+
#extract audio segements
|
| 21 |
+
beginning_audio_clip=current_audio.subclip(0,start_explosion_time) #0 = start, end value will be the beginning of the explotion part
|
| 22 |
+
end_audio_clip=current_audio.subclip(end_explosion_time,) #start = end of the explotion, end = end of the audio
|
| 23 |
+
|
| 24 |
+
#haptic_audio_clip=current_audio.subclip(start_explosion_time,end_explosion_time) #start = start of the explotion, end = end of the explotion
|
| 25 |
+
|
| 26 |
+
haptic_audio_path='https://phonebrrdemonstration2.blob.core.windows.net/audio3secondsmp3/3_second_explosion_00001.mp3'
|
| 27 |
+
haptic_audio=AudioFileClip(haptic_audio_path)
|
| 28 |
+
haptic_audio_clip=haptic_audio.subclip() #start = start of the explotion, end = end of the explotion
|
| 29 |
+
|
| 30 |
+
#concatenate audio clips to create enhanced audio
|
| 31 |
+
final_audio=concatenate_audioclips([beginning_audio_clip,haptic_audio_clip,end_audio_clip]) #enhanced audio
|
| 32 |
+
|
| 33 |
+
#save the enhanced audio
|
| 34 |
+
final_audio_path="output.mp3"
|
| 35 |
+
final_audio.write_audiofile(final_audio_path) #enhanced audio "name"
|
| 36 |
+
print("Enhanced audio has been created")
|
| 37 |
+
|
| 38 |
+
#create a video without audio
|
| 39 |
+
extracted_video=current_video.without_audio()
|
| 40 |
+
|
| 41 |
+
#save the video without audio
|
| 42 |
+
extracted_video_path="output.mp4"
|
| 43 |
+
extracted_video.write_videofile(extracted_video_path,fps=60)
|
| 44 |
+
print("Video without audio has been created")
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
#combine the final video without the enhanced audio
|
| 48 |
+
final_video=extracted_video.set_audio(final_audio)
|
| 49 |
+
|
| 50 |
+
#save the final video
|
| 51 |
+
final_video_path="final_video.mp4"
|
| 52 |
+
final_video.write_videofile(final_video_path)
|
| 53 |
+
print("final video has been created")
|
| 54 |
+
|
| 55 |
+
|