2013-10-22 70 views
0

我使用的是GPUImage libraryhere,並有大量樣本可以提供幫助,但我發現有一件事,而使用過濾器的工作正常,GPUImageVideoCamera。我試圖在已錄製的視頻上應用過濾器,過濾器工作正常,但是當我嘗試更改過濾器的值時,它並未反映出來,因爲我沒有使用GPUImageVideoCamera,因爲我不必記錄視頻,但我必須實現過濾器預覽,然後應用選定的過濾器並創建一個新電影。使用GPUImageFilter動態更改值

下面我把一些我的代碼

- (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]; 
} 

任何幫助表示讚賞。

謝謝。

+0

我看不出與SimpleVideoFileFilter示例應用程序相同的行爲,這是做到這一點。如果您在那裏移動滑塊,則過濾器會隨着正在播放的視頻動態更新。確保你的滑塊確實發送了正確的更新事件(0.0-1.0)到你的回調方法。 –

+0

@BradLarson是的樣品工作正常,因爲它使用'GPUImageVideoCamera',但我沒有在這裏使用相機,我試圖播放應用了過濾器的視頻,工作正常,但是當我更改過濾器的值這是行不通的。是的,我所得到的值是正確的,正如你所提到的那樣。 – iphonic

+0

不,SimpleVideoFileFilter使用GPUImageMovie。具體看那一個。就像我說的那樣,它在那裏按預期工作。 –

回答

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