JWo*_*ood 8 iphone core-graphics core-video ipad
我正在尝试使用a将视频旋转到正确的方向AVAssetExportSession,我总是会收到以下错误:
Error Domain=AVFoundationErrorDomain Code=-11841 "The operation couldn’t be completed. (AVFoundationErrorDomain error -11841.)"
Run Code Online (Sandbox Code Playgroud)
这转化为AVErrorInvalidVideoComposition但我看不出我的视频构图有什么问题.这是代码:
AVAssetTrack *sourceVideo = [[avAsset tracksWithMediaType:AVMediaTypeVideo] lastObject];
AVAssetTrack *sourceAudio = [[avAsset tracksWithMediaType:AVMediaTypeAudio] lastObject];
CGAffineTransform preferredTransform = [sourceVideo preferredTransform];
AVMutableComposition *composition = [[AVMutableComposition alloc] init];
AVMutableCompositionTrack *compositionVideoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo
preferredTrackID:kCMPersistentTrackID_Invalid];
AVAssetExportSession *exporter = [[[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetMediumQuality] autorelease];
[compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, avAsset.duration)
ofTrack:sourceVideo
atTime:kCMTimeZero
error:nil];
if( !CGAffineTransformIsIdentity(preferredTransform) ) {
AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoComposition];
videoComposition.renderSize = CGSizeMake([avAsset naturalSize].height, [avAsset naturalSize].width);
videoComposition.frameDuration = CMTimeMake(1, compositionVideoTrack.naturalTimeScale);
AVMutableVideoCompositionLayerInstruction *instruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:sourceVideo];
[instruction setTransform:preferredTransform atTime:kCMTimeZero];
AVMutableVideoCompositionInstruction *videoTrackInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
videoTrackInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, avAsset.duration);
videoTrackInstruction.layerInstructions = [NSArray arrayWithObject:instruction];
[videoComposition setInstructions:[NSArray arrayWithObject:videoTrackInstruction]];
exporter.videoComposition = videoComposition;
}
AVMutableCompositionTrack *compositionAudioTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio
preferredTrackID:kCMPersistentTrackID_Invalid];
[compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, avAsset.duration)
ofTrack:sourceAudio
atTime:kCMTimeZero
error:nil];
exporter.outputURL = tempPathUrl;
exporter.outputFileType = AVFileTypeQuickTimeMovie;
[exporter exportAsynchronouslyWithCompletionHandler:^{ }];
Run Code Online (Sandbox Code Playgroud)
这个构图有什么问题?我已经阅读了文档,到目前为止看不出任何问题.
这可能与您的帧持续时间有关。您正在使用
CMTimeMake(1, naturalTimeScale)
您应该检查naturalTimeScale,因为它并不总是等于fps。有关详细信息,请参阅AVFoundation 编程指南“时间的表示”。
| 归档时间: |
|
| 查看次数: |
4054 次 |
| 最近记录: |