Link to home
Start Free TrialLog in
Avatar of Tessando
TessandoFlag for United States of America

asked on

Assistance Fixing MoviePY Python Error "NameError: name 'video' is not defined"

I am following this AWS Tutorial on how to create Video subtitles. Per the suggestions in the write-up I'm using Windows (in my case a Server 2019 VM) and Python. I am following the directions perfectly, but when I get to Step 10, in which I test MoviePY, I get the following error:

NameError: name 'video' is not defined

Open in new window

I've done some research and it seems like I do need to define 'video' in Python, but what I'm not aware of is:

  1. Where I make this adjustment? E.g. to what configuration file?
  2. What I put into the Configuration file in order to fix this error?

Thanks for your help!
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

It seems like either your are missing import some library or refer the wrong video file path

Can you share some related working code here to further understand of your actual error?
Avatar of Tessando

ASKER

Ah, yes. Thank you David. I'm attempting to follow the tutorial listed in the AWS doc in order to test MoviePy. In this test case, I'm taking an existing MP4 file, reducing the volume and writing the output as a WebM file. Here is the test code that produces the error I mentioned in the opening question:

# Import everything needed to edit video clips
from moviepy.editor import *

# Load .mp4 and select the subclip 00:00:50 - 00:00:60
clip = VideoFileClip("TEMP_VTT-MS-Test.mp4").subclip(50,60)

# Reduce the audio volume (volume x 0.8)
clip = clip.volumex(0.8)

# Write the result to a file (many options available !)
video.write_videofile("TEMP_VTT-MS-Test.webm")

Open in new window


Hopefully something is clear from this. Thanks!
Noted. Can you rename the file below and try again?
clip = VideoFileClip("mstemp.mp4").subclip(50,60)

Open in new window

Thank you, David. I renamed the file that and changed the script, but I'm getting the same error. Here is the full error and path:

C:\Program Files\ImageMagick-7.1.0-Q16-HDRI\TEMP_TestMoviePY>moviepy-test.py
Traceback (most recent call last):
  File "C:\Program Files\ImageMagick-7.1.0-Q16-HDRI\TEMP_TestMoviePY\moviepy-test.py", line 20, in <module>
    video.write_videofile("mstemp.webm")
NameError: name 'video' is not defined

Open in new window


Thanks again for your help.
can I know your current working path?

import os

path = os.getcwd()

print(path)

Open in new window

The current working path is:

C:\Program Files\ImageMagick-7.1.0-Q16-HDRI\TEMP_TestMoviePY
Noted. Then, you need to adjust your current working path.

import os

# change the current directory to the directory where the running script file (.py) 
os.chdir(os.path.dirname(os.path.abspath(__file__)))

Open in new window

# Import everything needed to edit video clips
from moviepy.editor import *

# Load .mp4 and select the subclip 00:00:50 - 00:00:60
clip = VideoFileClip("mstemp.mp4").subclip(50,60)

# Reduce the audio volume (volume x 0.8)
clip = clip.volumex(0.8)

# Write the result to a file (many options available !)
video.write_videofile("TEMP_VTT-MS-Test.webm")

Open in new window

Thanks David - I added the import command to the top of the script but I'm getting the same error and no results (e.g. no WebM file). Below is the new script I'm running, perhaps I missing something.

import os

# change the current directory to the directory where the running script file (.py) 
os.chdir(os.path.dirname(os.path.abspath(__file__)))

# Import everything needed to edit video clips
from moviepy.editor import *

# Load myHolidays.mp4 and select the subclip 00:00:50 - 00:00:60
clip = VideoFileClip("mstemp.mp4").subclip(50,60)

# Reduce the audio volume (volume x 0.8)
clip = clip.volumex(0.8)

# Write the result to a file (many options available !)
video.write_videofile("mstemp.webm")

Open in new window


Does this script look correct to you (for what you intended me to run)?
ASKER CERTIFIED SOLUTION
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial