Hold multiple Frames in Memory before sending them to AVAssetWriter

后端 未结 2 1857
夕颜
夕颜 2021-02-10 01:19

I need to hold some video frames from a captureSession in memory and write them to a file when \'something\' happens.

Similar to this solution, i use this code to put a

2条回答
  •  孤城傲影
    2021-02-10 01:42

    This is pretty old, but to help those that come after, there's a few issues to be fixed:

    1. Lock/unlock the base address when you copy out as suggested by Alex's answer
    2. CVImageBufferRef is an abstract base class type. You want to use CVPixelBufferCreateWithBytes to make an instance, not just typecast the raw pixel bytes. (The system needs to know the size/format of those pixels)
    3. You should create and store the new CVPixelBuffer directly from the original one's data instead of using an intermediary NSData for storage. That way you only have to do one copy instead of two.

提交回复
热议问题