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
@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
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…