0

I am trying to extract and save a frame from an .mp4 using moviepy like so (simplified):

from moviepy.editor import *
clip = VideoFileClip('conditiontest1.mpg')
clip.save_frame('frame1.png', 20)

When I run this I get:

Traceback (most recent call last):
File"C:\Users\boss\Documents\DVDFab\Video Enhancer AI\join.py", line 23, > in clip = VideoFileClip(d + f + '.mp4') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\moviepy\video\io\VideoFileClip.py", > line 88, in init_ self.reader = FFMPEG_VideoReader(filename, pix_fmt=pix_fmt, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\moviepy\video\io\ffmpeg_reader.py", > line 73, in init_ self.lastread = self.read_frame() ^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\moviepy\video\io\ffmpeg_reader.py", > line 133, in read_frame raise IOError(("MoviePy error: failed to read the first frame of " OSError: MoviePy error: failed to read the first frame of video file > conditiontest1.mp4. That might mean that the file is corrupted. That may also mean that you are using a deprecated version of FFMPEG. On Ubuntu/Debian for instance the version in the repos is deprecated. Please update to a recent version from the website.

Quite a few people have reported this error. The file is not corrupted, at least it plays fine in VLC. I have the latest FFMPEG. I have tried the other recommended fix, i.e. giving the full path. No help.

One interesting thing is that this only seems to happen to me when I'm processing clips I've produced with moviepy, as in:

from moviepy.editor import *
clip = VideoFileClip('conditiontest.mpg4')
clip1 = clip.subclip(10,60)
clip1.write_videofile('conditiontest1.mpg4',codec='libx264')

That runs fine. Anyone have ideas how I can fix this?

Steve
  • 945
  • 3
  • 13
  • 22

1 Answers1

0

Forgive me for not being able to fix this issues Because I use your code in my environment,it runs correctly, This error may be occured by moviepy cant read the frame of video, So try to change the version,The version of moviepy I installed is 1.0.3, After,examine your video if it is broken,use another .mpg video to test, Hope you can fix the problem :)

black_cat
  • 30
  • 5
  • That's the version I have. Also made sure I have the most recent FFMPEG. I'm thinking it might have something to do with the last line of the traceback which ends with a " but nothing after. Maybe the filename isn't getting passed for some reason. But then why wouldn't this happen every time? It's weird. – Steve Aug 01 '23 at 14:48