moviepy: write_videofile() appears fundamentally broken

Moviepy function write_videofile() works with static filename parameters, (i.e. "this_is_my_file.mp4") but does not work as intended when variables are passed into the filename parameter (i.e. my_variable = "a dynamic filename"). The resulting video possess audio, but is always frozen on the first frame.

Expected Behavior

production of video files with dynamic file names.

Actual Behavior

produces a video with the audio and the correct filename, but video is frozen on the first frame.

Steps to Reproduce the Problem

my_clip.write_videofile("meaty_chungus.mp4") #works

meaty_chungus = "meaty_chungus"
my_clip.write_videofile(meaty_chungus + ".mp4") #produces a video with the audio and the correct filename, but video is frozen on the first frame. 

Specifications

  • Python Version: 3.x
  • Moviepy Version: most recent
  • Platform Name: Windows
  • Platform Version: 10

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 23

Most upvoted comments

Hey @LYLeon, like I said earlier in this thread, I’ve not been able to replicate it. If you’d be able to provide the exact code and input files that you used to demonstrate this bug then I’ll take a look 😃

I’m also experiencing this issue. Using the code and file you provided I was unable to reproduce the bug. However, with a small tweak in your code, that seemingly shouldn’t matter, I get the freezing issue in every output clip. Here is the code I was able to use to recreate the issue while also using your provided video file:

import moviepy

from moviepy.editor import VideoFileClip

name = "small.mp4"
my_clip = VideoFileClip(name)
my_clip.write_videofile(name)

some_file_name = "some_file_name"
my_clip.write_videofile(some_file_name + ".mp4")

some_file_name = "another_name"
my_clip.write_videofile(some_file_name + ".mp4")

Now can we look into it? or is there something I’m fundamentally not seeing that is wrong for overwriting.

@monkfacedmonkey This code can never work because you are overwriting the source file whilst you are reading from it. When I run that code, I get lots of warning telling me that it is trying to read bytes, but can’t so it is using the last valid frames instead. If you run it on a video that is moving throughout, you’ll see that it works for the 1st second or so, which is the data that ffmpeg has cached. At that point it fails to read more and freezes on the frame for the rest of it.

Maybe it should give a better warning or error completely somewhere in the process, but there are no bugs there that I can see.

I’m going to close this unless anyone can provide anymore examples that should fail.

The solution is

video_file = mp.VideoFileClip("name1.mp4")
video_file.write_video("name1.mp4") // produces video freezed in first frame i.e corrupted
video_file.write_video("name2.mp4") // works as expected

You should not use the same name which you have specified inside VideoFileClip(), instead use a different filename

Ah, that is a different testcase: the first write_videofile() overwrites the original source clip: both input and output are called “small.mp4” here. That opens up a whole new range of possible causes. We are getting somewhere 😃

@Ethan0429 This appears to be a separate issue and perhaps warrants its own ticket. The issue this ticket is about differs in that the video does not play at all, only the first frame is displayed.

This issue appears to be caused by the source code, perhaps someone with further insight on how this function works can shed some light…