Проблема заключается в двух местах:
1.Путь, который вы указываете, должен быть таким, чтобы вы могли писать как каталог документов.И это должно иметь определенное расширение.Когда вы создаете HighestQualityVideo, оно должно быть .mov.
2.Вы должны предоставить правильный outputFileType, соответствующий расширению и presetType.так что в вашем случае это должно быть _assetExport.outputFileType = AVFileTypeQuickTimeMovie;
.
Попробуйте с этими изменениями.
Обновление: Чтобы удалить ошибку, вам нужно заменить код для AVAssetTrack
наследующий код в методе addAudioToFileAtPath
:
NSArray *tracks = [videoAsset tracksWithMediaType:AVMediaTypeAudio];
if([tracks count]>0)
{
AVAssetTrack * audioAssetTrack = [tracks objectAtIndex:0];
AVMutableCompositionTrack *compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio
preferredTrackID: kCMPersistentTrackID_Invalid];
[compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero,videoAsset.duration) ofTrack:audioAssetTrack atTime:kCMTimeZero error:nil];
//nextClipStartTime = CMTimeAdd(nextClipStartTime, a_timeRange.duration);
[audioAsset release];audioAsset = nil;
}
Относительно типов видео:
Facebook поддерживает QuickTimeVideo (mov / qt), см. http://www.facebook.com/help/?faq=218673814818907
Для поддержки другого типавидео, которые вам нужно будет изменить presetName
при создании объекта AVAssetExportSession
и расширения выходного файла, для этого, пожалуйста, просмотрите этот документ.
http://www.google.co.in/url?sa=t&rct=j&q=AVAssetExportSession++class&source=web&cd=1&ved=0CCYQFjAA&url=http%3A%2F%2Fdeveloper.apple.com%2Flibrary%2Fios%2FDOCUMENTATION%2FAVFoundation%2FReference%2FAVAssetExportSession_Class%2FReference%2FReference.html&ei=xXxPT5akDsG8rAeck5XUDQ&usg=AFQjCNH1HqxIiT1kYJom6kZ82NS-qjVSyQ&cad=rja
Обновление 1:
Здесь мы получаем доступ к каждому изображению и добавляем его в буфер после отображения некоторого времени (я разделил продолжительность.
for (int i=0; i<[image1array count]; i++)
{
int time = (int)i*(duration/[image1array count]);
CVPixelBufferRef buffer = [self pixelBufferFromCGImage:[[image1array objectAtIndex:i] CGImage]];
[adaptor appendPixelBuffer:buffer withPresentationTime:CMTimeMake(time, 1)];
}
Обновление 2:
Вот код, в котором я внес несколько изменений в состав смешанного актива.
-(void) addAudioToFileAtPath:(NSString *)vidoPath andAudioPath:(NSString *)audioFilePath{
NSURL* audio_inputFileUrl = [NSURL fileURLWithPath:audioFilePath];
NSURL* video_inputFileUrl = [NSURL fileURLWithPath:ImageVideoPath];
NSURL* outputFileUrl = [NSURL fileURLWithPath:FinalVideoPath];
AVMutableComposition *composition = [AVMutableComposition composition];
AVAsset * audioAsset = [AVURLAsset URLAssetWithURL:audio_inputFileUrl options:nil];;
AVAsset * videoAsset = [AVURLAsset URLAssetWithURL:video_inputFileUrl options:nil];
AVMutableCompositionTrack *compositionVideoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo
preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableCompositionTrack *compositionAudioTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio
preferredTrackID:kCMPersistentTrackID_Invalid];
NSError *error = nil;
BOOL ok = NO;
CMTimeRange video_timeRange = CMTimeRangeMake(kCMTimeZero,videoAsset.duration);
AVAssetTrack *sourceVideoTrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
ok = [compositionVideoTrack insertTimeRange:video_timeRange ofTrack:sourceVideoTrack atTime:kCMTimeZero error:&error];
if (!ok) {
// Deal with the error.
NSLog(@"Error : %@ : %d",error,videoAsset.duration.value);
}
CMTimeRange audio_timeRange = CMTimeRangeMake(kCMTimeZero, audioAsset.duration);
AVAssetTrack *sourceAudioTrack = [[audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];
ok = [compositionAudioTrack insertTimeRange:audio_timeRange ofTrack:sourceAudioTrack atTime:kCMTimeZero error:&error];
if (!ok) {
// Deal with the error.
NSLog(@"Error : %@ : %d",error,audioAsset.duration.value);
}
AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetHighestQuality];
_assetExport.outputFileType = AVFileTypeQuickTimeMovie;
_assetExport.outputURL = outputFileUrl;
[_assetExport exportAsynchronouslyWithCompletionHandler:
^(void ) {
switch (_assetExport.status)
{
case AVAssetExportSessionStatusCompleted:
//export complete
NSLog(@"Export Complete");
break;
case AVAssetExportSessionStatusFailed:
NSLog(@"Export Failed");
NSLog(@"ExportSessionError: %@", [_assetExport.error localizedDescription]);
//export error (see exportSession.error)
break;
case AVAssetExportSessionStatusCancelled:
NSLog(@"Export Failed");
NSLog(@"ExportSessionError: %@", [_assetExport.error localizedDescription]);
//export cancelled
break;
}
NSLog(@"Error : %@",_assetExport.error);
}];
}
Спасибо