ios - 合并后视频旋转问题
问题描述
我正在使用 AVFoundation 框架合并视频。合并后一些视频正在改变位置并旋转(横向到纵向,反之亦然)。如何解决这个问题。
我的代码:
func mergeVideos(arrayVideos:[AVAsset])
{
var atTimeM: CMTime = CMTimeMake(0, 0)
var layerInstructionsArray = [AVVideoCompositionLayerInstruction]()
var completeTrackDuration: CMTime = CMTimeMake(0, 1)
var videoSize: CGSize = CGSize(width: 0.0, height: 0.0)
var totalTime : CMTime = CMTimeMake(0, 0)
let mixComposition = AVMutableComposition.init()
for videoAsset in arrayVideos{
let videoTrack = mixComposition.addMutableTrack(withMediaType: AVMediaType.video, preferredTrackID: Int32(kCMPersistentTrackID_Invalid))
do {
if videoAsset == arrayVideos.first {
atTimeM = kCMTimeZero
} else {
atTimeM = totalTime // <-- Use the total time for all the videos seen so far.
}
try videoTrack?.insertTimeRange(CMTimeRangeMake(kCMTimeZero, videoAsset.duration),
of: videoAsset.tracks(withMediaType: AVMediaType.video)[0],
at: completeTrackDuration)
videoSize = (videoTrack?.naturalSize)!
} catch let error as NSError {
print("error: \(error)")
}
totalTime = CMTimeAdd(totalTime, videoAsset.duration)
let exporter = AVAssetExportSession(asset: mixComposition, presetName: AVAssetExportPresetHighestQuality)
解决方案
推荐阅读
- python - ForwardManyToOneDescriptor'对象没有属性'slug Django using reverse
- arrays - 如何使用 jq 将 bash 数组添加到 JSON 数组的字段中?
- apache-kafka - 相同的偏移量和分区记录被消耗两次导致重复
- r - Bookdown:定理编号的控制
- x86 - 我应该如何在笔记本电脑的 CPU 中找到流水线阶段的数量
- javascript - JS检索一年中的第一天和最后一天
- intellij-idea - 隐藏参数信息弹出的快捷方式 intellij idea
- javascript - 交替`
- mysql - 如何正确设置 MySQL 触发器
- r - 如何在不打开的情况下打开R控制台介绍