0
我使用的是GPUImage library
here,並有大量樣本可以提供幫助,但我發現有一件事,而使用過濾器的工作正常,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];
}
任何幫助表示讚賞。
謝謝。
我看不出與SimpleVideoFileFilter示例應用程序相同的行爲,這是做到這一點。如果您在那裏移動滑塊,則過濾器會隨着正在播放的視頻動態更新。確保你的滑塊確實發送了正確的更新事件(0.0-1.0)到你的回調方法。 –
@BradLarson是的樣品工作正常,因爲它使用'GPUImageVideoCamera',但我沒有在這裏使用相機,我試圖播放應用了過濾器的視頻,工作正常,但是當我更改過濾器的值這是行不通的。是的,我所得到的值是正確的,正如你所提到的那樣。 – iphonic
不,SimpleVideoFileFilter使用GPUImageMovie。具體看那一個。就像我說的那樣,它在那裏按預期工作。 –