diff --git a/framework/Source/iOS/GPUImageMovieWriter.h b/framework/Source/iOS/GPUImageMovieWriter.h index f0b2c6ad8..069215413 100755 --- a/framework/Source/iOS/GPUImageMovieWriter.h +++ b/framework/Source/iOS/GPUImageMovieWriter.h @@ -64,4 +64,8 @@ extern NSString *const kGPUImageColorSwizzlingFragmentShaderString; - (void)processAudioBuffer:(CMSampleBufferRef)audioBuffer; - (void)enableSynchronizationCallbacks; +// Addition +- (void)pauseRecording; +- (void)resumeRecording; + @end diff --git a/framework/Source/iOS/GPUImageMovieWriter.m b/framework/Source/iOS/GPUImageMovieWriter.m index addc0a79a..c6b4893c4 100755 --- a/framework/Source/iOS/GPUImageMovieWriter.m +++ b/framework/Source/iOS/GPUImageMovieWriter.m @@ -36,6 +36,9 @@ @interface GPUImageMovieWriter () BOOL isRecording; } +// +@property (nonatomic,strong) NSDate *lastPauseTime; +@property (nonatomic,assign) NSTimeInterval accumulativeInterval; // Movie recording - (void)initializeMovieWithOutputSettings:(NSMutableDictionary *)outputSettings; @@ -80,6 +83,7 @@ - (id)initWithMovieURL:(NSURL *)newMovieURL size:(CGSize)newSize fileType:(NSStr return nil; } + _accumulativeInterval = 0.0; _shouldInvalidateAudioSampleWhenDone = NO; self.enabled = YES; @@ -692,6 +696,24 @@ - (void)renderAtInternalSizeUsingFramebuffer:(GPUImageFramebuffer *)inputFramebu glFinish(); } +#pragma mark - +#pragma mark Pause Recording And Resume + +- (void)pauseRecording { + isRecording = NO; + // + self.lastPauseTime = [NSDate date]; +} + +- (void)resumeRecording { + if (self.lastPauseTime) { + NSTimeInterval pass = [[NSDate date] timeIntervalSinceDate:self.lastPauseTime]; + self.accumulativeInterval += pass; + } + // + isRecording = YES; +} + #pragma mark - #pragma mark GPUImageInput protocol @@ -702,7 +724,12 @@ - (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex; [firstInputFramebuffer unlock]; return; } - + //fix the frame time + if (self.accumulativeInterval > 0) { + CMTime offset = CMTimeMake(self.accumulativeInterval*frameTime.timescale, frameTime.timescale); + frameTime = CMTimeSubtract(frameTime, offset); + } + // if (discont) { discont = NO; CMTime current;