Skip to content

OCVWarp-ffmpeg.cpp initial commit runs only at 3fps #33

@hn-88

Description

@hn-88

Possibly due to I/O being synchronous, so the input and output threads block each other while they work. To try Gemini's suggestion:

Here is a conceptual overview and a detailed code snippet for implementing asynchronous I/O with threads in your C++ application.

The Strategy: Producer-Consumer Model

  1. Thread-Safe Queue: We will create a queue that can be safely accessed by multiple threads. This queue will hold the processed cv::Mat frames that are ready to be written.
  2. Main Thread (The Producer): This thread will perform its original job:
  • Read a frame from the video source.
  • Process and remap the frame.
  • Instead of writing the frame directly to the pipe, it will push the processed frame into the thread-safe queue.
  1. Writer Thread (The Consumer): This new thread will run a simple loop:
  • Pop a frame from the thread-safe queue. (It will wait automatically if the queue is empty).
  • Write that frame's data to the FFmpeg pipe.
    This architecture allows the main thread to immediately start processing the next frame as soon as it has pushed the previous one to the queue, while the writer thread independently handles the potentially blocking I/O operation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions