-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to create a video from a sequence of images without writing them on memory #159
Comments
Have a look at this section of the docs. Here is how you flip a video with moviepy
note that there is also a predefined FX function mirror_y in moviepy so you can simply do:
|
Thanks Zulko for your answer. But flipping the video was just an example. My main problem is related to how create a new video and write it from several images or numpy arrays. The point is that, in my case, I have to analysis each frame separately, do some thing and then concatenate them together. Please let me know whether it is possible to create a new video from several numpy arrays in moviePy? |
If you replace the "flip" function by any other function you can do any transformation. For instance, this will apply the effect "invert the green and blue components" to each frame of the clip, and write the result to a new video file:
I really you want to make a list of (transformed) numpy arrays first, here is how you could do:
|
Many Thanks Zulko. I got your general point, tried and it works perfectly. But let me ask another question. Let me know in the function "ImageSequenceClip", there is a solid need to have all frames in one numpy array/list once. For example, if I have, 20,000 frames, I have to put all in one list/array? In this case, memory allocation error raises up. As far as I know, in FFMPEG, there is the opportunity of stream writing. I really appreciate it if you let me know in MoviePy is there any stream option? Thanks a lot |
Again, I think ImageSequenceClip is NOT what you want to use, because it forces you to have all the frames at once. All the other examples I gave you do that "streaming": you only have one frame at once in the RAM. Also have a look here for more examples (in particular the very last one). |
Exactly. Thanks for the time you spent. It is awesome. :D If I want to pass some input argument to my function, How do I have to do that? For instance, in your example, from moviepy.editor import VideoFileClip clip = VideoFileClip("my_original_video.mp4") |
@Zulko : I really appreciate it, if you let me know whether it is possible to call a function with more than one input parameters in fl_image() or not. |
For the moment you can't, but there are many other ways to do the same thing. One solution is to use fx instead of fl, because fx accepts additional parameters.
See the documentation link I give in my first answer for more details. |
I think the replies in this issue answered the original question. For a potential feature request, I'd suggest opening a new issue. |
Hi together,
I looked for my question in the net, but unfortunately, I did not find any answer for that. My purpose is to read a video via moviepy/opencv libraries and then extract the frames and do some tasks on them and concatenate them again to create a new video. To this end, I wanna use moviepy "write_videofile" method due to promising codecs and audio provider. As far as I understood, for creating the video from a sequence of images, I have to provide a list of them in "ImageSequenceClip(images_list, fps=25)". But I wanna avoid to write the images on the hard disk one by one and read them from a folder. Do you have any recommendation how to use a loop to read the frames of a video one by one, do something and concatenate them together to form a new video. any recommendation would be appreciated.
Thank you
This is a simple example which I have in mind.
import numpy as np
from moviepy.editor import *
from moviepy.Clip import *
from moviepy.video.VideoClip import *
import cv2
targetVideo = "pathToMyVideoFile"
cap = cv2.VideoCapture(targetVideo)
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
video.write_videofile('test.avi', fps=30, codec='mpeg4')
cap.release()
cv2.destroyAllWindows()
print "done"
The text was updated successfully, but these errors were encountered: