Skip to main content

Package for buffering frames in memory and sharing them between processes.

Project description

Overview

The FramesDepot class is designed to store and manage video frames in shared memory, allowing for controlled access and efficient frame management in asynchronous environments. It’s particularly useful in scenarios where frames need to be shared between different processes or handled at different rates.

Features

  • Fixed-size Queue: Holds a specified maximum number of frames.

  • Shared Memory: Utilizes shared memory for efficient inter-process communication.

  • Backpressure Management: Provides a callback mechanism to handle situations where the frame queue is full.

  • Asynchronous Support: Designed to work in an asynchronous environment, ensuring safe and efficient operations.

Usage

Initialization

frame_size = (width, height, channels)  # Dimensions of the frames
memory_name = "frame_depot"  # Name for the shared memory block
max_size = 10  # Maximum number of frames in the queue

frames_depot = FramesDepot(frame_size, memory_name, max_size)

Adding Frames

# Assume frame is a NumPy array representing a video frame and current_frame is an integer frame number
frame_dict = {"frame_number": current_frame, "frame": frame}
await frames_depot.enqueue(frame_dict)

Retrieving Frames

frame_number = 5  # The specific frame number you want to retrieve
frames_depot.get_frame(frame_number)

Handling Full Queue

Implement a backpressure_callback function that will be called when the queue is full.

def backpressure_callback():
    print("The queue is full. Consider slowing down frame production or handling the surplus.")

frames_depot = FramesDepot(frame_size, memory_name, max_size, backpressure_callback)

Clearing the Queue

await frames_depot.clear_queue()

Closing and Releasing Resources

await frames_depot.close()

Methods

  • __init__(frame_size, memory_name, max_size, backpressure_callback): Initializes the FramesDepot.

  • enqueue(frame_dict): Asynchronously adds a frame to the queue and shared memory.

  • get_frame(frame_number): Retrieves a specific frame by number.

  • clear_queue(): Asynchronously clears the frame queue and index.

  • close(): Asynchronously closes and releases all resources, including shared memory.

Properties

  • queue_is_full: Indicates whether the queue is full.

Requirements

  • Python 3.7+

  • NumPy

  • asyncio

Note

Ensure proper synchronization and error handling in your production environment, especially when dealing with shared resources and asynchronous operations.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gh-frames-depot-1.0.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gh_frames_depot-1.0.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file gh-frames-depot-1.0.0.tar.gz.

File metadata

  • Download URL: gh-frames-depot-1.0.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for gh-frames-depot-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1bae639ba23b6a3664fa3d3501a311746917c691ca08494cf2775cd6b977f726
MD5 5c2a36569bfd911c4eebfd28aaabf5d0
BLAKE2b-256 0243a0c08b95c82aa6d2033877dbb8f9cbd0519792b54e885ffccd84190b680a

See more details on using hashes here.

File details

Details for the file gh_frames_depot-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gh_frames_depot-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82ea738e6b73b268922a96403811bb78172afb120d1845100204044c56dee616
MD5 14d49bbad23b834ee4787358472afb7f
BLAKE2b-256 fd0e73bec25096333c7bbf6a13e5dbb469096cd70009792288b0e278e2bb642e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page