Pass an open pipeline from C++ to Matlab

3 views (last 30 days)
Doron Joffe
Doron Joffe on 12 Dec 2022
Answered: Harsh Sanghai on 23 Mar 2023
I have created a Mex function that opens an FFMPEG streaming pipeline. I need this open pipeline to be passed as an input to a second Mex function which processes video frames and writes the output to the open pipeline. My ideal workflow is as follows:
Open the pipeline in the 1st Mex function. Pass this open pipeline back into Matlab. Create a While loop to process video frames and generate bounding boxes. Call a second Mex function within the loop which takes the open pipeline as input together with a frame and writes the output to an RTSP server.
The problem is that I currently can't pass the open pipeline from my first Mex function to a Matlab variable. The data type of the open pipeline is a File and the error I get is:
note: while trying to match the argument list '(matlab::data::Array, FILE *)'.
I use the c++ function _popen to open the pipeline and according to the documentation, _popen() returns a pointer to an open stream that can be used to read or write to the pipe.
Is there a way to somehow pass an open pipeline to a matlab variable?

Answers (1)

Harsh Sanghai
Harsh Sanghai on 23 Mar 2023
It is not possible to pass an open pipeline (a FILE pointer) directly to a MATLAB variable using MATLAB's built-in data types. However, you can create a custom MATLAB data type that wraps the FILE pointer and pass that custom data type between the two MEX functions.
You can follow the steps mention below to obtain this:
  1. Create a custom MATLAB data type that wraps the FILE pointer.
  2. Allocate and return an instance of the custom data type from the 1st Mex function.
  3. Accept the custom data type as an input to the 2nd Mex function.
  4. Unwrap the custom data type in the 1st Mex function to obtain the FILE pointer.


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!