我想使导出会话的淡入/淡出效果。但它不起作用。请帮帮我!AVMutableAudioMix和AVAssetExportSession
修剪作品完美!但是淡入/淡出并不:(((
NSURL *assetURL = [song valueForProperty:MPMediaItemPropertyAssetURL];
AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:assetURL options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]
initWithAsset:songAsset
presetName:AVAssetExportPresetPassthrough];
NSArray *tracks = [songAsset tracksWithMediaType:AVMediaTypeAudio];
AVAssetTrack *track = [tracks objectAtIndex:0];
id desc = [track.formatDescriptions objectAtIndex:0];
const AudioStreamBasicDescription *audioDesc = CMAudioFormatDescriptionGetStreamBasicDescription((CMAudioFormatDescriptionRef)desc);
FourCharCode formatID = audioDesc->mFormatID;
// trim track
CMTime startTrimTime = CMTimeMakeWithSeconds(startTime, 1);
CMTime endTrimTime = CMTimeMakeWithSeconds(endTime, 1);
CMTimeRange exportTimeRange = CMTimeRangeFromTimeToTime(startTrimTime, endTrimTime);
exportSession.timeRange = exportTimeRange;
//add fade in, fade out
CMTime startFadeInTime = startTrimTime;
CMTime endFadeInTime = CMTimeMakeWithSeconds(startTime + 4.0, 1);
CMTimeRange fadeInTimeRange = CMTimeRangeFromTimeToTime(startFadeInTime, endFadeInTime);
CMTime startFadeOutTime = CMTimeMakeWithSeconds(endTime - 4.0, 1);
CMTime endFadeOutTime = endTrimTime;
CMTimeRange fadeOutTimeRange = CMTimeRangeFromTimeToTime(startFadeOutTime, endFadeOutTime);
AVMutableAudioMix *exportAudioMix = [AVMutableAudioMix audioMix];
//AVMutableAudioMixInputParameters *exportAudioMixInputParameters = [AVMutableAudioMixInputParameters audioMixInputParameters];
AVMutableAudioMixInputParameters *exportAudioMixInputParameters = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:track];
[exportAudioMixInputParameters setVolumeRampFromStartVolume:0.0 toEndVolume:1.0 timeRange:fadeInTimeRange];
[exportAudioMixInputParameters setVolumeRampFromStartVolume:1.0 toEndVolume:0.0 timeRange:fadeOutTimeRange];
exportAudioMix.inputParameters = [NSArray arrayWithObject:exportAudioMixInputParameters];
exportSession.audioMix = exportAudioMix;
...
myDeleteFile(filePath);
exportSession.outputURL = [NSURL fileURLWithPath:filePath];
[exportSession exportAsynchronouslyWithCompletionHandler:^{
if (exportSession.status == AVAssetExportSessionStatusCompleted) {
NSLog(@"export session completed");
//
//return YES;
} else {
NSLog(@"export session error");
//return NO;
}
[exportSession release];
}];
有你找到了这个解决方案?请帮忙。 – iPhoneDv 2012-06-16 15:53:26
“start”的定义在哪里? – zakdances 2012-07-30 16:54:47