ios - video zoom in and zoom out while recording iphone -
i working on app in user have facility zoom in , zoom out video. using av foundation record video not able zoom in , zoom out video when user recording video.
i using following code record video
- (void) startcamera nslog(@"setting capture session"); capturesession = [[avcapturesession alloc] init]; //----- add inputs ----- nslog(@"adding video input"); //add video input avcapturedevice *videodevice = [avcapturedevice defaultdevicewithmediatype:avmediatypevideo]; if (videodevice) { nserror *error; videoinputdevice = [avcapturedeviceinput deviceinputwithdevice:videodevice error:&error]; if (!error) { if ([capturesession canaddinput:videoinputdevice]) [capturesession addinput:videoinputdevice]; else nslog(@"couldn't add video input"); } else { nslog(@"couldn't create video input"); } } else { nslog(@"couldn't create video capture device"); } //add audio input nslog(@"adding audio input"); avcapturedevice *audiocapturedevice = [avcapturedevice defaultdevicewithmediatype:avmediatypeaudio]; nserror *error = nil; avcapturedeviceinput *audioinput = [avcapturedeviceinput deviceinputwithdevice:audiocapturedevice error:&error]; if (audioinput) { [capturesession addinput:audioinput]; } //----- add outputs ----- //add video preview layer nslog(@"adding video preview layer"); [self setpreviewlayer:[[avcapturevideopreviewlayer alloc] initwithsession:capturesession]]; previewlayer.orientation = avcapturevideoorientationportrait; //<<set orientation. can deliberatly set wrong flip image , may need set wrong right image [[self previewlayer] setvideogravity:avlayervideogravityresizeaspectfill]; //add movie file output nslog(@"adding movie file output"); moviefileoutput = [[avcapturemoviefileoutput alloc] init]; float64 totalseconds = 60; //total seconds int32_t preferredtimescale = 30; //frames per second cmtime maxduration = cmtimemakewithseconds(totalseconds, preferredtimescale); //<<set max duration moviefileoutput.maxrecordedduration = maxduration; moviefileoutput.minfreediskspacelimit = 1024 * 1024; //<<set min free space in bytes recording continue on volume if ([capturesession canaddoutput:moviefileoutput]) [capturesession addoutput:moviefileoutput]; //set connection properties (output properties) [self camerasetoutputproperties]; //(we call method has done after changing camera) //----- set image quality / resolution ----- //options: // avcapturesessionpresethigh - highest recording quality (varies per device) // avcapturesessionpresetmedium - suitable wifi sharing (actual values may change) // avcapturesessionpresetlow - suitable 3g sharing (actual values may change) // avcapturesessionpreset640x480 - 640x480 vga (check supported before setting it) // avcapturesessionpreset1280x720 - 1280x720 720p hd (check supported before setting it) // avcapturesessionpresetphoto - full photo resolution (not supported video output) nslog(@"setting image quality"); [capturesession setsessionpreset:avcapturesessionpresetmedium]; if ([capturesession cansetsessionpreset:avcapturesessionpreset640x480]) //check size based configs supported before setting them [capturesession setsessionpreset:avcapturesessionpreset640x480]; //----- display preview layer ----- //display full screen under out view controller existing controls nslog(@"display preview layer"); cgrect layerrect; layerrect = cgrectmake(284, 0, 200, 200); [previewlayer setbounds:layerrect]; [previewlayer setposition:cgpointmake(cgrectgetmidx(layerrect), cgrectgetmidy(layerrect))]; //[[[self view] layer] addsublayer:[[self capturemanager] previewlayer]]; //we use instead goes on layer behind our ui controls (avoids having manually bring each control front): uiview *cameraview = [[uiview alloc] init]; [[self view] addsubview:cameraview]; [self.view sendsubviewtoback:cameraview]; [[cameraview layer] addsublayer:previewlayer]; //----- start capture session running ----- [capturesession startrunning]; } //********** camera set output properties ********** - (void) camerasetoutputproperties { //set connection properties (output properties) avcaptureconnection *captureconnection = [moviefileoutput connectionwithmediatype:avmediatypevideo]; //set landscape (if required) if ([captureconnection isvideoorientationsupported]) { avcapturevideoorientation orientation = avcapturevideoorientationportrait; //<<<<<set video orientation if landscape [captureconnection setvideoorientation:orientation]; } //set frame rate (if requried) cmtimeshow(captureconnection.videominframeduration); cmtimeshow(captureconnection.videomaxframeduration); if (captureconnection.supportsvideominframeduration) captureconnection.videominframeduration = cmtimemake(1, capture_frames_per_second); if (captureconnection.supportsvideomaxframeduration) captureconnection.videomaxframeduration = cmtimemake(1, capture_frames_per_second); cmtimeshow(captureconnection.videominframeduration); cmtimeshow(captureconnection.videomaxframeduration); } //********** did finish recording output file @ url ********** - (void)captureoutput:(avcapturefileoutput *)captureoutput didfinishrecordingtooutputfileaturl:(nsurl *)outputfileurl fromconnections:(nsarray *)connections error:(nserror *)error { nslog(@"didfinishrecordingtooutputfileaturl - enter"); bool recordedsuccessfully = yes; if ([error code] != noerr) { // problem occurred: find out if recording successful. id value = [[error userinfo] objectforkey:averrorrecordingsuccessfullyfinishedkey]; if (value) { recordedsuccessfully = [value boolvalue]; } } if (recordedsuccessfully) { //----- recorded sucessfully ----- nslog(@"didfinishrecordingtooutputfileaturl - success"); alassetslibrary *library = [[alassetslibrary alloc] init]; if ([library videoatpathiscompatiblewithsavedphotosalbum:outputfileurl]) { [library writevideoatpathtosavedphotosalbum:outputfileurl completionblock:^(nsurl *asseturl, nserror *error) { if (error) { } }]; } } }
any great
you cannot zoom iphone camera, @ best can while taking pictures use cameraviewtransform:
, apply transform live view of camera, still doesn't affect final picture taken
Comments
Post a Comment