If you don’t want to use CMPSampleBufferCreateWithText you can roll your own similar to https://yhf8377.medium.com/quicktime-movie-editing-using-avfoundation-and-swift-5-33965c522abc (code flow is basically the same in any language)
But the real reason I’m writing here is to reference this How to create a CMBlockBufferRef from NSData
The data ownership is not quite apparent as writing the same buf happens later possibly in another scope. So if you’ve constructed an NSData it could be deallocated before the sample buffer is written which ends up with a chapter that has no title. Spent a long time on this but you need to pass the ownership as the data is referenced and not copied in.