Hold multiple Frames in Memory before sending them to AVAssetWriter

后端 未结 2 1858
夕颜
夕颜 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:51

    You're supposed to lock base address before accessing imageBuffer's properties.

    CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
    CVPixelBufferLockBaseAddress(imageBuffer, 0);
    uint8 *baseAddress = (uint8*)CVPixelBufferGetBaseAddress(imageBuffer);
    NSData *rawFrame = [[NSData alloc] initWithBytes:(void*)baseAddress length:(height * bytesPerRow)];
    [m_frameDataArray addObject:rawFrame];
    CVPixelBufferUnlockBaseAddress(imageBuffer, 0);
    

提交回复
热议问题