2016-12-23 2 views
3

Wie kann ich dieser Filterpipeline dynamischen Text hinzufügen? Ich weiß, dass ich einen Mischfilter und ein UIElement benötige, aber ich bin nicht sicher, wo/wer zu welchen Zielen hinzuzufügen.Hinzufügen von dynamischem Text GPUImage zu gefiltertem Video

Kann jemand helfen?

videoCamera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPresetMedium cameraPosition:AVCaptureDevicePositionBack]; 
videoCamera.outputImageOrientation = UIInterfaceOrientationLandscapeRight; 

cropFilter = [[GPUImageCropFilter alloc] initWithCropRegion:CGRectMake(0, 0, 1, 1)]; 
sourcePicture = [[GPUImagePicture alloc] initWithImage:[NPFilterBuilder getTextureOverlay] smoothlyScaleOutput:NO]; 
[sourcePicture processImage]; 

customFilter = [NPFilterBuilder getFilter]; 
[videoCamera addTarget:cropFilter]; 
[cropFilter addTarget:customFilter atTextureLocation:0]; 
[sourcePicture addTarget:customFilter atTextureLocation:1]; 

[customFilter addTarget:mViewCameraPreview]; 

[videoCamera startCameraCapture]; 

Ich weiß, dass ich so etwas zu tun:

blendFilter = [[GPUImageAlphaBlendFilter alloc] init]; 
blendFilter.mix = 1.0; 
uiElementInput = [[GPUImageUIElement alloc]initWithView:[self buildTimeLabel]]; 

[uiElementInput addTarget:blendFilter]; 

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

Ich brauche die blendFilter irgendwo in meiner Filterkette hinzuzufügen, aber ich kann nicht herausfinden, wo es zu tun. Ich habe ein Diagramm erstellt, wie ich meine jetzige Kette sehe. enter image description here

+0

Was meinst du mit dynamischem Text? Du meinst, du willst Text auf dem Bild als Filter einblenden? – Alistra

Antwort

1

Kann sein, es wird Ihnen helfen:

NSURL *sampleURL = [[NSBundle mainBundle] URLForResource:@"Missile_Preview" withExtension:@"m4v"]; 

movieFile = [[GPUImageMovie alloc] initWithURL:sampleURL]; 
movieFile.runBenchmark = YES; 
movieFile.playAtActualSpeed = NO; 

filter = [[GPUImageBrightnessFilter alloc] init]; 
[(GPUImageBrightnessFilter*)filter setBrightness:0.0]; 

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

UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height-20)]; 
contentView.backgroundColor = [UIColor clearColor]; 

UIImageView *ivTemp = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 147, 59)]; 
ivTemp.image = [UIImage imageNamed:@"logo.png"]; 
[contentView addSubview:ivTemp]; 

UILabel *lblDemo = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 30)]; 
lblDemo.text = @"Paracha"; 
lblDemo.font = [UIFont systemFontOfSize:30]; 
lblDemo.textColor = [UIColor redColor]; 
lblDemo.tag = 1; 
lblDemo.hidden = YES; 
lblDemo.backgroundColor = [UIColor clearColor]; 
[contentView addSubview:lblDemo]; 

uiElementInput = [[GPUImageUIElement alloc] initWithView:contentView]; 
[filter addTarget:blendFilter]; 
[uiElementInput addTarget:blendFilter]; 

[movieFile addTarget:filter]; 

// Only rotate the video for display, leave orientation the same for recording 
GPUImageView *filterView = (GPUImageView *)vwVideo; 
[filter addTarget:filterView]; 
[blendFilter addTarget:filterView]; 

[filter setFrameProcessingCompletionBlock:^(GPUImageOutput * filter, CMTime frameTime){ 
    if (frameTime.value/frameTime.timescale == 2) { 
     [contentView viewWithTag:1].hidden = NO; 
    } 
    [uiElementInput update]; 
}]; 

// 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 

movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:[NSURL fileURLWithPath:pathToMovie] size:CGSizeMake(640.0, 480.0)]; 
[filter addTarget:movieWriter]; 
[blendFilter addTarget:movieWriter]; 

// 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]; 

[movieWriter setCompletionBlock:^{ 
    UISaveVideoAtPathToSavedPhotosAlbum(pathToMovie, nil, nil, nil); 
}]; 
Verwandte Themen