Zulko / moviepy

Video editing with Python
https://zulko.github.io/moviepy/
MIT License
12.54k stars 1.57k forks source link

Problem with moviepy loop and speedx with error: Accessing time t= seconds, with clip duration= seconds #1652

Open Miguelo981 opened 3 years ago

Miguelo981 commented 3 years ago

I am testing the moviepy lib to make a masked video to speed it up and loop it but I can't get both things working at the same time. I get the follow error.


Python script:

video = ColorClip(color=(255, 255, 255), size=(1920, 1080))\
            .set_duration(15)\
            .set_fps(30)\
            .set_audio(None)

vtuber_clip = VideoFileClip(os.path.join(ASSETS_PATH, 'videos/test1.mp4'))

masked_clip = vtuber_clip.fx(mpe.vfx.mask_color, color=[0,214,11], thr=100, s=5)\
.set_pos(('right', 'bottom'))\
.fx(mpe.vfx.loop, n=3)\
.fx(mpe.vfx.speedx, 4)\
.set_duration(13)

final_clip = CompositeVideoClip([video, masked_clip])\
.set_duration(vtuber_clip.duration)

final_clip.write_videofile('test1.mp4')

Error:

File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site- 
      packages\moviepy\Clip.py", line 93, in get_frame
return self.make_frame(t)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site- 
      packages\moviepy\audio\io\AudioFileClip.py", line 77, in <lambda>
self.make_frame = lambda t: self.reader.get_frame(t)
File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site- 
      packages\moviepy\audio\io\readers.py", line 172, in get_frame
"with clip duration=%d seconds, "%self.duration)
OSError: Error in file D:\projects\program\assets\videos/test1.mp4, Accessing time 
         t=13.39-13.57 seconds, with clip duration=13 seconds,
jaxcooper commented 1 year ago

I know I am very late but I ran into the same problem.

According to this link: https://stackoverflow.com/questions/73214071/moviepy-oserror-error-in-file-converted-fg01-mp4-accessing-time-t-1352-40-13

The workaround worked for me:

clip = clip.fx(mp.vfx.loop, duration=desired_length)
if clip.duration > desired_length:
    clip = clip.subclip(0, desired_length)