ios - 带有指令的 AVAssetExportSession 使黑屏
<p><p>我正在尝试将 2 个音频文件和 1 个视频文件合并为 1 个 .mov 文件。我用下一个代码实现了它:</p>
<pre><code>-(void)combineData{
AVMutableComposition *mixComposition = [ init];
AVAsset *audioAsset = ;
AVAsset* audioAsset2 = ]]];
AVURLAsset *videoAsset = ]] options:nil];
AVMutableCompositionTrack *firstTrack = ;
objectAtIndex:0] atTime:kCMTimeZero error:nil];
AVMutableCompositionTrack *secondTrack = ;
objectAtIndex:0] atTime:kCMTimeZero error:nil];
AVMutableCompositionTrack *videoTrack = ;
objectAtIndex:0] atTime:kCMTimeZero error:nil];
AVMutableVideoCompositionLayerInstruction *layerInstruction = ;
/*CGAffineTransform rotationTransform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(90));
CGAffineTransform rotateTranslate = CGAffineTransformTranslate(rotationTransform,320,0);*/
;
AVMutableVideoCompositionInstruction * mainInstruction = ;
mainInstruction.timeRange = CMTimeRangeMake(kCMTimeZero, videoAsset.duration);
];
mixComposition.naturalSize = videoTrack.naturalSize;
AVMutableVideoComposition *mainCompositionInst = ;
mainCompositionInst.renderScale = 1.0;
mainCompositionInst.renderSize = videoTrack.naturalSize;
mainCompositionInst.frameDuration = CMTimeMake(1, 30);
mainCompositionInst.instructions = ;
//mainCompositionInst.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = ;
NSString *myPathDocs =;
if ([ fileExistsAtPath:myPathDocs]) {
[ removeItemAtPath:myPathDocs error:nil];
NSLog(@"Removing old mergeVideo");
}
NSURL *url = ;
AVAssetExportSession *exporter = [ initWithAsset:mixComposition presetName:AVAssetExportPresetHighestQuality];
exporter.outputURL=url;
exporter.outputFileType = AVFileTypeQuickTimeMovie;
exporter.videoComposition = mainCompositionInst;
exporter.shouldOptimizeForNetworkUse = YES;
[exporter exportAsynchronouslyWithCompletionHandler:^
{
dispatch_async(dispatch_get_main_queue(), ^{
;
});
}];
</code></pre>
<p>我的第一个任务是处理我的新视频 90 次旋转。当我将 <code>mainCompositionInst</code> 包含到我的代码中时,我的新视频有所有声音,但它有一个黑屏并且仍然没有旋转。如果我不使用任何说明,它可以正常工作。也许我的代码有错误,也可能没有。你有什么建议?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我会尝试在 <code>preferredTransform</code> 顶部应用旋转,因为 <code>preferredTransform</code> 可能会翻译您的视频,使其正确显示在屏幕上。</p>
<p>我会尝试以下方法:</p>
<pre><code>CGAffineTransform transform = videoTrack.preferredTransform;
transform = CGAffineTransformRotate(transform, DEGREES_TO_RADIANS(90));
//transform = CGAffineTransformTranslate(transform, 320, 0);
;
</code></pre></p>
<p style="font-size: 20px;">关于ios - 带有指令的 AVAssetExportSession 使黑屏,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/21235467/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/21235467/
</a>
</p>
页:
[1]