GPUImageGrayscaleFilter produces black frame using MovieWriter
I have my filter chain setup for video preview with the GPUImageGrayscaleFilter and it works fine. However, if I try to use it with the movie writer I get black frames. The same code works fine if I substitute the monochrome or haze filter but I only get black frames with the GPUImageGrayscaleFilter if I am using the movie writer
I should mention that I am using the movie write to process an existing video file and write it out with the new filter. It works fine with any other filter (well, I haven't tried them all).
My code for filter setup for both camera preview and movie writer:
- (void)prepareFilter:(bool)bIsMovie
{
if (myMovie != nil) [myMovie removeAllTargets];
[filterView removeFromSuperview];
[stillCamera removeAllTargets];
[filter removeAllTargets];
[filterBW removeAllTargets];
[filterSmooth removeAllTargets];
if (switchBlackAndWhite.isOn)
{
if (bIsMovie)
{
[myMovie addTarget:filterBW];
}
else
{
[stillCamera addTarget:filterBW];
}
if (switchSmooth.isOn)
{
[filterBW addTarget:filterSmooth];
if (bIsMovie)
{
[filterSmooth addTarget:movieWriter];
}
[filterSmooth addTarget:filterView];
}
else
{
[filterBW addTarget:filter];
if (bIsMovie)
{
[filter addTarget:movieWriter];
}
[filter addTarget:filterView];
}
}
else
{
if (switchSmooth.isOn)
{
if (bIsMovie)
{
[myMovie addTarget:filterSmooth];
[filterSmooth addTarget:movieWriter];
}
else
{
[stillCamera addTarget:filterSmooth];
}
[filterSmooth addTarget:filterView];
}
else
{
if (bIsMovie)
{
[myMovie addTarget:filter];
[filter addTarget:movieWriter];
}
else
{
[stillCamera addTarget:filter];
}
[filter addTarget:filterView];
}
}
[[self view] addSubview:filterView];
[[self view] addSubview:overlayImageView];
[filter prepareForImageCapture];
if (switchSmooth.isOn)
{
[filterSmooth prepareForImageCapture];
}
if (switchBlackAndWhite.isOn)
{
[filterBW prepareForImageCapture];
}
}
My code for movie writer setup and start:
-(void)ApplyFilterToVideoURL:(NSURL *)videoUrl path:(NSString *)moviePath
{
if (movieURL != nil)
{
[[NSFileManager defaultManager] removeItemAtURL:movieURL error:nil];
}
myMovie = [[GPUImageMovie alloc] initWithURL:videoUrl];
//myMovie.runBenchmark = YES;
//myMovie.playAtActualSpeed = YES;
//Setting path for temporary storing the video in document directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *myPathDocs = [documentsDirectory stringByAppendingPathComponent:
@"MyMovie.mov"];
//remove old file first otherwise we will keep adding until full!
if (myPathDocs != nil)
{
[[NSFileManager defaultManager] removeItemAtPath:myPathDocs error:nil];
}
movieURL = [NSURL fileURLWithPath:myPathDocs];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:videoUrl options:nil];
AVAssetTrack *videoAssetTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
CGAffineTransform videoTransform = videoAssetTrack.preferredTransform;
//if (movieWriter == nil) //always re-create
{
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(videoAssetTrack.naturalSize.width, videoAssetTrack.naturalSize.height)];
}
[self prepareFilter:YES];
m_bLoadWasMovie = YES;
[myMovie prepareForImageCapture];
//Movie Write needs big activity indicator!
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityIndicator.alpha = 1.0;
activityIndicator.center = self.view.center;
activityIndicator.hidesWhenStopped = NO;
CGAffineTransform transform = CGAffineTransformMakeScale(3.0f, 3.0f);
activityIndicator.transform = transform;
[self.view addSubview:activityIndicator];
[activityIndicator startAnimating];
movieWriter.shouldPassthroughAudio = YES;
myMovie.audioEncodingTarget = movieWriter;
[myMovie enableSynchronizedEncodingUsingMovieWriter:movieWriter];
__weak typeof(self) weakSelf = self;
[movieWriter setFailureBlock:^ (NSError *failureBlock)
{
dispatch_async(dispatch_get_main_queue(), ^
{
[weakSelf.activityIndicator stopAnimating];
[weakSelf.activityIndicator removeFromSuperview];
[weakSelf prepareFilter:NO];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Movie Processing Error!" message:failureBlock.localizedDescription delegate:weakSelf cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
alert.tag = 90289;
[alert show];
});
}];
[movieWriter setCompletionBlock:^
{
[weakSelf.movieWriter finishRecording];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (weakSelf.movieURL.path))
{
UISaveVideoAtPathToSavedPhotosAlbum (weakSelf.movieURL.path, nil, nil, nil);
}
dispatch_async(dispatch_get_main_queue(), ^
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Success!" message:@"Movie File\nFinished Processing" delegate:weakSelf cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
alert.tag = 990000;
[alert show];
});
}];
[movieWriter startRecordingInOrientation:videoTransform];
[myMovie startProcessing];
}
Me too, i use GPUImageGrayscaleFilter get black video
hello i find old GPUImage version can solve this problem.