首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带AVMutableComposition差分相机的iPad缺失帧记录器

带AVMutableComposition差分相机的iPad缺失帧记录器
EN

Stack Overflow用户
提问于 2015-05-20 19:33:58
回答 1查看 317关注 0票数 0

我使用著名的PBJVision记录视频,然后必须合并在一起。我使用AVMutableComposition使用insertTimeRange(_:ofAsset:atTime:error:)组合视频。如果视频是用同一台相机拍摄的,效果很好。但是,例如,如果一个是用后面的摄像机拍摄的,那么使用前面的摄像机拍摄另一个,后者的视频就丢失了。看来只有音频被添加了。这是我的代码:

代码语言:javascript
复制
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")
        }
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-28 11:23:10

就在我问完这个问题之后,我在附近散步了一夜,我自己找到了答案:)所以不同的相机有不同的最大分辨率,从而产生不同尺寸的帧,混淆构图对象。它使用第一个视频的大小,并忽略不同大小的视频的帧。因此,测试和看看什么是最好的分辨率AVCaptureSessionPreset支持的两个相机在特定的设备上。然后在您的视频捕获代码中使用预置,不要直接跳转到使用AVCaptureSessionPresetHigh。

我希望这对其他人也有帮助:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30358827

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档