Skip to content

Commit aa4f259

Browse files
author
chenliming
committed
save video to local for mp4
1 parent bc5dcef commit aa4f259

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

LFLiveKit/LFLiveSession.h

+8
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,15 @@ typedef NS_ENUM(NSInteger,LFLiveCaptureTypeMask) {
127127
*.*/
128128
@property (nonatomic, strong, nullable) UIView *warterMarkView;
129129

130+
/* The currentImage is videoCapture shot */
130131
@property (nonatomic, strong,readonly ,nullable) UIImage *currentImage;
132+
133+
/* The saveLocalVideo is save the local video */
134+
@property (nonatomic, assign) BOOL saveLocalVideo;
135+
136+
/* The saveLocalVideoPath is save the local video path */
137+
@property (nonatomic, strong, nullable) NSURL *saveLocalVideoPath;
138+
131139
#pragma mark - Initializer
132140
///=============================================================================
133141
/// @name Initializer

LFLiveKit/LFLiveSession.m

+17
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,23 @@ - (void)setBeautyFace:(BOOL)beautyFace {
251251
[self didChangeValueForKey:@"beautyFace"];
252252
}
253253

254+
- (BOOL)saveLocalVideo{
255+
return self.videoCaptureSource.saveLocalVideo;
256+
}
257+
258+
- (void)setSaveLocalVideo:(BOOL)saveLocalVideo{
259+
[self.videoCaptureSource setSaveLocalVideo:saveLocalVideo];
260+
}
261+
262+
263+
- (NSURL*)saveLocalVideoPath{
264+
return self.videoCaptureSource.saveLocalVideoPath;
265+
}
266+
267+
- (void)setSaveLocalVideoPath:(NSURL*)saveLocalVideoPath{
268+
[self.videoCaptureSource setSaveLocalVideoPath:saveLocalVideoPath];
269+
}
270+
254271
- (BOOL)beautyFace {
255272
return self.videoCaptureSource.beautyFace;
256273
}

LFLiveKit/capture/LFVideoCapture.h

+8
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,15 @@
6464
/*** The warterMarkView control whether the watermark is displayed or not ,if set ni,will remove watermark,otherwise add *.*/
6565
@property (nonatomic, strong, nullable) UIView *warterMarkView;
6666

67+
/* The currentImage is videoCapture shot */
6768
@property (nonatomic, strong, nullable) UIImage *currentImage;
69+
70+
/* The saveLocalVideo is save the local video */
71+
@property (nonatomic, assign) BOOL saveLocalVideo;
72+
73+
/* The saveLocalVideoPath is save the local video path */
74+
@property (nonatomic, strong, nullable) NSURL *saveLocalVideoPath;
75+
6876
#pragma mark - Initializer
6977
///=============================================================================
7078
/// @name Initializer

LFLiveKit/capture/LFVideoCapture.m

+16
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ @interface LFVideoCapture ()
3232
@property (nonatomic, strong) GPUImageUIElement *uiElementInput;
3333
@property (nonatomic, strong) UIView *waterMarkContentView;
3434

35+
@property (nonatomic, strong) GPUImageMovieWriter *movieWriter;
36+
3537
@end
3638

3739
@implementation LFVideoCapture
@@ -88,10 +90,12 @@ - (void)setRunning:(BOOL)running {
8890
if (!_running) {
8991
[UIApplication sharedApplication].idleTimerDisabled = NO;
9092
[self.videoCamera stopCameraCapture];
93+
if(self.saveLocalVideo) [self.movieWriter finishRecording];
9194
} else {
9295
[UIApplication sharedApplication].idleTimerDisabled = YES;
9396
[self reloadFilter];
9497
[self.videoCamera startCameraCapture];
98+
if(self.saveLocalVideo) [self.movieWriter startRecording];
9599
}
96100
}
97101

@@ -252,6 +256,16 @@ -(UIImage *)currentImage{
252256
return nil;
253257
}
254258

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+
255269
#pragma mark -- Custom Method
256270
- (void)processVideo:(GPUImageOutput *)output {
257271
__weak typeof(self) _self = self;
@@ -300,11 +314,13 @@ - (void)reloadFilter{
300314
[self.filter addTarget:self.blendFilter];
301315
[self.uiElementInput addTarget:self.blendFilter];
302316
[self.blendFilter addTarget:self.gpuImageView];
317+
if(self.saveLocalVideo) [self.blendFilter addTarget:self.movieWriter];
303318
[self.filter addTarget:self.output];
304319
[self.uiElementInput update];
305320
}else{
306321
[self.filter addTarget:self.output];
307322
[self.output addTarget:self.gpuImageView];
323+
if(self.saveLocalVideo) [self.output addTarget:self.movieWriter];
308324
}
309325

310326
[self.filter forceProcessingAtSize:self.configuration.videoSize];

LFLiveKitDemo/LFLiveKitDemo/LFLivePreview.m

+7
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,13 @@ - (LFLiveSession *)session {
255255
_session.showDebugInfo = NO;
256256
_session.preView = self;
257257

258+
/*本地存储*/
259+
// _session.saveLocalVideo = YES;
260+
// NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.mp4"];
261+
// unlink([pathToMovie UTF8String]); // If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie
262+
// NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];
263+
// _session.saveLocalVideoPath = movieURL;
264+
258265
UIImageView *imageView = [[UIImageView alloc] init];
259266
imageView.alpha = 0.8;
260267
imageView.frame = CGRectMake(100, 100, 29, 29);

0 commit comments

Comments
 (0)