@@ -32,6 +32,8 @@ @interface LFVideoCapture ()
32
32
@property (nonatomic , strong ) GPUImageUIElement *uiElementInput;
33
33
@property (nonatomic , strong ) UIView *waterMarkContentView;
34
34
35
+ @property (nonatomic , strong ) GPUImageMovieWriter *movieWriter;
36
+
35
37
@end
36
38
37
39
@implementation LFVideoCapture
@@ -88,10 +90,12 @@ - (void)setRunning:(BOOL)running {
88
90
if (!_running) {
89
91
[UIApplication sharedApplication ].idleTimerDisabled = NO ;
90
92
[self .videoCamera stopCameraCapture ];
93
+ if (self.saveLocalVideo ) [self .movieWriter finishRecording ];
91
94
} else {
92
95
[UIApplication sharedApplication ].idleTimerDisabled = YES ;
93
96
[self reloadFilter ];
94
97
[self .videoCamera startCameraCapture ];
98
+ if (self.saveLocalVideo ) [self .movieWriter startRecording ];
95
99
}
96
100
}
97
101
@@ -252,6 +256,16 @@ -(UIImage *)currentImage{
252
256
return nil ;
253
257
}
254
258
259
+ - (GPUImageMovieWriter*)movieWriter {
260
+ if (!_movieWriter){
261
+ _movieWriter = [[GPUImageMovieWriter alloc ] initWithMovieURL: self .saveLocalVideoPath size: self .configuration.videoSize];
262
+ _movieWriter.encodingLiveVideo = YES ;
263
+ _movieWriter.shouldPassthroughAudio = YES ;
264
+ self.videoCamera .audioEncodingTarget = self.movieWriter ;
265
+ }
266
+ return _movieWriter;
267
+ }
268
+
255
269
#pragma mark -- Custom Method
256
270
- (void )processVideo : (GPUImageOutput *)output {
257
271
__weak typeof (self) _self = self;
@@ -300,11 +314,13 @@ - (void)reloadFilter{
300
314
[self .filter addTarget: self .blendFilter];
301
315
[self .uiElementInput addTarget: self .blendFilter];
302
316
[self .blendFilter addTarget: self .gpuImageView];
317
+ if (self.saveLocalVideo ) [self .blendFilter addTarget: self .movieWriter];
303
318
[self .filter addTarget: self .output];
304
319
[self .uiElementInput update ];
305
320
}else {
306
321
[self .filter addTarget: self .output];
307
322
[self .output addTarget: self .gpuImageView];
323
+ if (self.saveLocalVideo ) [self .output addTarget: self .movieWriter];
308
324
}
309
325
310
326
[self .filter forceProcessingAtSize: self .configuration.videoSize];
0 commit comments