Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- self.movieFile = [[GPUImageMovie alloc] initWithURL:self.assetURL];
- self.movieFile.runBenchmark = YES;
- self.movieFile.playAtActualSpeed = NO;
- self.filter = [[GPUImageLightenBlendFilter alloc] init];
- [self.movieFile addTarget:self.filter];
- NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/video.mp4"];
- unlink([pathToMovie UTF8String]); // If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie
- NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];
- AVAssetTrack *videoAssetTrack = [[self.asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
- self.movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(videoAssetTrack.naturalSize.width, videoAssetTrack.naturalSize.height)];
- [self.filter addTarget:self.movieWriter];
- // Configure this for video from the movie file, where we want to preserve all video frames and audio samples
- self.movieWriter.shouldPassthroughAudio = YES;
- self.movieFile.audioEncodingTarget = self.movieWriter;
- [self.movieFile enableSynchronizedEncodingUsingMovieWriter:self.movieWriter];
- [self.movieWriter startRecording];
- [self.movieFile startProcessing];
- __weak typeof(self) weakSelf = self;
- [self.movieWriter setCompletionBlock:^{
- [weakSelf.filter removeTarget:weakSelf.movieWriter];
- [weakSelf.movieWriter finishRecording];
- dispatch_async(dispatch_get_main_queue(), ^{
- weakSelf.isFiltered = YES;
- weakSelf.filteredAsset = weakSelf.movieFile.asset;
- weakSelf.playerItem = [AVPlayerItem playerItemWithAsset:weakSelf.movieFile.asset];
- weakSelf.player = [AVPlayer playerWithPlayerItem:weakSelf.playerItem];
- [weakSelf.playerView setPlayer:weakSelf.player];
- });
- }];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement