gpt4 book ai didi

iphone - AVAssetExportSession dealloc 在 iOS 4.3 中崩溃

转载 作者:行者123 更新时间:2023-12-03 21:07:53 25 4
gpt4 key购买 nike

更新:我认为问题是内存不足;它不是。此错误在 4.3 中始终发生,而在 4.1/4.2 中即使在内存非常低的情况下也不会发生。

这是在一个小型 Objective-C 库中,我必须为主要是 Monotouch 应用程序编写——AVFoundation 尚未完全绑定(bind)。

这是跟踪:

0   Orbiter                             0x007977d8 mono_handle_native_sigsegv + 404
1 Orbiter 0x007746b4 mono_sigsegv_signal_handler + 348
2 libsystem_c.dylib 0x34ce472f _sigtramp + 42
3 AVFoundation 0x365b3ab5 -[AVAssetExportSession dealloc] + 164
4 CoreFoundation 0x34bc2c43 -[NSObject(NSObject) release] + 30
5 AVFoundation 0x365b3607 -[AVAssetExportSession release] + 62
6 CoreFoundation 0x34bdd047 sendRelease + 14
7 libsystem_blocks.dylib 0x312c292f _Block_object_dispose + 118
8 AVFoundation 0x365b45b3 __destroy_helper_block_5 + 22
9 libsystem_blocks.dylib 0x312c288f _Block_release + 58
10 libdispatch.dylib 0x30df18ed _dispatch_call_block_and_release + 16
11 libdispatch.dylib 0x30deced1 _dispatch_queue_drain + 240
12 libdispatch.dylib 0x30ded043 _dispatch_queue_invoke + 78
13 libdispatch.dylib 0x30dec611 _dispatch_worker_thread2 + 196
14 libsystem_c.dylib 0x34cda591 _pthread_wqthread + 264
15 libsystem_c.dylib 0x34cdabc4 _init_cpu_capabilities + 4294967295

代码如下:

@implementation AVUtils : NSObject

+ (void) dubAudio:(NSURL*)videoUrl
withTrack:(NSURL*)audioUrl
outputTo:(NSURL*)newUrl
handleSuccess:(void(^)(void))successHandler
handleFailure:(void(^)(NSError* err))failureHandler
{
AVURLAsset* video = [[AVURLAsset alloc]initWithURL:videoUrl options:nil];
AVAssetTrack* videoTrack = [[video tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
CMTime videoDuration = video.duration;

AVURLAsset* audio = [[AVURLAsset alloc]initWithURL:audioUrl options:nil];
AVAssetTrack* audioTrack = [[audio tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];
CMTime audioDuration = audio.duration;

CMTime newDuration = CMTimeMinimum(audioDuration, videoDuration);
CMTimeRange newTimeRange = CMTimeRangeMake(kCMTimeZero, newDuration);

AVMutableComposition* newComposition = [AVMutableComposition composition];
NSError* theError;
BOOL success;

AVMutableCompositionTrack* newAudioTrack = [newComposition addMutableTrackWithMediaType:AVMediaTypeAudio
preferredTrackID:kCMPersistentTrackID_Invalid];
theError = nil;
success = [newAudioTrack insertTimeRange:newTimeRange ofTrack:audioTrack atTime:kCMTimeZero error:&theError];
if (success == NO) {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Error adding audio track"
message:[theError localizedDescription]
delegate: nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:nil];
[alertView show];
[alertView release];
} else {

AVMutableCompositionTrack* newVideoTrack = [newComposition addMutableTrackWithMediaType:AVMediaTypeVideo
preferredTrackID:kCMPersistentTrackID_Invalid];
theError = nil;
success = [newVideoTrack insertTimeRange:newTimeRange ofTrack:videoTrack atTime:kCMTimeZero error:&theError];
if (success == NO) {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Error adding audio track"
message:[theError localizedDescription]
delegate: nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:nil];
[alertView show];
[alertView release];
} else {

AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:newComposition presetName:AVAssetExportPresetPassthrough];
_assetExport.outputFileType = @"com.apple.quicktime-movie";
_assetExport.outputURL = newUrl;
_assetExport.shouldOptimizeForNetworkUse = YES;

[_assetExport exportAsynchronouslyWithCompletionHandler:
^(void) {
if (_assetExport.status == AVAssetExportSessionStatusCompleted) {
successHandler();
} else {
failureHandler(_assetExport.error);
}

[_assetExport release];
[video release];
[audio release];
[newComposition release];
}
];
}
}
}
@end

我的理论是,我泄漏了指向 _assetExport.error 的指针,将其传递给另一个线程(我就是这样),然后在取消引用时它无效,因为 _assetExport 正在被垃圾收集。但我验证了即使导出成功也会发生段错误,所以在本例中不是这样。

我对 Obj-C 还很陌生——任何人都可以看到我在这里所做的任何其他明显的缺陷吗?

最佳答案

看起来与完成 block 有关的内存管理是问题所在。崩溃日志表明它在释放 _assetExport 时崩溃。您绝对不应该释放 newComposition (您没有分配或保留它)。

关于iphone - AVAssetExportSession dealloc 在 iOS 4.3 中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5346382/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com