Skip to content

Instantly share code, notes, and snippets.

@pita5
Created September 5, 2012 12:33
Show Gist options
  • Save pita5/3635925 to your computer and use it in GitHub Desktop.
Save pita5/3635925 to your computer and use it in GitHub Desktop.
[audioReader startReading];
// Go back to the beginning of the video to append the audio
[videoWriter startSessionAtSourceTime:kCMTimeZero];
// Get the next block of date of the audio
CMSampleBufferRef sample;
// Keep appending the audio as it becomes ready
while ((sample = [readerOutput copyNextSampleBuffer]))
{
// Wait for the audio writer to be ready
while (![audioWriterInput isReadyForMoreMediaData]) {}
// Append to audio writer with input
[audioWriterInput appendSampleBuffer:sample];
// Cleanup
CFRelease(sample);
sample = NULL;
}
// Finish the video at the source time
[videoWriter endSessionAtSourceTime:CMTimeMake(duration-1, 2)];
// Finish
[videoWriter finishWriting];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment