Created
February 29, 2016 05:06
-
-
Save phucnm/59599cf4bae05bed284b to your computer and use it in GitHub Desktop.
Record video from camera with AVAssetWriter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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