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

Cache video into the memory to increase frame read speed #89

Open
pozitronik opened this issue Nov 4, 2023 · 0 comments
Open

Cache video into the memory to increase frame read speed #89

pozitronik opened this issue Nov 4, 2023 · 0 comments
Assignees
Labels
dev 🧑‍💻Developer issues (todos, experiments, styling, etc)

Comments

@pozitronik
Copy link
Owner

Something like

import cv2
import io

class MemoryStream:
    def __init__(self, data):
        self.buffer = io.BytesIO(data)

    def read(self, size=-1):
        return self.buffer.read(size)

    def seek(self, offset, whence=0):
        return self.buffer.seek(offset, whence)

    def tell(self):
        return self.buffer.tell()


with open('your_video.mp4', 'rb') as video_file:
    video_data = video_file.read()

memory_file_object = MemoryStream(video_data)
cap = cv2.VideoCapture(memory_file_object)
@pozitronik pozitronik added the dev 🧑‍💻Developer issues (todos, experiments, styling, etc) label Nov 4, 2023
@pozitronik pozitronik self-assigned this Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev 🧑‍💻Developer issues (todos, experiments, styling, etc)
Projects
None yet
Development

No branches or pull requests

1 participant