osx - AVFoundation - how to mirror video from webcam - Mac OS X -


i trying mirror video received webcam on mac os x. avoid doing manual flip/tranform after receiving video buffer . so, want setup avcapturesession such video buffer received in captureoutput method of avcapturevideodataoutputsamplebufferdelegate mirrored avfoundation itself. don't want use preview layer.

on imac(10.8.5), mirror video, avcaptureconnection isvideomirroringsupported tested before setting videomirrored property. video buffer received in captureoutput delegate isn't mirrored.

note: video mirroring on ios successful, when followed this answer. isn't helping on mac os x.

code used below. error checking left out post.

    //create session     _session = [[avcapturesession alloc] init];      //get capture device     _device = [avcapturedevice defaultdevicewithmediatype:avmediatypevideo];      //create sesion input     nserror * error;     _sessioninput = [avcapturedeviceinput deviceinputwithdevice:_device error:&error];      //create session output     _sessionoutput = [[avcapturevideodataoutput alloc] init];     [_sessionoutput setalwaysdiscardslatevideoframes:yes];     [[_sessionoutput connectionwithmediatype:avmediatypevideo] setenabled:yes];     nsdictionary *videosettings = [nsdictionary dictionarywithobject: [nsnumber numberwithunsignedint:kcvpixelformattype_32bgra] forkey:(id)kcvpixelbufferpixelformattypekey];     [_sessionoutput setvideosettings:videosettings];      //serial queue process video frames     dispatch_queue_t videooutputqueue = dispatch_queue_create("deviceeraqueue", dispatch_queue_serial);     [_sessionoutput setsamplebufferdelegate:self queue:videooutputqueue];      //begin session configuration     [_session beginconfiguration ];      //input , output session     if( [_session canaddinput:_sessioninput]) {         [_session addinput:_sessioninput];     }     if( [_session canaddoutput:_sessionoutput]) {         [_session addoutput:_sessionoutput];      }      //set video mirroring     avcaptureconnection* avconnection = [_sessionoutput connectionwithmediatype:avmediatypevideo];     if( [avconnection isvideomirroringsupported]) {         avconnection.videomirrored = yes;         nslog(@"video mirroring support: yes"); // line printed     } else {         nslog(@"video mirroring support: no");     }      //set session preset         [_session setsessionpreset:avcapturesessionpreset640x480];     [ _session commitconfiguration ];      ...........     ...........      - (void)captureoutput:(avcaptureoutput *)captureoutput didoutputsamplebuffer:(cmsamplebufferref)samplebuffer fromconnection:(avcaptureconnection *)connection     {     .........     //samplebuffer not mirrored video     ........ 

of lesser importance 1 - though c++, tried looking opencv's videocapture implementation way mirror video. but, opencv don't mirror video mac(uses flip). left libvlc/v4l.

of lesser importance 2 - in slide 73 of this 2010 wwdc apple presentation (3mb pdf), there mention setvideoorientation not supported on 'avcapturevideodataoutput` connection. in 2013, apple docs updated , supports method.

you can add transform on preview layer flip x value of frames before preview window.

[[self previewlayer] settransform:catransform3dmakescale(-1, 1, 1)]; 

then can run recorded video through export session , same transformation. way video preview match final recorded video. bit of hack, gets same results.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -