Home > Software engineering >  Flush sink writer to prevent loading all samples into memory?
Flush sink writer to prevent loading all samples into memory?

Time:09-18

Is it possible to flush the current progress of the sink writer to file? Similar to IMFSinkWriter::Finalize, but allowing samples to still be written. Currently, I have to write all samples to the SinkWriter then finalize. However, this means all samples are required to be loaded into memory.

I am writing compressed H264 frames to an MP4 output container.

The IMFSinkWriter is attached to a IMFByteStream using MFCreateSinkWriterFromURL. I've tried IMFByteStream::Flush after each IMFSinkWriter::WriteSample, although this does not appear to do anything.

CodePudding user response:

Media Foundation sinks are not supposed to load samples into memory and hence the tagline question is incorrect in first place. There is no direct answer for this, or, if a short answer is needed, then the answer is "No".

Important part behind this challenge is the structure of the produced data stream (typically a file) and ability to interrupt it, then continue from mid-point. This behavior is format specific and so it is important to narrow down the question to the format of interest. You mentioned MP4 and Windows provides two sinks for MP4: for a regular MP4 file and for so called fragmented MP4 file. Neither of the two can be flushed and continued in the way that secondary piece is playable on its own.

Perhaps the easiest way to address the mentioned task of flushing and resuming from new file is implementation of custom Media Foundation Media Sink. This software item could either accumulate the data and "flush" by starting a secondary pipeline with real MP4 sink and hence an output file, or it could alternatively implement the MP4 related specification and produce boxes/atoms that constitute an MP4 file. Or, it can also embed some third party API or library to achieve a similar effect.

  • Related