iphone - Can use AVCaptureVideoDataOutput and AVCaptureMovieFileOutput at the same time? -


i want record video , grab frames @ same time code.

i using avcapturevideodataoutput grab frames , avcapturemoviefileoutput video recording. can't work , error code -12780 while working @ same time individual.

i searched problem no answer. did have same experience or explain? it's bother me while time.

thanks.

i can't answer specific question put, i've been recording video , grabbing frames @ same time using:

  • avcapturesession , avcapturevideodataoutput route frames own code
  • avassetwriter, avassetwriterinput , avassetwriterinputpixelbufferadaptor write frames out h.264 encoded movie file

that's without investigating audio. end getting cmsamplebuffers capture session , pushing them pixel buffer adaptor.

edit: code looks more or less like, bits you're having no problems skimmed on , ignoring issues of scope:

/* ensure i'm given incoming cmsamplebuffers */ avcapturesession *capturesession = alloc , init, set preferred preset/etc; avcapturedevice *capturedevice = default video, probably;  avcapturedeviceinput *deviceinput = input device above,                                      , attach session;  avcapturevideodataoutput *output = output 32bgra pixel format, me                                    delegate , suitable dispatch queue affixed.  /* prepare output; i'll output 640x480 in h.264, via asset writer */ nsdictionary *outputsettings =     [nsdictionary dictionarywithobjectsandkeys:              [nsnumber numberwithint:640], avvideowidthkey,             [nsnumber numberwithint:480], avvideoheightkey,             avvideocodech264, avvideocodeckey,              nil];  avassetwriterinput *assetwriterinput = [avassetwriterinput                                     assetwriterinputwithmediatype:avmediatypevideo                                                   outputsettings:outputsettings];  /* i'm going push pixel buffers it, need     avassetwriterpixelbufferadaptor, expect same 32bgra input i've    asked avcapturevidedataoutput supply */ avassetwriterinputpixelbufferadaptor *pixelbufferadaptor =            [[avassetwriterinputpixelbufferadaptor alloc]                  initwithassetwriterinput:assetwriterinput                  sourcepixelbufferattributes:                      [nsdictionary dictionarywithobjectsandkeys:                           [nsnumber numberwithint:kcvpixelformattype_32bgra],                             kcvpixelbufferpixelformattypekey,                      nil]];  /* that's going go somewhere, imagine you've got url sorted,    create suitable asset writer; we'll put our h.264 within normal    mpeg4 container */ avassetwriter *assetwriter = [[avassetwriter alloc]                                 initwithurl:urlfromsomwhere                                 filetype:avfiletypempeg4                                 error:you need check error conditions,                                       example lazy]; [assetwriter addinput:assetwriterinput];  /* need warn input expect real time data incoming, tries    avoid being unavailable @ inopportune moments */ assetwriterinput.expectsmediadatainrealtime = yes;  ... ...  [assetwriter startwriting]; [assetwriter startsessionatsourcetime:kcmtimezero]; [capturesession startrunning];  ... elsewhere ...  - (void)        captureoutput:(avcaptureoutput *)captureoutput      didoutputsamplebuffer:(cmsamplebufferref)samplebuffer             fromconnection:(avcaptureconnection *)connection {     cvimagebufferref imagebuffer = cmsamplebuffergetimagebuffer(samplebuffer);      // dense way keep track of time @ frame     // occurs relative output stream, it's example!     static int64_t framenumber = 0;     if(assetwriterinput.readyformoremediadata)         [pixelbufferadaptor appendpixelbuffer:imagebuffer                          withpresentationtime:cmtimemake(framenumber, 25)];     framenumber++; }  ... and, stop, ensuring output file finished ...  [capturesession stoprunning]; [assetwriter finishwriting]; 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -