Я борюсь с приведенным ниже кодом.
Я получил NSProgress
для работы с QTMovieModernizer
- но последние 90% конверсии происходят очень быстро (менее 1во-вторых) и создает более 700 уведомлений KVO по сравнению с ≈20 таких уведомлений в течение первых 90%.
Может ли кто-нибудь просветить меня об этом? Это было бы очень признательно!
QTMovieModernizer *modernizer; // instance variable
-(BOOL)doModernizerOnMovie:(NSURL *)inputURL writeToFile:(NSURL *)outputURL
{
if (!inputURL || !outputURL)
return NO;
modernizer = [[QTMovieModernizer alloc] initWithSourceURL:inputURL
destinationURL:outputURL];
__block BOOL doneModernizing = NO;
__block NSError *modernizerError = nil;
// set up progress watcher
NSProgress *progress = [NSProgress progressWithTotalUnitCount:1];
[progress addObserver:self
forKeyPath:NSStringFromSelector(@selector(fractionCompleted))
options:NSKeyValueObservingOptionInitial
context:&modernizer];
[progress becomeCurrentWithPendingUnitCount:1];
dispatch_semaphore_t waitForModernize = dispatch_semaphore_create(1);
dispatch_semaphore_wait(waitForModernize, DISPATCH_TIME_FOREVER);
[modernizer setOutputFormat:QTMovieModernizerOutputFormat_AppleProRes4444];
[modernizer modernizeWithCompletionHandler:^{
[progress removeObserver:self
forKeyPath:NSStringFromSelector(@selector(fractionCompleted))
context:&self->modernizer];
modernizerError = [self->modernizer error];
doneModernizing = YES;
dispatch_semaphore_signal(waitForModernize);
}];
dispatch_semaphore_wait(waitForModernize, DISPATCH_TIME_FOREVER);
[progress resignCurrent];
dispatch_semaphore_signal(waitForModernize);
if (modernizerError!=nil) {
NSLog(@"Modernizer error %@",modernizerError.description);
return NO;
}
return YES;
}
-(void) observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary<nskeyvaluechangekey,id> *)change
context:(void *)context
{
if (context == &modernizer) {
NSProgress *progress = object;
NSLog(@"Total work done: %2.2f",progress.fractionCompleted);
}
else
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
2019-02-07 20:35:39.517067-0800 CDTest[2055:102993] Total work done: 0.00
2019-02-07 20:35:39.517681-0800 CDTest[2055:102857] Total work done: 0.03
2019-02-07 20:35:39.518859-0800 CDTest[2055:102857] Total work done: 0.05
2019-02-07 20:35:39.518920-0800 CDTest[2055:102857] Total work done: 0.10
2019-02-07 20:35:40.705553-0800 CDTest[2055:102857] Total work done: 0.12
2019-02-07 20:35:41.795755-0800 CDTest[2055:102857] Total work done: 0.18
2019-02-07 20:35:42.860847-0800 CDTest[2055:102857] Total work done: 0.23
2019-02-07 20:35:43.954465-0800 CDTest[2055:102857] Total work done: 0.31
2019-02-07 20:35:45.042048-0800 CDTest[2055:102857] Total work done: 0.36
2019-02-07 20:35:46.130878-0800 CDTest[2055:102857] Total work done: 0.42
2019-02-07 20:35:47.207742-0800 CDTest[2055:102857] Total work done: 0.47
2019-02-07 20:35:48.305811-0800 CDTest[2055:102857] Total work done: 0.52
2019-02-07 20:35:49.405433-0800 CDTest[2055:102857] Total work done: 0.57
2019-02-07 20:35:50.502851-0800 CDTest[2055:102857] Total work done: 0.63
2019-02-07 20:35:51.590723-0800 CDTest[2055:102857] Total work done: 0.71
2019-02-07 20:35:52.636067-0800 CDTest[2055:102857] Total work done: 0.76
2019-02-07 20:35:53.728937-0800 CDTest[2055:102857] Total work done: 0.81
2019-02-07 20:35:54.817713-0800 CDTest[2055:102857] Total work done: 0.90
2019-02-07 20:35:54.825667-0800 CDTest[2055:102857] Total work done: 0.90
**<snipped about 700 lines>**
2019-02-07 20:35:55.866583-0800 CDTest[2055:102857] Total work done: 1.00
2019-02-07 20:35:55.868668-0800 CDTest[2055:102857] Total work done: 1.00
2019-02-07 20:35:55.868716-0800 CDTest[2055:102857] Total work done: 1.00
2019-02-07 20:35:55.868750-0800 CDTest[2055:102857] Total work done: 1.00