Avatar of Stevie Zakhour
Stevie Zakhour
 asked on

Python Error

Hi Guys

I have a python script that takes a video file called video.mp4 and cuts it down based on sound activity. See below. The python script is saved as PythonVideo.py in directory C:\Users\user\Desktop\Video

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 

Open in new window


The issue here is when I run PythonVideo.py I get lines of error, see below. Is there something wrong I'm doing here? The python version I'm using 3.6.6

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'

Open in new window


Any help is greatly appreciated.
* python3* Video EditingPythonScripting Languages

Avatar of undefined
Last Comment
Stevie Zakhour

8/22/2022 - Mon
noci

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.




Stevie Zakhour

ASKER
Thanks Noci, not sure how to resolve this. Any help is greatly appreciated.
noci

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.

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
Stevie Zakhour

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question