Ios AVMutableComposition缺失帧记录器,配备iPad的差分摄像头
我使用著名的PBJVision录制视频,然后必须将这些视频组合在一起。 我使用AVMutableComposition来组合视频 insertTimeRange(3;:of资产:时间:错误:)。如果视频是用同一台相机拍摄的,效果会很好。但是,例如,如果一个是用后置相机拍摄的,然后用前摄相机拍摄另一个,则后一个视频的视频将丢失。看起来只添加了音频。这是我的密码:Ios AVMutableComposition缺失帧记录器,配备iPad的差分摄像头,ios,camera,avfoundation,avmutablecomposition,Ios,Camera,Avfoundation,Avmutablecomposition,我使用著名的PBJVision录制视频,然后必须将这些视频组合在一起。 我使用AVMutableComposition来组合视频 insertTimeRange(3;:of资产:时间:错误:)。如果视频是用同一台相机拍摄的,效果会很好。但是,例如,如果一个是用后置相机拍摄的,然后用前摄相机拍摄另一个,则后一个视频的视频将丢失。看起来只添加了音频。这是我的密码: var error: NSError? = nil let composition = AVMutableCompositio
var error: NSError? = nil
let composition = AVMutableComposition()
var currentTime = kCMTimeZero
for (index, videoURL) in enumerate(videoURLS) {
let asset = AVURLAsset.assetWithURL(videoURL) as! AVAsset
let success = composition.insertTimeRange(CMTimeRange(start: kCMTimeZero, duration: asset.duration),
ofAsset: asset,
atTime: currentTime,
error: &error)
if !success {
if error != nil {
println("timerange isnert error - \(error?.localizedDescription)")
}
}
// add time till we get to the last video
if index < videoURLS.count - 1 {
currentTime = CMTimeAdd(currentTime, asset.duration)
}
}
let outputURL = fileSystemHelper.temporaryStorageURLForExportSession()
let fileManager = NSFileManager.defaultManager()
fileManager.removeItemAtURL(outputURL, error: &error)
if error != nil {
println("export session file removal error - \(error?.localizedDescription)")
}
let exportSession = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetHighestQuality)
exportSession.outputFileType = AVFileTypeMPEG4
exportSession.outputURL = outputURL
let start = CMTimeMake(0, 1)
let range = CMTimeRangeMake(start, composition.duration)
//exportSession.timeRange = range
exportSession.exportAsynchronouslyWithCompletionHandler { () -> Void in
switch exportSession.status {
case .Completed:
self.fileSystemHelper.copyFileAtURL(outputURL, toURL: finalURL)
self.appendURL = nil
// self.isRecording = false
completion()
case .Failed:
println("fail error - \(exportSession.error.localizedDescription)")
self.fileSystemHelper.removeFileAtURL(outputURL)
self.appendURL = nil
//self.isRecording = false
println("failed to mix")
// delegate?.videoCaptureDidFinishRecordingVideoAtURL(URL, appended: appendURL == nil)
default:
println("something else happened, check code")
}
}
var错误:n错误?=无
let composition=AVMutableComposition()
var currentTime=kCMTimeZero
用于枚举(videoURL)中的(索引、videoURL){
将asset=avurlaste.assetwithur(videoURL)设为!AVAsset
让success=composition.insertTimeRange(CMTimeRange(开始:kCMTimeZero,持续时间:asset.duration),
资产类别:资产,
时间:现在,
错误:&错误)
如果!成功{
如果错误!=nil{
println(“时间范围isnert错误-\(错误?.localizedDescription)”)
}
}
//添加时间,直到我们看到最后一个视频
如果索引中的Void
切换exportSession.status{
案件.已完成:
self.fileSystemHelper.copyFileAtURL(outputURL,toURL:finalURL)
self.appendURL=nil
//self.isRecording=false
完成()
案例。失败:
println(“失败错误-\(exportSession.error.localizedDescription)”)
self.fileSystemHelper.removeFileAtURL(outputURL)
self.appendURL=nil
//self.isRecording=false
println(“未能混合”)
//委托?.VideoCaptureDidFinishRecordingVideoAttribute(URL,附加:appendURL==nil)
违约:
println(“发生了其他事情,请检查代码”)
}
}
在我问了这个问题之后,我在附近的一次夜间散步中找到了答案:)因此不同的相机具有不同的最大可能分辨率,从而产生了不同大小的帧,从而混淆了合成对象。它使用第一个视频的大小,并忽略具有不同大小的视频帧。
因此,请测试并查看特定设备上两个摄像头支持的最佳分辨率AVCaptureSessionPreset。然后在视频捕获代码中使用该预设,不要直接跳到使用AVCaptureSessionPresetHigh
我希望这也能对其他人有所帮助:)您能详细说明一下“因此,请测试并查看两台相机在设备上的最佳分辨率,并将预设设置为它,而不是直接设置为AVCaptureSessionPresetHigh。”?提前感谢。这意味着您将检查代表设备前后摄像头的AVCaptureDevice对象支持的包含特定分辨率的最高AVCaptureSessionPreset常量。并将此设置为用于捕获视频的预设,从而确保任何设备拍摄的帧大小相同。换句话说,使用两个设备中最高的一个?我不清楚的是“将预设设置为它,而不是直接设置为AVCaptureSessionPresetHigh”。再次感谢。