iphone - AVAssetImageGenerator cancelAllCGImageGeneration doesn't cancelAllCGImageGeneration -


there doesn't seem info around avassetimagegenerator , less cancelallcgimagegeneration hope isn't bug.

i'm calling generatecgimagesasynchronouslyfortimes , getting frames , if let process entire file. when cancelallcgimagegeneration...

...it takes while cancel - strange, no big deal.

...it continues call completion block every frame requested, result avassetimagegeneratorcancelled - seems odd design choice , inconvenient.

but major problem after series of calls avassetimagegeneratorcancelled starts calling avassetimagegeneratorsucceeded again. ideas?

(i workaround setting flag when cancel, , ignore images after this, user can restart operation video logic gets confusing. i'm getting "out of memory" errors on place.)

the code:

avurlasset* asset = [avurlasset urlassetwithurl:self.cameraselection.movieurl options:[nsdictionary dictionarywithobjectsandkeys:[nsnumber numberwithbool:yes], avurlassetpreferprecisedurationandtimingkey, nil]]; nstimeinterval duration = cmtimegetseconds(asset.duration); float fps = [[asset trackswithmediatype:avmediatypevideo] objectatindex:0].nominalframerate; int frames = duration * fps;  nsmutablearray* requestedtimes = [nsmutablearray array]; for( int i=0; i<frames; i++ ) {     [requestedtimes addobject:[nsvalue valuewithcmtime:cmtimemake(i, fps)]]; }  assetimagegenerator = [[avassetimagegenerator alloc] initwithasset:asset]; assetimagegenerator.requestedtimetolerancebefore = kcmtimezero; assetimagegenerator.requestedtimetoleranceafter = kcmtimezero; [assetimagegenerator generatecgimagesasynchronouslyfortimes:requestedtimes completionhandler:^(cmtime requestedtime, cgimageref image, cmtime actualtime, avassetimagegeneratorresult result, nserror *error)  {      nsstring* resultstr;      switch (result)      {          case avassetimagegeneratorsucceeded:   resultstr = @"avassetimagegeneratorsucceeded";  break;          case avassetimagegeneratorfailed:      resultstr = @"avassetimagegeneratorfailed"; break;          case avassetimagegeneratorcancelled:   resultstr = @"avassetimagegeneratorcancelled";  break;      }      cfstringref requestedtimestring = cmtimecopydescription(kcfallocatordefault, requestedtime);      cfstringref actualtimestring = cmtimecopydescription(kcfallocatordefault, actualtime);      nslog(@"%@ requestedtime:%@ actualtime:%@ error:%@", resultstr, (nsstring*)requestedtimestring, (nsstring*)actualtimestring, error);      cfrelease(requestedtimestring);      cfrelease(actualtimestring);  }]; 

the log:

 2013-07-01 12:23:54.815 improveyes[9114:1903] avassetimagegeneratorsucceeded requestedtime:{0/60 = 0.000} actualtime:{0/600 = 0.000} error:(null) 2013-07-01 12:23:54.864 improveyes[9114:1903] avassetimagegeneratorsucceeded requestedtime:{1/60 = 0.017} actualtime:{10/600 = 0.017} error:(null) 2013-07-01 12:23:54.894 improveyes[9114:1903] avassetimagegeneratorsucceeded requestedtime:{2/60 = 0.033} actualtime:{20/600 = 0.033} error:(null) 2013-07-01 12:23:54.950 improveyes[9114:1903] avassetimagegeneratorsucceeded requestedtime:{3/60 = 0.050} actualtime:{30/600 = 0.050} error:(null) 2013-07-01 12:23:54.964 improveyes[9114:1903] avassetimagegeneratorsucceeded requestedtime:{4/60 = 0.067} actualtime:{40/600 = 0.067} error:(null) *** cancel here *** 2013-07-01 12:23:56.137 improveyes[9114:1903] avassetimagegeneratorsucceeded requestedtime:{53/60 = 0.883} actualtime:{530/600 = 0.883} error:(null) 2013-07-01 12:23:56.138 improveyes[9114:907] assetimagegenerator cancelallcgimagegeneration 2013-07-01 12:23:56.210 improveyes[9114:1903] avassetimagegeneratorsucceeded requestedtime:{54/60 = 0.900} actualtime:{540/600 = 0.900} error:(null) 2013-07-01 12:23:56.230 improveyes[9114:1903] avassetimagegeneratorsucceeded requestedtime:{55/60 = 0.917} actualtime:{550/600 = 0.917} error:(null) *** continue receiving images while stop *** 2013-07-01 12:23:57.019 improveyes[9114:1903] avassetimagegeneratorsucceeded requestedtime:{90/60 = 1.500} actualtime:{900/600 = 1.500} error:(null) 2013-07-01 12:23:57.036 improveyes[9114:1903] avassetimagegeneratorsucceeded requestedtime:{91/60 = 1.517} actualtime:{910/600 = 1.517} error:(null) 2013-07-01 12:23:57.046 improveyes[9114:1903] avassetimagegeneratorcancelled requestedtime:{92/60 = 1.533} actualtime:{invalid} error:(null) 2013-07-01 12:23:57.056 improveyes[9114:1903] avassetimagegeneratorcancelled requestedtime:{93/60 = 1.550} actualtime:{invalid} error:(null) *** images start arriving again! *** 2013-07-01 12:24:01.234 improveyes[9114:1903] avassetimagegeneratorcancelled requestedtime:{538/60 = 8.967} actualtime:{invalid} error:(null) 2013-07-01 12:24:01.241 improveyes[9114:1903] avassetimagegeneratorcancelled requestedtime:{539/60 = 8.983} actualtime:{invalid} error:(null) 2013-07-01 12:24:01.249 improveyes[9114:1903] avassetimagegeneratorcancelled requestedtime:{540/60 = 9.000} actualtime:{invalid} error:(null) 2013-07-01 12:24:01.259 improveyes[9114:1903] avassetimagegeneratorsucceeded requestedtime:{541/60 = 9.017} actualtime:{5410/600 = 9.017} error:(null) 2013-07-01 12:24:01.270 improveyes[9114:1903] avassetimagegeneratorsucceeded requestedtime:{542/60 = 9.033} actualtime:{5420/600 = 9.033} error:(null) 2013-07-01 12:24:01.279 improveyes[9114:1903] avassetimagegeneratorsucceeded requestedtime:{543/60 = 9.050} actualtime:{5430/600 = 9.050} error:(null) ... 

i had same issue, still processes few because in queue.

try this:

__block bool haserrors = no;  avassetimagegeneratorcompletionhandler handler = ^(cmtime requestedtime, cgimageref im, cmtime actualtime, avassetimagegeneratorresult result, nserror *error) {     if (!haserrors) {          ddlogverbose(@"actual generation time %f", cmtimegetseconds(actualtime));          if (result != avassetimagegeneratorsucceeded) {             ddlogerror(@"failed generate thumb: %@", error.localizeddescription);             haserrors = yes;             [generator cancelallcgimagegeneration];             finishblock(images, yes);         } else {             [images addobject:[uiimage imagewithcgimage:im]];              if (cmtime_compare_inline(requestedtime, ==, ((nsvalue *) timeintervals.lastobject).cmtimevalue)) {                 ddlogverbose(@"movie composition thumb generation complete");                 finishblock(images, no);             }         }     } }; 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -