Create MDAT from I-frame/P-frame fragments

I am creating an MPEG-4 file from H.264 stream. H.264 stream comes in NAL format (EG: 0,0,0,1,67,...,0,0,1,68,...). Each video frame is transmitted as multiple I-frame/P-frame fragments. For eg: Fr...