Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

Buffering issues with muxer

moti_bot
Beginner
461 Views
Hello,

I'm facing some interesting issue with MP4Muxer class.

I use the muxer to save encoded frames (from encoder), most of the flow (adding frames)goes fine, but there are points where the muxer is crashing - sometimes in the end ("mux.Close();"), when the final MP4 file is created or even in the middle of saving buffers.
After some investigation and changing some fields I found out that this is related to buffering configuration of the muxer.

- Following that, what are the guidelines for buffering configuration with the muxer?

I use the following code to init the muxer:
[cpp]mp.pTrackParams[0].bufferParams.m_numberOfFrames = 30;
mp.pTrackParams[0].bufferParams.m_prefInputBufferSize = 1000000;
mp.pTrackParams[0].bufferParams.m_prefOutputBufferSize = 1000000;[/cpp]


The input video is 720x576, 25 FPS, bitrate of 2 Mbps.

I tested two ways with the muxer.

1. Using muxer internal buffers (Lock/Unlock):
[cpp]UMC::MediaData temp;
mux.LockBuffer(&temp, 0);
memcpy(temp.GetBufferPointer(), data, size);
temp.SetDataSize(size);
temp.SetTime(frameCounter * 1.0 / framerate);
mux.UnlockBuffer(&temp, 0);[/cpp]


2. Using external buffer:
[cpp]md.Reset(); // MediaData obj
md.SetBufferPointer(data, size);
md.SetDataSize(size);
md.SetTime(frameCounter * 1.0 / framerate);

mux.PutData(&md, 0);[/cpp]


Both work when everything is fine, and both don't work when it is not.
It is also important to note, that depends on the configuration of the buffering, not all data is written to disk.
I found myself trying to find out how a file becomes so small, and then figured that frames were missing. Increasing the buffering sizes (buffer size or frames number) made the file become bigger, still, calling mux.Close(); failed (at writing the header).

I would appreciate any comment and generalization of the above, since the above inputs are only one caseI use.

Thanks,
Moti.
0 Kudos
2 Replies
Sergey_O_Intel1
Employee
461 Views
prefInput and Output sizes should comply with data size you're going to keep in the buffer. Return statuses of methods of MediaBuffer class (NOT_ENOUGH_BUFFER, NOT_ENOUGH_DATA) depend on these values. MP4Muxer uses Sample buffer that is why Input and Output sizes are the same. Input size isthe max size of data portion one puts into the buffer, Output size the min size when data can be recieved (though it's more important for linear buffers). BTW this is described in the manual.

Usually one creates a buffer to keep 5-10 frames for multiplexing. In your case it can be about

2000000/25=80000kBits per frame = 10kB/fr, so let it be 20000 (to make sure)for Input and Output size

Regarding any bugs I can't help here. IPP sample is not a ready solution. You can improve it as you like.
But to say the truth I've never heard about the problem you describe.
0 Kudos
moti_bot
Beginner
461 Views
prefInput and Output sizes should comply with data size you're going to keep in the buffer. Return statuses of methods of MediaBuffer class (NOT_ENOUGH_BUFFER, NOT_ENOUGH_DATA) depend on these values. MP4Muxer uses Sample buffer that is why Input and Output sizes are the same. Input size isthe max size of data portion one puts into the buffer, Output size the min size when data can be recieved (though it's more important for linear buffers). BTW this is described in the manual.

Usually one creates a buffer to keep 5-10 frames for multiplexing. In your case it can be about

2000000/25=80000kBits per frame = 10kB/fr, so let it be 20000 (to make sure)for Input and Output size

Regarding any bugs I can't help here. IPP sample is not a ready solution. You can improve it as you like.
But to say the truth I've never heard about the problem you describe.

Hi Sergey,

Thanks for your response.
I have tried it and tested under some circumstances.
The buffer were configured with enough space (1 MB per frame), it seems that all the frames were written, but again, when reaching the point of closing the file, "finalization", the function crashes while updating/writing the headers of the file.
It happens in every configuration of the muxer (w/out start with headers, fragmented, etc.)

Do you have any insight about this?
I will try to start from scratch to investigate it further.
BTW, the H.264 stream is valid and fine.

Thanks,
Moti.
0 Kudos
Reply