import numpy as np # for numerical operations
from moviepy.editor import VideoFileClip, concatenate
clip = VideoFileClip("video.mp4")
cut = lambda i: clip.audio.subclip(i,i+1).to_soundarray(fps=22000)
volume = lambda array: np.sqrt(((1.0*array)**2).mean())
volumes = [volume(cut(i)) for i in range(0,int(clip.duration-1))]
increases = np.diff(averaged_volumes)[:-1]>=0
decreases = np.diff(averaged_volumes)[1:]<=0
peaks_times = (increases * decreases).nonzero()[0]
peaks_vols = averaged_volumes[peaks_times]
peaks_times = peaks_times[peaks_vols>np.percentile(peaks_vols,90)]
final_times=[peaks_times[0]]
for t in peaks_times:
if (t - final_times[-1]) < 60:
if averaged_volumes[t] > averaged_volumes[final_times[-1]]:
final_times[-1] = t
else:
final_times.append(t)
final = concatenate([clip.subclip(max(t-5,0),min(t+5, clip.duration))
for t in final_times])
final.to_videofile('video1.mp4') # low quality is the default
Traceback (most recent call last):
File "C:\Users\user\Desktop\Video\PythonVideo.py", line 7, in <module>
volumes = [volume(cut(i)) for i in range(0,int(clip.duration-1))]
File "C:\Users\user\Desktop\Video\PythonVideo.py", line 7, in <listcomp>
volumes = [volume(cut(i)) for i in range(0,int(clip.duration-1))]
File "C:\Users\user\Desktop\Video\PythonVideo.py", line 5, in <lambda>
cut = lambda i: clip.audio.subclip(i,i+1).to_soundarray(fps=22000)
File "<C:\Program Files\Python36\lib\site-packages\decorator.py:decorator-gen-72>", line 2, in to_soundarray
File "C:\Program Files\Python36\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
return f(clip, *a, **k)
File "C:\Program Files\Python36\lib\site-packages\moviepy\audio\AudioClip.py", line 126, in to_soundarray
snd_array = self.get_frame(tt)
File "<C:\Program Files\Python36\lib\site-packages\decorator.py:decorator-gen-10>", line 2, in get_frame
File "C:\Program Files\Python36\lib\site-packages\moviepy\decorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
File "C:\Program Files\Python36\lib\site-packages\moviepy\Clip.py", line 95, in get_frame
return self.make_frame(t)
File "C:\Program Files\Python36\lib\site-packages\moviepy\Clip.py", line 138, in <lambda>
newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
File "C:\Program Files\Python36\lib\site-packages\moviepy\Clip.py", line 190, in <lambda>
return self.fl(lambda gf, t: gf(t_func(t)), apply_to,
File "<C:\Program Files\Python36\lib\site-packages\decorator.py:decorator-gen-10>", line 2, in get_frame
File "C:\Program Files\Python36\lib\site-packages\moviepy\decorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
File "C:\Program Files\Python36\lib\site-packages\moviepy\Clip.py", line 95, in get_frame
return self.make_frame(t)
File "C:\Program Files\Python36\lib\site-packages\moviepy\audio\io\AudioFileClip.py", line 78, in <lambda>
self.make_frame = lambda t: self.reader.get_frame(t)
File "C:\Program Files\Python36\lib\site-packages\moviepy\audio\io\readers.py", line 184, in get_frame
self.buffer_around(fr_max)
File "C:\Program Files\Python36\lib\site-packages\moviepy\audio\io\readers.py", line 238, in buffer_around
array = self.read_chunk(chunksize)
File "C:\Program Files\Python36\lib\site-packages\moviepy\audio\io\readers.py", line 112, in read_chunk
s = self.proc.stdout.read(L)
AttributeError: 'NoneType' object has no attribute 'stdout'
follow the list of message from bottom to top reading the sources. You get the point where the program was on the moment of failure.
working up to the header of the function you can see of the stdout object member get set to a value.
(also the creator procedure needs to be checked. )
If it is set from a parameter you need to follow the chain up unti you can see where you have to supply a parameter.
The other way is see what procedures you are using and verify you supplied all parameters. also one that is optional to "allow conversations" between user and software.
You may have frogotten some argument...
The next message:
File "C:\Program Files\Python36\lib\site-packages\moviepy\audio\io\readers.py", line 112, in read_chunk
s = self.proc.stdout.read(L)
AttributeError: 'NoneType' object has no attribute 'stdout'
Tells you the self.proc doesn't have a stdout (a channel to the terminal)
What the self in that context is hard to guess that you need to read in the code of readers.py.