2016-07-15 2 views
0

새로운 GPUImageUIElementFilter의 몇 가지 예를 살펴본 결과 디스크에서 가져온 비디오에 적용하려고 시도했지만 대신 "흰색 화면"비디오가 나타납니다. 나는 다른 필터 (세피아, pixelate)와 코드를 실행 해봤지만, 잘 작동하는 것 같지만, UI 요소와 블렌딩이 실패합니다.GPUImageUIElementFilter가 흰색 화면으로 비디오를 반환합니다.

여기 내 코드입니다 :

//Declared in interface 

@property(nonatomic, strong) GPUImageMovieWriter *movieWriter; 
@property(nonatomic, strong) GPUImageMovie *movieFile; 
@property(nonatomic, strong) GPUImageFilter *blendFilter; 
@property(nonatomic, strong) GPUImageUIElement *uiElementFilter; 



- (void)videoOutputOverlay { 

    self.movieFile = [[GPUImageMovie alloc] initWithURL:self.post.url]; 
    self.movieFile.runBenchmark = YES; 
    self.movieFile.playAtActualSpeed = YES; 
    self.blendFilter = [[GPUImageAlphaBlendFilter alloc] init]; 
    ((GPUImageAlphaBlendFilter *)self.blendFilter).mix = 1.0; 
    self.drawingView.backgroundColor = [UIColor clearColor]; 

    self.uiElementFilter = [[GPUImageUIElement alloc] initWithView:self.drawingView]; 
    [self.movieFile addTarget:self.blendFilter]; 
    [self.uiElementFilter addTarget:self.blendFilter]; 

    // In addition to displaying to the screen, write out a processed version of the movie to disk 
    NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Output.m4v"]; 
    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]; 

    self.movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(640.0, 480.0)]; 
    [self.blendFilter 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 PostPreviewViewController *weakSelf = self; 
    [self.movieWriter setCompletionBlock:^{ 
    [weakSelf.blendFilter removeTarget:weakSelf.movieWriter]; 
    [weakSelf.movieWriter finishRecording]; 

    UISaveVideoAtPathToSavedPhotosAlbum(pathToMovie, nil, NULL, NULL); 

    NSLog(@"completed saving movie"); 

    }]; 
} 

이 거의 온라인 거기에 몇 가지 예에서 동일하게 복사 된 모든이며, 주요 차이점은 내가 비디오를 살 파일을 사용하고 있다는 점이다.

내 "카메라 롤"에 보낸 비디오에

, 나는 오디오를들을 수 + 모든 다른 필터와 함께 일했다, 그래서 나는 비디오가 올바로로드 (플러스 수출에 오류 못하고)

I입니다 확신 내가 필터/타겟을 설정하는 방식에 뭔가 잘못되었다고 가정합니다.

도움을 주시면 감사하겠습니다. 감사합니다

답변

0

누구든지이 문제에 부딪치게되면, 나는 그것을 약간 해결할 수있었습니다. 지금은 제 경우에 소리가 들리지 않습니다. 여기에 내 코드가있다. 프로젝트에 특정 사항이 있지만 다소 일반적인 것일 수도있다.

- (void)videoOutputOverlay { 

    movieFile = [[GPUImageMovie alloc] initWithURL:self.post.videoUrl]; 
    movieFile.runBenchmark = YES; 
    movieFile.playAtActualSpeed = NO; 

    filter = [[GPUImageBrightnessFilter alloc] init]; 
    // [filter useNextFrameForImageCapture]; 
    [(GPUImageBrightnessFilter *)filter setBrightness:0.0]; 
    [filter setInputRotation:kGPUImageRotateRight atIndex:0]; 

    GPUImageAlphaBlendFilter *blendFilter = [[GPUImageAlphaBlendFilter alloc] init]; 
    // [blendFilter useNextFrameForImageCapture]; 
    blendFilter.mix = 1.0; 

    UIView *contentView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; 
    [contentView addSubview:self.drawingView]; 
    [contentView addSubview:self.textOverlayView]; 
    uiElementInput = [[GPUImageUIElement alloc] initWithView:contentView]; 

    [movieFile addTarget:filter]; 
    [filter addTarget:blendFilter]; 
    [uiElementInput addTarget:blendFilter]; 

    // In addition to displaying to the screen, write out a processed version of the movie to disk 
    NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.m4v"]; 
    unlink([pathToMovie UTF8String]); // If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie 

    //load asset to grab size 
    AVAsset *asset = [AVAsset assetWithURL:self.post.videoUrl]; 

    AVAssetTrack *track = asset.tracks.firstObject; 
    CGSize exportSize = CGSizeMake(track.naturalSize.height, track.naturalSize.width); 

    movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:[NSURL fileURLWithPath:pathToMovie] size:exportSize]; 
    [blendFilter addTarget:movieWriter]; 

    __weak GPUImageUIElement *weakUIElement = uiElementInput; 
    [filter setFrameProcessingCompletionBlock:^(GPUImageOutput *filter, CMTime frameTime) { 
    [weakUIElement update]; 
    }]; 

    // Configure this for video from the movie file, where we want to preserve all video frames and audio samples 
    movieWriter.shouldPassthroughAudio = YES; 
    movieFile.audioEncodingTarget = movieWriter; 
    [movieFile enableSynchronizedEncodingUsingMovieWriter:movieWriter]; 

    [movieWriter startRecording]; 
    [movieFile startProcessing]; 

    __weak PostPreviewViewController *weakSelf = self; 
    [movieWriter setCompletionBlock:^{ 
    UISaveVideoAtPathToSavedPhotosAlbum(pathToMovie, weakSelf, @selector(image:completedSavingLocallyWithError:usingContextInfo:), NULL); 
    }]; 
} 
관련 문제