Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. self.movieFile = [[GPUImageMovie alloc] initWithURL:self.assetURL];
  2. self.movieFile.runBenchmark = YES;
  3. self.movieFile.playAtActualSpeed = NO;
  4. self.filter = [[GPUImageLightenBlendFilter alloc] init];
  5.  
  6. [self.movieFile addTarget:self.filter];
  7.  
  8. NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/video.mp4"];
  9. unlink([pathToMovie UTF8String]); // If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie
  10. NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];
  11.  
  12. AVAssetTrack *videoAssetTrack = [[self.asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
  13. self.movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(videoAssetTrack.naturalSize.width, videoAssetTrack.naturalSize.height)];
  14. [self.filter addTarget:self.movieWriter];
  15.  
  16. // Configure this for video from the movie file, where we want to preserve all video frames and audio samples
  17. self.movieWriter.shouldPassthroughAudio = YES;
  18. self.movieFile.audioEncodingTarget = self.movieWriter;
  19. [self.movieFile enableSynchronizedEncodingUsingMovieWriter:self.movieWriter];
  20.  
  21. [self.movieWriter startRecording];
  22. [self.movieFile startProcessing];
  23.  
  24. __weak typeof(self) weakSelf = self;
  25. [self.movieWriter setCompletionBlock:^{
  26. [weakSelf.filter removeTarget:weakSelf.movieWriter];
  27. [weakSelf.movieWriter finishRecording];
  28.  
  29. dispatch_async(dispatch_get_main_queue(), ^{
  30. weakSelf.isFiltered = YES;
  31. weakSelf.filteredAsset = weakSelf.movieFile.asset;
  32.  
  33. weakSelf.playerItem = [AVPlayerItem playerItemWithAsset:weakSelf.movieFile.asset];
  34. weakSelf.player = [AVPlayer playerWithPlayerItem:weakSelf.playerItem];
  35. [weakSelf.playerView setPlayer:weakSelf.player];
  36. });
  37.  
  38.  
  39. }];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement