[英]AVAssetExportSession not exporting time range
我有这个问题。 我正在通过AVAssetExportSession修剪声音文件。 我设置时间范围,然后异步导出。 我将输出文件保存在与输入文件不同的名称下。
它工作正常,但这是第一次。 当我尝试修剪修剪过的文件时,它会以整个持续时间导出它,但CMTimeRangeShow显示正确的时间范围。
谁知道,我做错了什么?
我不确定我的代码现在可用,因为它适用于iOS7。 我希望这能帮到您。
- (BOOL)trimAudio :(NSURL *) url
{
float vocalStartMarker = timeFrom;
float vocalEndMarker = timeTo;
NSURL *audioFileInput = url_Audio;
NSURL *audioFileOutput = url;
if (!audioFileInput || !audioFileOutput)
{
return NO;
}
[[NSFileManager defaultManager] removeItemAtURL:audioFileOutput error:NULL];
AVAsset *asset = [AVAsset assetWithURL:audioFileInput];
AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:asset
presetName:AVAssetExportPresetAppleM4A];
if (exportSession == nil)
{
return NO;
}
CMTime startTime = CMTimeMake((int)(floor(vocalStartMarker * 100)), 100);
CMTime stopTime = CMTimeMake((int)(ceil(vocalEndMarker * 100)), 100);
CMTimeRange exportTimeRange = CMTimeRangeFromTimeToTime(startTime, stopTime);
exportSession.outputURL = audioFileOutput;
exportSession.outputFileType = AVFileTypeAppleM4A;
exportSession.timeRange = exportTimeRange;
[exportSession exportAsynchronouslyWithCompletionHandler:^
{
if (AVAssetExportSessionStatusCompleted == exportSession.status)
{
// It worked!
}
else if (AVAssetExportSessionStatusFailed == exportSession.status)
{
// It failed...
[[[UIAlertView alloc]initWithTitle:@"Unknown Error" message:nil delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]show];
}
}];
return YES;
}
您应该检查输出文件是否已存在。
“exportAsynchronouslyWithCompletionHandler”不会覆盖outputfile。
在exportAsynchronouslyWithCompletionHandler
检查导出会话的state
和error
信息,确保输出URL文件不存在。
参考这两个主题,祝你好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.