ios - How to add Image to video using GPUImage in Swift -
i have codes add image video using gpuimage, somehow doesn't work thought. have searched solution, , still have problem.
i'm trying merge image when recoding done. output video not image.
here's code.
override func viewdidload(){ super.viewdidload setupcamera() } func setupcamera(){ let myboundsize: cgsize = uiscreen.mainscreen().bounds.size camerasubpreview = gpuimageview(frame: cgrectmake(0, 0, myboundsize.width, myboundsize.height)) camerainput = gpuimagevideocamera(sessionpreset: avcapturesessionpreset1280x720, cameraposition: .front) camerainput.horizontallymirrorfrontfacingcamera = true camerainput.outputimageorientation = .portrait camerainput.addtarget(mainvideofilter) mainvideofilter.addtarget(camerasubpreview) camerapreview.addsubview(camerasubpreview) camerainput.startcameracapture() } func setupfilter(){ let logoimageforgpu = gpuimagepicture(image: logoimageview.image) logoimageforgpu.addtarget(transformfilter) logoimageforgpu.processimage() // apply transform filter let tx: cgfloat = logoimageview.frame.size.width let ty: cgfloat = logoimageview.frame.size.height print("tx , ty: \(tx), \(ty)") let t: cgaffinetransform = cgaffinetransformmakescale(tx, ty); transformfilter.affinetransform = t transformfilter.addtarget(mainvideofilter, attexturelocation: 1) } func startrecordingvideo(sender: anyobject) { if(sender.state == uigesturerecognizerstate.began) { if !self.isrecording { setupfilter() let ud = nsuserdefaults.standarduserdefaults() var intforfilepath : int? = ud.objectforkey("intforfilepath") as? int if intforfilepath == nil{ intforfilepath = 10000 } let paths = nssearchpathfordirectoriesindomains(.documentdirectory, .userdomainmask, true) let documentsdirectory = paths[0] intforfilepath = intforfilepath! + 1 let filepath : string? = "\(documentsdirectory)/temp\(intforfilepath!).mp4" ud.setobject(intforfilepath, forkey: "intforfilepath") // url. let fileurl : nsurl = nsurl(fileurlwithpath: filepath!) //print(filepath) self.delegate.filepathforvideo = filepath! moviewriter = gpuimagemoviewriter(movieurl: fileurl, size: cgsize(width: 480, height: 800)) moviewriter.shouldpassthroughaudio = true //camerainput.addtarget(stillimagefilter) //print("sif: \()") stillimagefilter.addtarget(moviewriter) camerainput.audioencodingtarget = moviewriter // start recording moviewriter.startrecording() circle.hidden = false drawcircleanimation("strokeend", animename: "updategageanimation", fromvalue: 0.0, tovalue: 1.0, duration: 10.0, repeat: 1, flag: false) self.isrecording = true } } else if (sender.state == uigesturerecognizerstate.ended) { if self.isrecording { //stop recording moviewriter.finishrecording() stopcircleanimation() self.isrecording = false self.movetovideosaveview() } } }
if have ideas solve this, please let me know.
in advance.
Comments
Post a Comment