iVidCap プラグインを使用して作成したビデオにオーディオを追加しようとしています。基本的に、この質問とまったく同じです:ビデオ + 生成されたオーディオを AVAssetWriterInput に書き込み、オーディオが吃音します。この記事のコードをベースとして、iVidCap.mm ファイルを自分で変更しようとしましたが、アプリは常に endRecordingSession でクラッシュします。
オーディオに対応するために endRecordingSession をどのように変更する必要があるのか わかりません(元のプラグインはビデオファイルを作成するだけです)。関数は次のとおりです。
- (int) endRecordingSession: (VideoDisposition) action {
NSLog(@"Start endRecordingSession");
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSLog(@"Auto released pool");
NSString *filePath;
BOOL success = false;
[videoWriterInput markAsFinished];
NSLog(@"Mark video writer input as finished");
//[audioWriterInput markAsFinished];
// Wait for the video status to become known.
// Is this really doing anything?
int status = videoWriter.status;
while (status == AVAssetWriterStatusUnknown) {
NSLog(@"Waiting for video to complete...");
[NSThread sleepForTimeInterval:0.5f];
status = videoWriter.status;
}
NSLog(@"Video completed");
@synchronized(self) {
success = [videoWriter finishWriting];
NSLog(@"Success: %@", success);
if (!success) {
// We failed to successfully finalize the video file.
NSLog(@"finishWriting returned NO");
} else {
// The video file was successfully written to the Documents folder.
filePath = [[self getDocumentsFileURL:videoFileName] path];
if (action == Save_Video_To_Album) {
// Move the video to an accessible location on the device.
NSLog(@"Temporary video filePath=%@", filePath);
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(filePath)) {
NSLog(@"Video IS compatible. Adding it to photo album.");
UISaveVideoAtPathToSavedPhotosAlbum(filePath, self, @selector(copyToPhotoAlbumCompleteFromVideo: didFinishSavingWithError: contextInfo:), nil);
} else {
NSLog(@"Video IS NOT compatible. Could not be added to the photo album.");
success = NO;
}
} else if (action == Discard_Video) {
NSLog(@"Video cancelled. Removing temporary video file: %@", filePath);
[self removeFile:filePath];
}
}
[self cleanupWriter];
}
isRecording = false;
[pool drain];
return success; }
現在、[videoWriter finishWriting] でクラッシュします。[audioWriterInput markAsFinished] を追加してみましたが、その上でクラッシュします。元の投稿者に連絡してみましたが、うまくいったようですが、プライベート メッセージを送信する方法はないようです。
これを機能させる方法やクラッシュする理由について何か提案はありますか? 私はこれを理解するために最善を尽くしましたが、Obj-C にはかなり慣れていません。必要に応じて、残りのコードを投稿できます (その多くは、以前に参照した元の投稿にあります)。