cocoa - QTKit, capture video for live streaming -


i trying create application mac create live video streaming. know vlc , other solutions, still.

to end trying record video isight using qtkit, , save continuously series of tiny video files. however, recording turns out not quite continuous, gaps between files.

basically, setting timer, starts recording new file @ time intervals, stopping old recording. tried setting max recorded length, , using delegate method ...didfinishrecording... , ...willfinishrecording..., same result (i can't estimate difference between gaps in these cases).

please, me, if know how these things should done.

here current code:

 - (void)applicationdidfinishlaunching:(nsnotification *)anotification {     qtcapturesession *session = [[qtcapturesession alloc] init];     qtcapturedevice *isight = [qtcapturedevice defaultinputdevicewithmediatype:qtmediatypevideo];     [isight open:nil];     qtcapturedeviceinput *myinput = [qtcapturedeviceinput deviceinputwithdevice:isight];     output = [[qtcapturemoviefileoutput alloc] init] ; //ivar, qtcapturefileoutput     [output setdelegate:self];     = 0; //ivar, int     filename = @"/users/dtv/filerecording_"; //ivar, nsstring     [session addoutput:output error:nil];     [session addinput:myinput error:nil];     [capview setcapturesession:session]; //iboutlet     [session startrunning];      [output setcompressionoptions:[qtcompressionoptions compressionoptionswithidentifier:@"qtcompressionoptionssd480sizeh264video"] forconnection:[[output connections] objectatindex:0]];     [output recordtooutputfileurl:[nsurl fileurlwithpath:[nsstring stringwithformat:@"%@%i.mov", filename, a]] bufferdestination:qtcapturefileoutputbufferdestinationoldfile];     nstimer *tmr = [nstimer timerwithtimeinterval:5 target:self selector:@selector(getmovielength:) userinfo:nil repeats:yes];     [[nsrunloop currentrunloop] addtimer:tmr formode:nsdefaultrunloopmode]; }

‐ (void) getmovielength:(nstimer *) t { a++; [output recordtooutputfileurl:[nsurl fileurlwithpath:[nsstring stringwithformat:@"%@%i.mov", filename, a]] bufferdestination:qtcapturefileoutputbufferdestinationoldfile]; }

there native mechanism brake captured movie pieces. use

[qtcapturefileoutput setmaximumrecordedduration:] 

to specify duration of piece or

[qtcapturefileoutput setmaximumrecordedfilesize:] 

to specify file size limit.

when limit reached delegate method called:

[qtcapturefileoutput_delegate captureoutput: shouldchangeoutputfileaturl: forconnections: duetoerror:] 

in method can set new file name:

[qtcapturefileoutput recordtooutputfileurl:] 

this allow cut pieces of recorded movie pretty precisely.

note, [qtcapturefileoutput_delegate captureoutput: didfinishrecordingtooutputfileaturl: forconnections: duetoerror:] called bit later after recoding file has been finished. if use method set new file have gaps in final video. not mean not need use method though. method indicated when piece of movie ready used.

if need more precise cutting can use

[qtcapturefileoutput captureoutput: didoutputsamplebuffer: fromconnection:] 

to specify exact movie frame when start recording new piece. however, need more specific knowledge work method.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -