xcode - SampleBufferDelegate is not Working -
for odd reason avcapturevideodataoutputsamplebufferdelegate isn't triggering. i've added delegate , everything, i'm not sure why isn't being ran in code. can me figure out why?
delegates in .h
@class avplayer; @class avplayerclass; @interface camera : uiviewcontroller <uiimagepickercontrollerdelegate, uinavigationcontrollerdelegate, avcapturevideodataoutputsamplebufferdelegate, avcapturefileoutputrecordingdelegate> {
.m code (initializecamera being called in viewdidload)
-(void)initializecamera { session = [[avcapturesession alloc]init]; [session setsessionpreset:avcapturesessionpresetphoto]; avcapturedevice *audiocapturedevice = [avcapturedevice defaultdevicewithmediatype:avmediatypeaudio]; nserror *error = nil; avcapturedeviceinput *audioinput = [avcapturedeviceinput deviceinputwithdevice:audiocapturedevice error:&error]; [session addinput:audioinput]; // preview layer*************** avcapturevideopreviewlayer *previewlayer = [[avcapturevideopreviewlayer alloc]initwithsession:session]; [previewlayer setvideogravity:avlayervideogravityresizeaspectfill]; calayer *rootlayer = [[self view] layer]; [rootlayer setmaskstobounds:yes]; cgrect frame = self.cameraview.frame; [previewlayer setframe:frame]; [rootlayer insertsublayer:previewlayer atindex:0]; [session beginconfiguration]; //remove existing input [session removeinput:newvideoinput]; newcamera = [self camerawithposition:avcapturedevicepositionback]; // frontcamera = no; [session setsessionpreset:avcapturesessionpresethigh]; if ([session cansetsessionpreset:avcapturesessionpreset1920x1080]) //check size based configs supported before setting them [session setsessionpreset:avcapturesessionpreset1920x1080]; //add input session nserror *err = nil; newvideoinput = [[avcapturedeviceinput alloc] initwithdevice:newcamera error:&err]; if(!newvideoinput || err) { nslog(@"error creating capture device input: %@", err.localizeddescription); } else if ([session canaddinput:newvideoinput]) { [session addinput:newvideoinput]; } [session commitconfiguration]; stillimageoutput = [[avcapturestillimageoutput alloc]init]; nsdictionary *outputsettings = [[nsdictionary alloc] initwithobjectsandkeys:avvideocodecjpeg, avvideocodeckey, nil]; [stillimageoutput setoutputsettings:outputsettings]; [session addoutput:stillimageoutput]; moviefileoutput = [[avcapturemoviefileoutput alloc]init]; float64 totalseconds = 10; int32_t preferredtimescale = 60; cmtime maxduration = cmtimemakewithseconds(totalseconds, preferredtimescale); moviefileoutput.maxrecordedduration = maxduration; moviefileoutput.minfreediskspacelimit = 1024 * 1024; if ([session canaddoutput:moviefileoutput]) [session addoutput:moviefileoutput]; // create videodataoutput , add session // avcapturevideodataoutput *output = [[avcapturevideodataoutput alloc] init]; // // [session addoutput:output]; // // // configure output. // // dispatch_queue_t queue = dispatch_get_main_queue(); // // [output setsamplebufferdelegate:self queue:queue]; // // // dispatch_release(queue); // // // specify pixel format // // output.videosettings = [nsdictionary dictionarywithobject: // // [nsnumber numberwithint:kcvpixelformattype_32bgra] // // forkey:(id)kcvpixelbufferpixelformattypekey]; // // // // // // avcapturevideodataoutput *dataoutput = [[avcapturevideodataoutput alloc] init]; // // [dataoutput setalwaysdiscardslatevideoframes:yes]; // [dataoutput setvideosettings:[nsdictionary dictionarywithobject:[nsnumber numberwithint:kcvpixelformattype_32bgra] // forkey:(id)kcvpixelbufferpixelformattypekey]]; // [dataoutput setsamplebufferdelegate:self queue:dispatch_get_main_queue()]; // // if ([session canaddoutput:dataoutput]) // [session addoutput:dataoutput]; // sessionに追加 // [self setupvideooutput]; [session setsessionpreset:avcapturesessionpresethigh]; if ([session cansetsessionpreset:avcapturesessionpreset1920x1080]) //check size based configs supported before setting them [session setsessionpreset:avcapturesessionpreset1920x1080]; [session startrunning]; } -(void)captureoutput:(avcaptureoutput *)captureoutput didoutputsamplebuffer:(cmsamplebufferref )samplebuffer fromconnection:(avcaptureconnection *)connections { nslog(@"buff"); pixelbuffer = (cvpixelbufferref)cmsamplebuffergetimagebuffer(samplebuffer); videobuffer = pixelbuffer; } -(void)captureoutput:(avcaptureoutput *)captureoutput diddropsamplebuffer:(cmsamplebufferref)samplebuffer fromconnection:(avcaptureconnection *)connection { nslog(@"the drop"); }
my code isn't triggering avcapturevideodataoutputsamplebufferdelegate because using avcapturemoviefileoutput instead of avcapturevideodataoutput. avcapturemoviefileoutput apparently not use sample buffers. how set avcapturevideodataoutput correctly use sample buffers post code. hope helps somebody.
Comments
Post a Comment