Skip to content

Commit 829b1ce

Browse files
committed
SCAssetExportSession is now fully multithreaded.
1 parent 0c0d986 commit 829b1ce

File tree

9 files changed

+419
-140
lines changed

9 files changed

+419
-140
lines changed

Examples/ObjC/Sources/SCRecorderViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ - (void)viewDidLoad {
7070

7171
_recorder = [SCRecorder recorder];
7272
_recorder.captureSessionPreset = [SCRecorderTools bestCaptureSessionPresetCompatibleWithAllDevices];
73-
_recorder.maxRecordDuration = CMTimeMake(10, 1);
73+
// _recorder.maxRecordDuration = CMTimeMake(10, 1);
7474
// _recorder.fastRecordMethodEnabled = YES;
7575

7676
_recorder.delegate = self;

Examples/ObjC/Sources/SCVideoPlayerViewController.m

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,15 @@ - (void)viewDidLoad
9797
[self createAnimatedFilter]
9898
];
9999
_player.CIImageRenderer = self.filterSwitcherView;
100+
[self.filterSwitcherView addObserver:self forKeyPath:@"selectedFilter" options:NSKeyValueObservingOptionNew context:nil];
100101
} else {
101102
SCVideoPlayerView *playerView = [[SCVideoPlayerView alloc] initWithPlayer:_player];
103+
playerView.playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
102104
playerView.frame = self.filterSwitcherView.frame;
103105
playerView.autoresizingMask = self.filterSwitcherView.autoresizingMask;
104106
[self.filterSwitcherView.superview insertSubview:playerView aboveSubview:self.filterSwitcherView];
105107
[self.filterSwitcherView removeFromSuperview];
106108
}
107-
[self.filterSwitcherView addObserver:self forKeyPath:@"selectedFilter" options:NSKeyValueObservingOptionNew context:nil];
108109

109110
_player.loopEnabled = YES;
110111
}
@@ -162,24 +163,21 @@ - (void)assetExportSessionDidProgress:(SCAssetExportSession *)assetExportSession
162163
dispatch_async(dispatch_get_main_queue(), ^{
163164
float progress = assetExportSession.progress;
164165

165-
[UIView animateWithDuration:0.1 animations:^{
166-
CGRect frame = self.progressView.frame;
167-
frame.size.width = self.progressView.superview.frame.size.width * progress;
168-
self.progressView.frame = frame;
169-
}];
166+
CGRect frame = self.progressView.frame;
167+
frame.size.width = self.progressView.superview.frame.size.width * progress;
168+
self.progressView.frame = frame;
170169
});
171170
}
172171

