Skip to content
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

Extracting frames #702

Closed
srikanthsridar opened this issue Jan 25, 2018 · 10 comments
Closed

Extracting frames #702

srikanthsridar opened this issue Jan 25, 2018 · 10 comments

Comments

@srikanthsridar
Copy link

Is there a way to extract frames in jpg to python numpy?

@Zulko
Copy link
Owner

Zulko commented Jan 25, 2018

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

@srikanthsridar
Copy link
Author

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

@Zulko
Copy link
Owner

Zulko commented Jan 25, 2018

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.

@srikanthsridar
Copy link
Author

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 ?

@Zulko
Copy link
Owner

Zulko commented Jan 25, 2018

can you explain what is the end goal of your project ? image analysis ? making a video ?

@srikanthsridar
Copy link
Author

srikanthsridar commented Jan 25, 2018

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

@Zulko
Copy link
Owner

Zulko commented Jan 25, 2018

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 ?

@Zulko Zulko closed this as completed Jan 25, 2018
@srikanthsridar
Copy link
Author

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.

@davidbernat
Copy link

davidbernat commented Jul 3, 2023

Hello @Zulko. Asking to reopen this ticket for its generic title. I am noticing that get_frame appears to be of fixed speed for successive calls; i.e., ten calls appears to take up to one second or more to process. This is presumably because the VideoFileClip object does not store video data in memory, and therefore must reload the entire clip, again, on each successive call. Is this correct, and is there a faster alternative? I also am noting that loading the clip into numpy (to then use slicing) seems not to be an option based on various past issues?

Would you be available to discuss this offline in email?

@keikoro
Copy link
Collaborator

keikoro commented Jul 11, 2023

@davidbernat It'd be better to open a new issue for this than for us to reopen this very old one, especially since nothing in OP's original question suggests it had anything to do with what you are asking here.

Subject lines aren't necessarily good indicators for if older issues match what you're looking for, and we don't want to make anyone, including ourselves, waste time by reading through years-old threads only to discover they are of little relevance to what's being asked now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants