【问题标题】:Using GPUImageFilter change values dynamically使用 GPUImageFilter 动态更改值
【发布时间】:2013-10-31 15:59:31
【问题描述】:

我使用的是 GPUImage library here ,并且有很多示例可以提供帮助,但是我在使用过滤器时发现了一件事,它与 GPUImageVideoCamera 配合得很好。我试图对已录制的视频应用过滤器,过滤器工作正常,但是当我尝试更改过滤器的值时,它不会反映它,因为我没有使用GPUImageVideoCamera,因为我不必录制视频,但我必须实现过滤器预览,然后应用所选过滤器并创建新电影。

下面是我的一些代码

- (void)viewDidLoad
{
    [super viewDidLoad];

    //Creating Filter
    filter=[[GPUImageSepiaFilter alloc] init];

    //Playing Video
    [self playVideo];
}

-(void)playVideo{

    if(!movieFile){
        movieFile = [[GPUImageMovie alloc] initWithURL:self.videoURL];
        movieFile.playAtActualSpeed=YES;
        movieFile.playSound=YES;
        movieFile.delegate=self;
    }



    [movieFile addTarget:filter];

    CGRect rect=self.viewMovie.frame;
    rect.origin=CGPointZero;


    self.filterView=[[GPUImageView alloc] initWithFrame:rect];
    [self.viewMovie addSubview:self.filterView];

    //Rotate the preview to fix portrait recored video to show properly
    if([self.transformation isEqualToString:@"portrait"]){
        self.filterView.rotation=kGPUImageRotateRight;
    }

    [self.filterView initMovie];
    [filter addTarget:self.filterView];


    double delayInSeconds = 0.5;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [movieFile startProcessing];
    });

}

- (IBAction)sliderAction:(id)sender {
    [self applySliderValue:self.slider.value];
}

//Doesn't work
-(void)applySliderValue:(float)sliderValue{
    [((GPUImageSepiaFilter *)filter) setIntensity:sliderValue];
}

感谢任何帮助。

谢谢。

【问题讨论】:

  • 我看不到与 SimpleVideoFileFilter 示例应用程序相同的行为,它就是这样做的。如果将滑块移到那里,过滤器会随着正在播放的视频动态更新。确保您的滑块确实向您的回调方法发送了具有正确值 (0.0-1.0) 的正确更新事件。
  • @BradLarson 是的,该示例工作正常,因为它使用“GPUImageVideoCamera”,但我没有在这里使用相机,我正在尝试播放应用了过滤器的视频,效果很好,但是当我更改了不起作用的过滤器的值。是的,正如您所提到的,我得到的值是正确的..
  • 不,SimpleVideoFileFilter 使用 GPUImageMovie。具体看那个。就像我说的,它在那里按预期工作。
  • @BradLarson 所以我的代码应该可以正常工作,对吧?我将再次检查滑块值.. 感谢您的见解..

标签: ios image-processing video-processing gpuimage


【解决方案1】:

我能否建议先调试一下滑块的笔尖连接:

-(void)applySliderValue:(float)sliderValue{
    NSLog(@"sliderValue: %f",sliderValue);
    [((GPUImageSepiaFilter *)filter) setIntensity:sliderValue];
}

如果一切连接正确,您应该会看到调试器在您移动滑块时快速弹出一系列介于 0.0 和 1.0 之间的值。

如果没有任何反应,则说明您的 nib 配置有问题。如果值范围在 0.0-1.0 之外,则说明存在 UISlider 配置问题。

如果这工作正常并且过滤器仍然没有响应,请通过在 GPUImageSepiaFilter 的自定义子类中重写此方法来更深入地挖掘:

- (void)setIntensity:(CGFloat)newIntensity;
{
    _intensity = newIntensity;

    NSLog(@"intensity: %f",_intensity);

    [self setFloat:_intensity forUniform:intensityUniform program:filterProgram];
}

【讨论】:

    猜你喜欢
    • 2012-04-15
    • 2019-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多