Manually record oni files frame by frame with OpenNI2

Hi,
This is the scenario I’d like to achieve… from a continuous stream record 5 minute chunks of .oni files. To do this without loosing any frame I can’t use the recorder class, because the time spent to close and reopen the oni files will make me loose some frames, depending on the computer performance. I’d use a multithread approach, one thread grab the frames and put in a buffer, another thread read from the buffer and save to a oni file, when the oni file reach five minutes (just an example), close the file and open a new one…
I already used this approach to save the color stream, but what about the depth stream? I canno’t simply convert to images, otherwise I will loose all the metadata related to frame and the device too…
I haven’t found anything on the web, do you have any idea?