173172
- (void)saveToCameraRoll {
174-
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
175173
SCFilter *currentFilter = self.filterSwitcherView.selectedFilter;
174+
[_player pause];
176175

177176
void(^completionHandler)(NSURL *url, NSError *error) = ^(NSURL *url, NSError *error) {
178177
if (error == nil) {
178+
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
179179
UISaveVideoAtPathToSavedPhotosAlbum(url.path, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
180180
} else {
181-
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
182-
183181
[[[UIAlertView alloc] initWithTitle:@"Failed to save" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
184182
}
185183
};
@@ -208,20 +206,13 @@ - (void)saveToCameraRoll {
208206
SCWatermarkOverlayView *overlay = [SCWatermarkOverlayView new];
209207
overlay.date = self.recordSession.date;
210208
exportSession.videoConfiguration.overlay = overlay;
211-
212-
// UIGraphicsBeginImageContext(label.frame.size);
213-
//
214-
// [label.layer renderInContext:UIGraphicsGetCurrentContext()];
215-
//
216-
// UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
217-
//
218-
// UIGraphicsEndImageContext();
219-
//
220-
// exportSession.videoConfiguration.watermarkImage = image;
221-
// exportSession.videoConfiguration.watermarkFrame = CGRectMake(10, 10, label.frame.size.width, label.frame.size.height);
222-
// exportSession.videoConfiguration.watermarkAnchorLocation = SCWatermarkAnchorLocationBottomRight;
223-
209+
210+
CFTimeInterval time = CACurrentMediaTime();
224211
[exportSession exportAsynchronouslyWithCompletionHandler:^{
212+
[_player play];
213+
214+
NSLog(@"Completed compression in %fs", CACurrentMediaTime() - time);
215+
225216
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
226217

227218
[UIView animateWithDuration:0.3 animations:^{

Library/SCRecorder.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
DCBA8FE71A92B2FF00DD1A79 /* SCRecorderToolsView.m in Sources */ = {isa = PBXBuildFile; fileRef = DCBA8FE51A92B2FF00DD1A79 /* SCRecorderToolsView.m */; };
6262
DCC1FC491A4AF1DD00F1C653 /* SCRecorderTools.h in Headers */ = {isa = PBXBuildFile; fileRef = DCC1FC471A4AF1DD00F1C653 /* SCRecorderTools.h */; settings = {ATTRIBUTES = (Public, ); }; };
6363
DCC1FC4A1A4AF1DD00F1C653 /* SCRecorderTools.m in Sources */ = {isa = PBXBuildFile; fileRef = DCC1FC481A4AF1DD00F1C653 /* SCRecorderTools.m */; };
64+
DCD12A9F1B456C5E0064674D /* SCProcessingQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = DCD12A9D1B456C5E0064674D /* SCProcessingQueue.h */; };
65+
DCD12AA01B456C5E0064674D /* SCProcessingQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = DCD12A9E1B456C5E0064674D /* SCProcessingQueue.m */; };
66+
DCD12AA41B45AA540064674D /* SCIOPixelBuffers.h in Headers */ = {isa = PBXBuildFile; fileRef = DCD12AA21B45AA540064674D /* SCIOPixelBuffers.h */; };
67+
DCD12AA51B45AA540064674D /* SCIOPixelBuffers.m in Sources */ = {isa = PBXBuildFile; fileRef = DCD12AA31B45AA540064674D /* SCIOPixelBuffers.m */; };
6468
DCDC1DF81AC79592001DC3D9 /* SCRecorderFramework.h in Headers */ = {isa = PBXBuildFile; fileRef = DCDC1DF71AC79592001DC3D9 /* SCRecorderFramework.h */; settings = {ATTRIBUTES = (Public, ); }; };
6569
DCDC1E161AC797EF001DC3D9 /* SCVideoConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = DCA163941A2028B800505966 /* SCVideoConfiguration.m */; };
6670
DCDC1E171AC797EF001DC3D9 /* SCAudioConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = DCA163981A2028C400505966 /* SCAudioConfiguration.m */; };
@@ -189,6 +193,10 @@
189193
DCC1FC481A4AF1DD00F1C653 /* SCRecorderTools.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SCRecorderTools.m; sourceTree = "<group>"; };
190194
DCCAB6AB17B46C8900CEA47B /* SCAudioTools.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SCAudioTools.h; sourceTree = "<group>"; };
191195
DCCAB6AC17B46C8900CEA47B /* SCAudioTools.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SCAudioTools.m; sourceTree = "<group>"; };
196+
DCD12A9D1B456C5E0064674D /* SCProcessingQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SCProcessingQueue.h; sourceTree = "<group>"; };
197+
DCD12A9E1B456C5E0064674D /* SCProcessingQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SCProcessingQueue.m; sourceTree = "<group>"; };
198+
DCD12AA21B45AA540064674D /* SCIOPixelBuffers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SCIOPixelBuffers.h; sourceTree = "<group>"; };
199+
DCD12AA31B45AA540064674D /* SCIOPixelBuffers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SCIOPixelBuffers.m; sourceTree = "<group>"; };
192200
DCDC1DF31AC79592001DC3D9 /* SCRecorder.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SCRecorder.framework; sourceTree = BUILT_PRODUCTS_DIR; };
193201
DCDC1DF61AC79592001DC3D9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
194202
DCDC1DF71AC79592001DC3D9 /* SCRecorderFramework.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SCRecorderFramework.h; sourceTree = "<group>"; };
@@ -371,6 +379,10 @@
371379
DCC1FC481A4AF1DD00F1C653 /* SCRecorderTools.m */,
372380
DC10CF261ACFD458009880C4 /* SCWeakSelectorTarget.h */,
373381
DC10CF271ACFD458009880C4 /* SCWeakSelectorTarget.m */,
382+
DCD12A9D1B456C5E0064674D /* SCProcessingQueue.h */,
383+
DCD12A9E1B456C5E0064674D /* SCProcessingQueue.m */,
384+
DCD12AA21B45AA540064674D /* SCIOPixelBuffers.h */,
385+
DCD12AA31B45AA540064674D /* SCIOPixelBuffers.m */,
374386
);
375387
name = Tools;
376388
sourceTree = "<group>";
@@ -492,7 +504,9 @@
492504
DC10CF281ACFD458009880C4 /* SCWeakSelectorTarget.h in Headers */,
493505
DCEE378A1B17E6480019C7B5 /* SCContext.h in Headers */,
494506
DCC1FC491A4AF1DD00F1C653 /* SCRecorderTools.h in Headers */,
507+
DCD12A9F1B456C5E0064674D /* SCProcessingQueue.h in Headers */,
495508
DC4CBA4D1863118E00532F1F /* SCAudioTools.h in Headers */,
509+
DCD12AA41B45AA540064674D /* SCIOPixelBuffers.h in Headers */,
496510
DC1949C019C07F1600E92A95 /* SCSampleBufferHolder.h in Headers */,
497511
);
498512
runOnlyForDeploymentPostprocessing = 0;
@@ -656,6 +670,8 @@
656670
DCA163961A2028B800505966 /* SCVideoConfiguration.m in Sources */,
657671
DCEE378B1B17E6480019C7B5 /* SCContext.m in Sources */,
658672
DC50285818E51FC0004E833F /* SCRecorder.m in Sources */,
673+
DCD12AA01B456C5E0064674D /* SCProcessingQueue.m in Sources */,
674+
DCD12AA51B45AA540064674D /* SCIOPixelBuffers.m in Sources */,
659675
DC7A62C01AFA47EC00EAB60C /* SCFilterAnimation.m in Sources */,
660676
DCB0415A192458C800D945D2 /* SCImageView.m in Sources */,
661677
DCA163A41A23C7C300505966 /* SCPhotoConfiguration.m in Sources */,

Library/Sources/SCAssetExportSession.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,4 @@
8585
*/
8686
- (void)exportAsynchronouslyWithCompletionHandler:(void(^__nullable)())completionHandler;
8787

88-
89-
//////////////////
90-
// PRIVATE API
91-
////
92-
93-
// These are only exposed for inheritance purpose
94-
@property (readonly, nonatomic) __nonnull dispatch_queue_t dispatchQueue;
95-
@property (readonly, nonatomic) __nonnull dispatch_group_t dispatchGroup;
96-
@property (readonly, nonatomic) AVAssetWriterInput *__nullable audioInput;
97-
@property (readonly, nonatomic) AVAssetWriterInput *__nullable videoInput;
98-
99-
- (void)markInputComplete:(AVAssetWriterInput *__nonnull)input error:(NSError *__nullable)error;
100-
- (BOOL)processSampleBuffer:(__nonnull CMSampleBufferRef)sampleBuffer;
101-
- (BOOL)processPixelBuffer:(__nonnull CVPixelBufferRef)pixelBuffer presentationTime:(CMTime)presentationTime;
102-
- (void)beginReadWriteOnInput:(AVAssetWriterInput *__nonnull)input fromOutput:(AVAssetReaderOutput *__nonnull)output;
103-
- (BOOL)needsInputPixelBufferAdaptor;
104-
10588
@end

0 commit comments

Comments
 (0)