Note that there are some explanatory texts on larger screens.

plurals
  1. POAVMutableAudioMix and AVAssetExportSession
    text
    copied!<p>I want to make fade in/out effect for export session. But it doesn't work. Please help me!</p> <p>Trim works perfect! But fade in/out doesn't :(((</p> <pre><code> 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-&gt;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]; }]; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload