Guest User

Untitled

a guest
Jun 17th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. #import "SLSSimpleVideoFilterWindowController.h"
  2.  
  3. @interface SLSSimpleVideoFilterWindowController ()
  4.  
  5. @end
  6.  
  7. @implementation SLSSimpleVideoFilterWindowController
  8.  
  9.  
  10. - (void)windowDidLoad {
  11. [super windowDidLoad];
  12.  
  13. // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
  14.  
  15. // Instantiate video camera
  16. videoCamera = [[GPUImageAVCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraDevice:nil];
  17. videoCamera.runBenchmark = YES;
  18.  
  19. // Create filter and add it to target
  20. // filter = [[GPUImageSepiaFilter alloc] init];
  21. // [videoCamera addTarget:filter];
  22.  
  23. lineDetector = [[GPUImageHoughTransformLineDetector alloc] init];
  24. lineDetector.edgeThreshold = .2;
  25. lineDetector.lineDetectionThreshold = 0.2;
  26.  
  27. [videoCamera addTarget:lineDetector];
  28.  
  29. // Save video to desktop
  30. NSError *error = nil;
  31.  
  32. NSURL *pathToDesktop = [[NSFileManager defaultManager] URLForDirectory:NSDesktopDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:&error];
  33. NSURL *pathToMovieFile = [pathToDesktop URLByAppendingPathComponent:@"movie.mp4"];
  34. NSString *filePathString = [pathToMovieFile absoluteString];
  35. NSString *filePathSubstring = [filePathString substringFromIndex:7];
  36. unlink([filePathSubstring UTF8String]);
  37.  
  38. // Instantiate movie writer and add targets
  39. movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:pathToMovieFile size:CGSizeMake(640.0, 480.0)];
  40. movieWriter.encodingLiveVideo = YES;
  41.  
  42. self.videoView.fillMode = kGPUImageFillModePreserveAspectRatio;
  43. [lineDetector addTarget:movieWriter];
  44. [lineDetector addTarget:self.videoView];
  45.  
  46. // Start capturing
  47. [videoCamera startCameraCapture];
  48.  
  49. double delayToStartRecording = 0.5;
  50. dispatch_time_t startTime = dispatch_time(DISPATCH_TIME_NOW, delayToStartRecording * NSEC_PER_SEC);
  51. dispatch_after(startTime, dispatch_get_main_queue(), ^(void){
  52. NSLog(@"Start recording");
  53.  
  54. videoCamera.audioEncodingTarget = movieWriter;
  55. [movieWriter startRecording];
  56.  
  57. double delayInSeconds = 10.0;
  58. dispatch_time_t stopTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
  59. dispatch_after(stopTime, dispatch_get_main_queue(), ^(void){
  60.  
  61. [lineDetector removeTarget:movieWriter];
  62. videoCamera.audioEncodingTarget = nil;
  63. [movieWriter finishRecording];
  64. NSLog(@"Movie completed");
  65.  
  66. });
  67. });
  68.  
  69. }
  70.  
  71. @end
Add Comment
Please, Sign In to add comment