video.mp4 비디오로 audio.caf 오디오 파일을 내보내고 새 output.mp4 컴포지션을 만듭니다. iOS 5.0에서는 잘 작동하지만 iPhone4 4.2.1에서는 오디오가 재생되지 않습니다.AVAssetExportSession을 사용하여 오디오 + 비디오를 내 보냈지 만 iphone4에서 오디오가 재생되지 않습니다. 4.2.1
NSURL *outputURL = [NSURL fileURLWithPath:outputPath];
AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetMediumQuality];
_assetExport.outputFileType = AVFileTypeQuickTimeMovie;
_assetExport.outputURL = outputURL;
_assetExport.timeRange = CMTimeRangeMake(CMTimeMakeWithSeconds(0.25, 600), videoAsset.duration);
_assetExport.shouldOptimizeForNetworkUse = YES;
[_assetExport exportAsynchronouslyWithCompletionHandler:^{
이 아이폰의 원본 트랙을 확인했는데 둘 다 괜찮습니다. 음악 만 컴포지션에 추가합니다.
이 내가 조성물에 오디오 트랙을 추가 해요 방법은 다음과 같습니다
NSURL *audioURL = [NSURL fileURLWithPath:audioPath];
AVURLAsset* audioAsset = [[AVURLAsset alloc]initWithURL:audioURL options:nil];
CMTimeRange audio_timeRange = CMTimeRangeMake(CMTimeMake(startRecording_,1),
audioAsset.duration);
AVMutableCompositionTrack *b_compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
[b_compositionAudioTrack insertTimeRange:audio_timeRange ofTrack:[[audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:kCMTimeZero error:&error];
그것은 많은 iOS5를 장치에서 근무 : S 미리
감사합니다!
질문과 관련이 없지만 'timeRange'가'kCMTimeZero'가 아닌 '0.25'에서 시작하도록 설정된 이유는 무엇입니까? 이것에 대한 특별한 이유가 있습니까? –
예, 해당 비디오를 Facebook에 업로드하고 미리보기에 검은 화면이 나타납니다. 이를 피하고 "무언가"를 미리보기 위해 1/4 초 후에 비디오를 시작해야했기 때문에 Facebook의 미리보기가 검은 색이 아니라 비디오의 실제 프레임이됩니다. – nano