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

Extract images from a video as numpy #63

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

Extract images from a video as numpy #63

srikanthsridar opened this issue Jan 25, 2018 · 7 comments
Labels

Comments

@srikanthsridar
Copy link

Hello kkroening,
Is it possible to use ffmpeg extracted frames in jpg to numpy using ffmpeg-python?

@depau depau added the question label Jan 25, 2018
@depau
Copy link
Collaborator

depau commented Jan 25, 2018

If you run ffmpeg manually with subprocess you can read (write) from (to) any pipe of the process.

Check this code from the tests.

Note that a .compile() operator has been added, which returns the command line arguments ready for subprocess, i.e.:

p = subprocess.Popen(out.compile(), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = p.stdout.read()

You may also want to check this out.

@srikanthsridar
Copy link
Author

Sure thank you.Will check this and get back to you.

@srikanthsridar
Copy link
Author

Between is it possible to mention image format as "jpg" or "png" in ffmpeg in extraction step?

@srikanthsridar
Copy link
Author

I am able to pipe the images but the image size(file size) in RAM is more than the jpg extraction.I will be reading thousands of files so I need in compressed format like jpg.Any thoughts on this?

@depau
Copy link
Collaborator

depau commented Jan 25, 2018

You should check the ffmpeg documentation. I'm pretty sure there's an encoder for jpeg but I don't remember how it works off the top of my head.
See here if you can find anything: https://ffmpeg.org/ffmpeg-all.html

@kkroening
Copy link
Owner

Here's an example in Jupyter notebook:

screen shot 2018-06-01 at 11 19 40 pm

I'll post the notebook file in the examples soon.

@kkroening
Copy link
Owner

kkroening commented Jun 2, 2018

If you want to read individual frames as jpg:

def read_frame_as_jpg(in_filename, frame_num):
    out, err = (
        ffmpeg
        .input(in_filename)
        .filter_('select', 'gte(n,{})'.format(frame_num))
        .output('pipe:', vframes=1, format='image2', vcodec='mjpeg')
        .run(capture_stdout=True)
    )
    return out

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

No branches or pull requests

3 participants