io

I/O for files and SDCards

class mio.io.BufferedCSVWriter(file_path: str | Path, header: list[str], buffer_size: int = 100, force: bool = False)

Write data to a CSV file in buffered mode.

Parameters:
  • file_path (Union[str, Path]) – The file path for the CSV file.

  • headers (list[str]) – Headers for csv - determine the order of columns and allowable values passed to append()

  • buffer_size (int, optional) – The number of rows to buffer before writing to the file (default is 100).

  • force (bool) – If True, remove any existing file and start a new one

file_path

The file path for the CSV file.

Type:

Path

buffer_size

The number of rows to buffer before writing to the file.

Type:

int

buffer

The buffer for storing rows before writing.

Type:

list

append(data: dict) None

Append data (as a list) to the buffer.

Parameters:

data (dict) – The data to be appended. Rows are constructed and columns are ordered according to header - keys that are not in header are ignored, and missing keys are None

close() None

Close the CSV file and flush any remaining data.

flush_buffer() None

Write all buffered rows to the CSV file.

class mio.io.VideoReader(video_path: str)

A class to read video files.

property cap: VideoCapture

The OpenCV video capture object.

property frame_count: int

Total number of frames in the video.

property height: int

The height of the video frames.

read_frame(index: int) ndarray | None

Read a frame from the video file.

read_frames() Iterator[tuple[int, ndarray]]

Read frames from the video file along with their index.

Yields: tuple[int, np.ndarray]: The 0-based index and the frame data.

release() None

Release the video capture object.

property width: int

The width of the video frames.

class mio.io.VideoWriter(path: str | Path, fps: int, output_dict: dict | None = None, force: bool = False)

Write data to a video file using FFMpegWriter.

DEFAULT_OUTPUT = {'-f': 'avi', '-pix_fmt': 'gray', '-vcodec': 'rawvideo', '-vsync': '0'}
close() None

Close the video file.

write_frame(frame: ndarray) bool

Write a frame to the video file.

Parameters: frame (np.ndarray): The frame to write.