objective c - iOS - Extract pictures from short video give me the same picture -
i'm working on ios project capture videos , extract images video (for example 10 pictures every 500 ms). problem short videos (few seconds). i'm extracting same pictures 2 or 3 times. don't have problem video lengths around 10 seconds , more.
when discussing friend, told me problem key frame number in video. i'm using avcapturedeviceinput, avcapturesession , avcapturemoviefileoutput take video.
so, questions : how can figure out why i'm extracting same pictures many times ? key-frame number problem , possible increase value (from capture session ? capture device ?).
edit : here code picture extract :
avurlasset *asset = [[avurlasset alloc] initwithurl:videourl options:nil]; avassetimagegenerator *generateimg = [[avassetimagegenerator alloc] initwithasset:asset]; nsmutablearray *pictlist = [nsmutablearray array]; (int = 0; < timelist.count; i++) { nserror *error = null; cmtime time = cmtimemake([[timelist objectatindex:i] intvalue], 1000); cgimageref refimg = [generateimg copycgimageattime:time actualtime:null error:&error]; //nslog(@"error==%@, refimage==%@", error, refimg); [pictlist addobject:[[uiimage alloc] initwithcgimage:refimg]]; }
and here timelist print out :
(lldb) po timelist <__nsarraym 0x175afab0>( 0, 131, 262, 393, 524 )
thanks in advance !
according documentation, there 2 property on avassetimagegenerator. these properties allow define tolerance getting nearest frame. if put tolerance zero, generates frame request. here corrected instanciation of avassetimagegenerator :
avassetimagegenerator *generateimg = [[avassetimagegenerator alloc] initwithasset:asset]; generateimg.requestedtimetolerancebefore = kcmtimezero; generateimg.requestedtimetoleranceafter = kcmtimezero;
it slower big videos, in case don't have time stakes it's perfect.
Comments
Post a Comment