Skip to content

Instantly share code, notes, and snippets.

@phucnm
Created February 29, 2016 05:06
Show Gist options
  • Save phucnm/59599cf4bae05bed284b to your computer and use it in GitHub Desktop.
Save phucnm/59599cf4bae05bed284b to your computer and use it in GitHub Desktop.
Record video from camera with AVAssetWriter
Sometimes, for some reason, you have to use AVAssetWriter to record videos from camera instead of using movile file output.
I had experienced some issue by that recording method due to lacking of tutorial and SO questions :))
Noted for everyone who met the issue: black first frame
if (CMSampleBufferDataIsReady(sampleBuffer)) {
if (videoWriter.status != AVAssetWriterStatusWriting) {
CMTime startTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
[videoWriter startWriting];
[videoWriter startSessionAtSourceTime:startTime];
}
if (writerInput.readyForMoreMediaData == YES) {
[writerInput appendSampleBuffer:sampleBuffer];
}
}
I had used if (writerInput.readyForMoreMediaData == YES) { before, so it leads to first frame can not be appended.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment