Is there a way to extract frames in jpg to python numpy?
No clear what you mean by "frames in jpg to python numpy.
Here are some examples of code in case it helps:
import moviepy.editor as mpe
video = mpe.VideoFileClip('some_video.mp4')
np_frame = video.get_frame(2) # get the frame at t=2 seconds
np_frame = video.get_frame(frame_number * video_fps) # get frame by index
video.save_frame('my_image.jpeg', t=2) # save frame at t=2 as JPEG
Hey zulko,
Thank you for quick reply.I meant i have a video from which i need to extract frames at a particular FPS.But conditions are the image format is jpg and a certain quality like "qscale:v" parameter in ffmpeg and i need the extracted images(frames) in numpy
You can do it in moviepy with:
my_numpy_array = mpe.ImageClip('my_image.jpeg').get_frame()
But there are many more libraries that can do that such as Pillow, certainly Scipy, etc.
Yes in many other libraries including the ones you mentioned, the issue is ffmpeg extracts the frames for a certain size(file size).When I load the "ffmpeg extracted" image using (say) OpenCV's imread the size in memory is increased.My application requires thousands of images to be loaded in memory.So an 100MB files in harddisk increases to 2GB in RAM.any thoughts on this direction ?
can you explain what is the end goal of your project ? image analysis ? making a video ?
It is image analysis from a video.
14400 files taking 92MB disk space
Same 14400 files in python list takes 2 to 2.5GB in RAM
I will close this as it is not Moviepy related anymore. For this kind of support it is better to post to Stackoverflow or Reddit/Moviepy, we try to keep this section for bug reports or feature requests.
You should give more details when you post on these sites, such as what kind of analysis you are doing. The key question here is - are you really obliged to open all the images at the same time ?
Sure,I understand what you are saying.will think about the approach.Between the point am trying to make is opencv or scipy when decoding the image (extracted from ffmpeg) the file size changes.Thank you for such a quick response.
Most helpful comment
No clear what you mean by "frames in jpg to python numpy.
Here are some examples of code in case it helps: