-
Notifications
You must be signed in to change notification settings - Fork 0
/
mucvid.py
156 lines (95 loc) · 4.56 KB
/
mucvid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
## Making Movie with Music * .mp3
def mzic(raw_audio,video,audio_length,Merged_video_root):
from moviepy.editor import AudioFileClip,VideoFileClip
import os
import numpy as np
from datetime import datetime
cwd = os.path.dirname(os.path.realpath(__file__))
musci_root = os.path.join(cwd,'musicroot')
os.mkdir(musci_root)
try:
f=open(raw_audio,'r')
del f
audioclip=AudioFileClip(raw_audio)
video1=VideoFileClip(video)
wav_duration=audioclip.duration
start_wav=0
end_wav=wav_duration
pc=audioclip.subclip(start_wav,-end_wav+int(audio_length)) ## wav audio duration 3 seconds
# cwd = os.getcwd()
cwd = os.path.dirname(os.path.realpath(__file__))
croped_audio_dir = os.path.join(cwd,'croped_audio')
croped_audio_videoname='nm'
video_outputname=croped_audio_dir +"/"+croped_audio_videoname+'.mp3'
croped_audio_file = os.path.join(croped_audio_dir , video_outputname)
pc.write_audiofile(croped_audio_file)
del pc
audioclip=AudioFileClip(croped_audio_file)
del_var1=[AudioFileClip,croped_audio_file]
del del_var1
## VIDEO AUDIO MERGE
# cwd = os.getcwd()
Merged_video = os.path.join(cwd,'musicroot')
# Merged_video=Merged_video_root
croped_audio_videoname='musicroot'
mp4adi_dt=datetime.utcnow()
mp4adi_timstmp=int(round(mp4adi_dt.timestamp()*1000))
croped_audio_videoname=str(mp4adi_timstmp)
video_outputname=Merged_video +"/"+croped_audio_videoname+'.mp4' ## mp4 webm
Merged_video_file = os.path.join(Merged_video , video_outputname)
video1.audio=audioclip
video2=video1
del AudioFileClip,VideoFileClip
video2.write_videofile(Merged_video_file)
import mirage
import os
dir_path = os.path.dirname(os.path.realpath(__file__))
mirag_out=mirage.watermark(Merged_video_file,Merged_video_root)
os.remove(video) # remove first level video without music file
os.remove(croped_audio_file) # remove cropped audio file
# os.remove(Merged_video)
os.rmdir(Merged_video)
return [Merged_video]
except (FileNotFoundError,IOError):
print('Music File was not in root')
#################################################################
##################################################################
# try:
# f=open(raw_audio,'r')
# del f
# #
# audioclip=AudioFileClip(raw_audio)
# video1=VideoFileClip(video)
# wav_duration=audioclip.duration
# start_wav=0
# end_wav=wav_duration
# pc=audioclip.subclip(start_wav,-end_wav+int(audio_length)) ## wav audio duration 3 seconds
# cwd = os.getcwd()
# croped_audio_dir = os.path.join(cwd,'croped_audio')
# croped_audio_videoname='nm'
# video_outputname=croped_audio_dir +"/"+croped_audio_videoname+'.mp3'
# croped_audio_file = os.path.join(croped_audio_dir , video_outputname)
# pc.write_audiofile(croped_audio_file)
# del pc
# audioclip=AudioFileClip(croped_audio_file)
# del_var1=[AudioFileClip,croped_audio_file]
# del del_var1
# ## VIDEO AUDIO MERGE
# cwd = os.getcwd()
# Merged_video = os.path.join(cwd,'Merged_video_out')
# Merged_video=Merged_video_root
# croped_audio_videoname='output'
# mp4adi_dt=datetime.utcnow()
# mp4adi_timstmp=int(round(mp4adi_dt.timestamp()*1000))
# croped_audio_videoname=str(mp4adi_timstmp)
# video_outputname=Merged_video +"/"+croped_audio_videoname+'.webm' ## mp4 webm
# Merged_video_file = os.path.join(Merged_video , video_outputname)
# video1.audio=audioclip
# video2=video1
# del AudioFileClip,VideoFileClip
# video2.write_videofile(Merged_video_file)
# os.remove(video) # remove first level video without music file
# os.remove(croped_audio_file) # remove cropped audio file
# return [video_outputname]
# except (FileNotFoundError,IOError):
# print('Music File was not in root')