Recently, I'm doing an app that needs to add filters to existing videos, not real-time filters, but filters for existing videos.
Although there are many blogs about gpuimage on the internet, most of them are filters for images or real-time filters that are added directly to the camera head, after a long search ...
Found on GitHub that there was ...
But in the online search, but did not say that many people give such a filter tutorial, here simply to share the next.
1. First, what is Gpuimage? For details, please, simply put, is a third-party library that uses GPUs to process pictures and videos.
2. Add filters to the image, if it is only add filters, then there are a lot of tutorials on the web, here do not elaborate, here is mainly about how to find the filter and the filter to set what parameters.
2.1 Looking for a filter to use, in fact, whether it is recommended by many people gpuimage or Apple's official coreimage, the name of the filter itself has been very good to explain the effect of this filter:
In addition, in Gpuimage, each filter class filter, will have detailed comments to explain the role of this filter
Of course, it's all in English .....
2.2 Configuration parameters.
In Gpuimage, in fact, there is no coreimage can directly use the method to obtain the current filter needs to use the parameters so convenient, but by clicking into the corresponding filter of the. h file inside the query.
, red, green, and blue inside are the configuration parameters to set.
3. Add a filter to the existing video, this is an official example on GitHub in Gpuimage .... Everyone can go and see.
/* Below try using Gpuimage to add filters to the video. */Gpuimagecontrastfilter *secondfilter = [[Gpuimagecontrastfilter alloc] init]; [Secondfilter setcontrast:1.80]; Gpuimagebrightnessfilter *firstfilter = [[Gpuimagebrightnessfilter alloc] init]; [Firstfilter setbrightness:0.1]; Gpuimagecolorburnblendfilter gpuimagergbfilter *filter = [[Gpuimagergbfilter alloc] init]; filter.red = 0.8; Filter.green = 1; Filter.blue = 1.2; Nsurl *vediourl = [Nsurl fileurlwithpath:[[nsbundle mainbundle] pathforresource:@ "S2" oftype:@ "mp4"]; Gpuimagemovie *movie = [[Gpuimagemovie alloc] initwithurl:vediourl]; Movie.runbenchmark = YES; [Movie Addtarget:filter]; [Movie Addtarget:secondfilter]; Gpuimagemoviewriter *vediowriter = [[Gpuimagemoviewriter alloc] Initwithmovieurl:[nsurl fileurlwithpath:@ "/Users/ Huazai/desktop/t/t16.mov "] Size:cgsizemake (1280, 800)]; Movie.audioencodingtarget = nil; Vediowriter.shouldpassthroughaudio = YES; Movie.playatactualspeed = NO; [Movie startprocessing]; [Filter Addtarget:vediowriter]; [Secondfilter Addtarget:vediowriter]; [Vediowriter startrecording]; [Vediowriter setcompletionblock:^{NSLog (@ "Completed!!! "); }];
I'll write a few more blogs about how to use Gpuimage to write watermarks, mix filters, and look forward to ...
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Use Gpuimage to add filters to videos on iOS