我正致力于视频裁剪。但是当我裁剪并保存它。它已经错误地保存到景观中。但它只在肖像视频的情况下,它与风景视频工作正常。我想上传图片以便您更好地理解,但至少需要10个声望。不幸的是我没有。
但我尝试过使用AVMutableVideoComposition。
MainInstruction.layerInstructions = [NSArray arrayWithObjects:FirstlayerInstruction,nil];
AVMutableVideoComposition *MainCompositionInst = [AVMutableVideoComposition videoComposition];
MainCompositionInst.instructions = [NSArray arrayWithObject:MainInstruction];
MainCompositionInst.frameDuration = origionalComposition.frameDuration;
MainCompositionInst.renderScale = 1.0;
MainCompositionInst.renderSize = CGSizeMake(nRenderWidth, nRenderHeight);
它不起作用。我不知道如何管理。有人知道请回答我,我在等待回应。 我正在使用AVAssetExportSession来保存裁剪的视频文件。
AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetMediumQuality];
exporter.outputURL=url;
exporter.outputFileType = AVFileTypeQuickTimeMovie;
//exporter.videoComposition = MainCompositionInst;
exporter.shouldOptimizeForNetworkUse = YES;
[exporter exportAsynchronouslyWithCompletionHandler:^
{
dispatch_async(dispatch_get_main_queue(), ^{
[self exportDidFinish:exporter];
});
}];
答案 0 :(得分:-2)
VAAssetTrak 有preferredTransform,此转换用于将视频旋转到正确的位置。
AVMutableVideoCompositionLayerInstruction* transformer = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:clipVideoTrack];
CGAffineTransform videoTransform = clipVideoTrack.preferredTransform;
if (videoTransform.a == 0 && videoTransform.b == 1.0 && videoTransform.c == -1.0 && videoTransform.d == 0) {
//portrait mode
t1 = CGAffineTransformMakeTranslation(clipVideoTrack.naturalSize.height-translateX, -translateY);
t2 = CGAffineTransformRotate(t1, M_PI_2);
finalTransform = t2;
[transformer setTransform:finalTransform atTime:kCMTimeZero];
}
if (videoTransform.a == 0 && videoTransform.b == -1.0 && videoTransform.c == 1.0 && videoTransform.d == 0) {
//portrait up side down
t1 = clipVideoTrack.preferredTransform;
t2 = CGAffineTransformConcat(t1,CGAffineTransformMakeTranslation(translateX , -translateY));
finalTransform = t2;
[transformer setTransform:finalTransform atTime:kCMTimeZero];
}
if (videoTransform.a == 1.0 && videoTransform.b == 0 && videoTransform.c == 0 && videoTransform.d == 1.0) {
//landscape right
t1 = clipVideoTrack.preferredTransform;
t2 = CGAffineTransformConcat(t1,CGAffineTransformMakeTranslation(-translateX , -translateY));
finalTransform = t2;
[transformer setTransform:finalTransform atTime:kCMTimeZero];
}
if (videoTransform.a == -1.0 && videoTransform.b == 0 && videoTransform.c == 0 && videoTransform.d == -1.0) {
//landscape left
t1 = clipVideoTrack.preferredTransform;
t2 = CGAffineTransformConcat(t1,CGAffineTransformMakeTranslation(-translateX , -translateY));
finalTransform = t2;
[transformer setTransform:finalTransform atTime:kCMTimeZero];
}
//add the transformer layer instructions, then add to video composition
instruction.layerInstructions = [NSArray arrayWithObjects:transformer,nil];
特别是" // FIXING ORIENTATION //"