Creating Cameras and filters
-(void) Createvideocamera: (avcapturedeviceposition) frontorback{
[Videocamera Removealltargets];
Videocamera = nil;
Videocamera = [[Gpuimagevideocamera alloc] initwithsessionpreset:avcapturesessionpreset1280x720 cameraPosition: Frontorback];
Videocamera.outputimageorientation = uiinterfaceorientationportrait;
Horizontallymirrorfrontfacingcamera Property YES means the front is not mirrored
Videocamera.horizontallymirrorfrontfacingcamera = YES;
Videocamera.horizontallymirrorrearfacingcamera = NO;
Crop Filter
Cropfilter = [[Gpuimagecropfilter alloc] Initwithcropregion:cgrectmake (0, (1280-720)/2/1280.0, 1,720/1280.0)];
Custom Beauty Filters
Beautyfilter = [[Gpuimagebeautyfilter alloc] init];
Filter grouping
Filtergroup = [[Gpuimagefiltergroup alloc] init];
No beauty.
if (!isbeauty) {
[Videocamera Addtarget:cropfilter];
Preview Layer/* Preview layer can omit */
[Cropfilter Addtarget:preview];
}
else{///Beauty and cropping filters are added to the filter group.
[Cropfilter Addtarget:beautyfilter];
[Filtergroup Addtarget:cropfilter];
[Filtergroup Addtarget:beautyfilter];
[Filtergroup Setinitialfilters:[nsarray Arraywithobject:cropfilter];
[Filtergroup Setterminalfilter:beautyfilter];
[Filtergroup forceProcessingAtSize:preView.frame.size];
[Filtergroup Usenextframeforimagecapture];
[Videocamera Addtarget:filtergroup];
[Filtergroup Addtarget:preview];
}
Start capturing
[Videocamera Startcameracapture];
}
Start recording a segmented recording to instantiate one Moviewriter at a time
-(void) Startphoto {
Videos recorded based on the time generation path are stored in the path to be unique
NSString *pathtomovie = [self getvideomergefilepathstring];
[Videoarray Addobject:pathtomovie];
NSLog (@ "%@", Pathtomovie);
Unlink ([Pathtomovie utf8string]);
Nsurl *movieurl = [Nsurl Fileurlwithpath:pathtomovie];
Moviewriter = [[Gpuimagemoviewriter alloc] Initwithmovieurl:movieurl size:cgsizemake (720, 720) FileType:AVFileTypeQ Uicktimemovie Outputsettings:videosettings];
Moviewriter = [[Gpuimagemoviewriter alloc] Initwithmovieurl:movieurl size:cgsizemake (720, 720)];
Audiosettings Some audio configurations
/*
Audiochannellayout channellayout;
memset (&channellayout, 0, sizeof (audiochannellayout));
Channellayout.mchannellayouttag = Kaudiochannellayouttag_stereo;
Audiosettings = [Nsdictionary Dictionarywithobjectsandkeys:
[NSNumber NUMBERWITHINT:KAUDIOFORMATMPEG4AAC], avformatidkey,//developing the coding algorithm
[NSNumber Numberwithint:2], avnumberofchannelskey,//Channel
[NSNumber numberwithfloat:16000.0], avsampleratekey,//sample rate
[NSData datawithbytes:&channellayout length:sizeof (audiochannellayout)], Avchannellayoutkey,
[NSNumber numberwithint:32000], avencoderbitratekey,//encoding rate
NIL];
*/
[Moviewriter Sethasaudiotrack:yes audiosettings:audiosettings];
Moviewriter.hasaudiotrack = YES;
[Videocamera addaudioinputsandoutputs];
Videocamera.audioencodingtarget = Moviewriter;
if (!isbeauty) {
[Cropfilter Addtarget:moviewriter];
}
else {
[Filtergroup Addtarget:moviewriter];
}
[Moviewriter startrecording];
}
Finish recording
-(void) endrecording {
[Moviewriter finishrecording];
[Cropfilter Removetarget:moviewriter];
[Beautyfilter Removetarget:moviewriter];
[Filtergroup Removetarget:moviewriter];
Videocamera.audioencodingtarget = nil;
[Self savePhotoCmare:videoArray.lastObject];
}
Write a recorded video to a photo album
-(void) Savephotocmare: (NSString *) Pathtomovie {
Nsurl *url = [[Nsurl alloc] initfileurlwithpath:pathtomovie];
Alassetslibrary *library = [[Alassetslibrary alloc] init];
if ([library Videoatpathiscompatiblewithsavedphotosalbum:url]) {
[Library Writevideoatpathtosavedphotosalbum:url
completionblock:^ (Nsurl *asseturl, Nserror *error) {
Dispatch_async (Dispatch_get_main_queue (), ^{
if (Error) {
Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Error" message:@ "Video saving Failed" Delegate:nil Cancelbutto ntitle:@ "OK" otherbuttontitles:nil, nil];
[Alert show];
}else{
Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Video Saved" message:@ "Saved to Photo Album" Delegate:self Canc elbuttontitle:@ "OK" otherbuttontitles:nil];
[Alert show];
}
});
}];
}
}
Gpuimage Video Recording plus filters