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.
production of video files with dynamic file names.
produces a video with the audio and the correct filename, but video is frozen on the first frame.
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.
That's an extremely strange problem because it shouldn't be possible! I'm afraid there's nothing that I can do to help here. Assuming that you have run that exact code and you are getting the results you describe, then I have no clue what's going on.
I'd suggest trying to run one bit, quit and reopen python and then run the second snippet.
@tburrows13 Thank you for the timely response.
Digging into the source code has led me to believe this issue is a result of the way python handles concatenation of objects, or perhaps with how it handles locality of variables. write_videofile(filename) calls ffmpeg_write_video(filename). That was as far as my research led me.
I would encourage people interested in this ticket to attempt recreation on other platforms.
I cannot do any testing right now but this should recreate it.
import moviepy
my_clip = VideoFileClip("my_clip_1.mp4")
my_broken_clip_name = "my_broken_clip"
write_videofile("my_clip.mp4")
write_videofile(my_broken_clip_name + ".mp4")
I am encountering this exact issue. However, the problem arises even when using a static file name. The code is as follows:
for clip in clip_link_final:
video_clip.append(VideoFileClip(clip))
video = concatenate_videoclips(video_clip, method="compose")
video.write_videofile(r"C:\Users\Name\Desktop\TCD\finalvideo.mp4")
As you can see, I am passing a static file name to write_videofile, but the issue of the frozen frame on all the clips still comes up.
This is very aggravating, as it seems the one function that should definitely work is not working...
@Ethan0429 try
video.write_videofile("finalvideo.mp4")
let me know what happens
@gintdm I have tried everything, including that code, and the result is always the same:
The video plays just fine for the first half or so, and then the rest of the clips in the video are frozen on the first frame, but the audio plays fine.
@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...
It is possible this is a concatenation issue.
I dont think its possible to concatenate within the function call without confusing python
possible solution would look like
meaty_chungus = "meaty_chungus" + ".mp4"
my_clip.write_videofile(meaty_chungus)
as opposed to
meaty_chungus = "meaty_chungus"
my_clip.write_videofile(meaty_chungus + ".mp4")
Have not had the opportunity to test this yet
There is no way in which calling f('a regular string') would ever behave differently from f('a ' + 'regular string') or c = 'regular string'; f('a ' + c)' as far as I am aware (disregarding exotic operator overloading scenarios that are not at play here). That is just not how python works.
My test, which you are welcome to repeat:
import moviepy
from moviepy.editor import VideoFileClip
# using this clip: http://techslides.com/demos/sample-videos/small.mp4
my_clip = VideoFileClip("small.mp4")
my_clip.write_videofile("some_file_name.mp4")
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")
This gives me 2 output video's (since the second write_videofile overwrites the first output, because it has the same name. They all work as expected (sound + video).
I'm not saying there is no problem, I'm just highly suspicious of the tests that point to the string concatenation issue for other people: most likely there are external factors that cause the problem.
Remember that my_clip is an object with state, hence calling a function the second time might have different effects than the first time. The files / filesystem could also play a role.
I'm closing this because @Sv3n's comment is correct. There is no way that just concatenating the strings makes any difference. If you are able to investigate further and find a different cause, then feel free to reopen this or create a new issue.
I don't really think that's a good enough reason to close this issue the
issue persists is replicable and is still very real regardless of weather
or not my solution is correct. Frankly its the only reason we don't use
this software for what we do.
On Thu, May 14, 2020 at 3:49 PM Tom Burrows notifications@github.com
wrote:
I'm closing this because @Sv3n https://github.com/Sv3n's comment is
correct. There is no way that just concatenating the strings makes any
difference. If you are able to investigate further and find a different
cause, then feel free to reopen this or create a new issue.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Zulko/moviepy/issues/1029#issuecomment-628851852, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/ANTAE4GB5RVSBD3M4XR2GB3RRRDNJANCNFSM4JFHWDCQ
.
Sorry, @gintdm, I'm not denying that you're experiencing issues, but neither I nor @Sv3n are able to replicate it using the explanation that you've provided, so there's nothing we can do about it. Remember issues can always be reopened if new information is provided, but without it it is impossible for anyone to do anything about it.
If you can run exactly the following (with the same input video) and it doesn't work, then there is definitely something for us to investigate.
import moviepy from moviepy.editor import VideoFileClip # using this clip: http://techslides.com/demos/sample-videos/small.mp4 my_clip = VideoFileClip("small.mp4") my_clip.write_videofile("some_file_name.mp4") 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")
For example, another possible cause is "Remember that my_clip is an object with state, hence calling a function the second time might have different effects than the first time." If you swap the lines round in your initial post's example, and it is still the second write_videofile that doesn't work, then that gives us something to go off (though it is still very hard to debug a program that doesn't crash).
Are we using similar video files to recreate? I am thinking there may be
some link to the codec. I haven't looked at this issue in a while as our
software project found another solution but I will attempt to replicate and
send the video files I use for the replication
On Thu, May 14, 2020 at 4:07 PM Tom Burrows notifications@github.com
wrote:
Sorry, @gintdm https://github.com/gintdm, I'm not denying that you're
experiencing issues, but neither I nor @Sv3n https://github.com/Sv3n
are able to replicate it using the explanation that you've provided, so
there's nothing we can do about it. If you can run exactly the following
(with the same input video) and it doesn't work, then there is definitely
something for us to investigate.import moviepy
from moviepy.editor import VideoFileClipusing this clip: http://techslides.com/demos/sample-videos/small.mp4
my_clip = VideoFileClip("small.mp4")my_clip.write_videofile("some_file_name.mp4")
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")For example, another possible cause is "Remember that my_clip is an object
with state, hence calling a function the second time might have different
effects than the first time." If you swap the lines round in your initial
post's example, and it is still the second write_videofile that doesn't
work, then that gives us something to go off (though it is still very hard
to debug a program that doesn't crash).—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Zulko/moviepy/issues/1029#issuecomment-628860089, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/ANTAE4EOB5UMF46HXEIY6KLRRRFQ5ANCNFSM4JFHWDCQ
.
I don't really think that's a good enough reason to close this issue the issue persists is replicable and is still very real regardless of weather or not my solution is correct. Frankly its the only reason we don't use this software for what we do.
…
On Thu, May 14, 2020 at 3:49 PM Tom Burrows @.*> wrote: I'm closing this because @Sv3n https://github.com/Sv3n's comment is correct. There is no way that just concatenating the strings makes any difference. If you are able to investigate further and find a different cause, then feel free to reopen this or create a new issue. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#1029 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANTAE4GB5RVSBD3M4XR2GB3RRRDNJANCNFSM4JFHWDCQ .
I'm seeing this issue too
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 :)
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.
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 :)
Yeah the whole string thing didn't make too much sense to me but if there is a problem with overwriting source files somehow under the hood, that could definitely be a culprit
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.
So the solution to my case would then be (if I wanted to end up with the final clip named the same thing as the source clip), for me to do some OS naming and file manipulation instead of the moviepy library incorporating an edge case to account for this (perhaps with temp files so that the write process isnt eating itself?). Whether it is a bug or not would really come down to arguing semantics, but it would be nice if the write_videofile() function accounted for this.