我正在使用SCRecorder。在视频上应用滤镜后,它会自动在右侧迅速添加黑屏

时间:2018-09-26 07:44:04

标签: ios swift video filtering

我在使用SCRecorder库的视频过滤器上遇到了一些问题。当我在视频上应用过滤器时,系统会自动裁剪并在屏幕右侧添加一些黑屏。

我的代码在这里:

    DispatchQueue.global(qos: .userInitiated).async {
        let movieURL = VideoAlbumManager.sharedSingleton().returnPathUrl(effcetVideoUrl)
        let aVideoAsset   = AVURLAsset.init(url: effcetVideoUrl)
        let exportSession = SCAssetExportSession(asset: (self.recordSession?.assetRepresentingSegments1(aVideoAsset))!)
        exportSession.videoConfiguration.filter = SCFilter(ciFilterName: modelClass.effectFile)
        exportSession.videoConfiguration.preset = SCPresetHighestQuality
        exportSession.audioConfiguration.preset = SCPresetHighestQuality
        exportSession.videoConfiguration.maxFrameRate = 35
        exportSession.outputUrl = movieURL!
         exportSession.outputFileType = AVFileType.mp4.rawValue
        exportSession.delegate = self
        exportSession.contextType = SCContextType(rawValue: 0)!
        print("exportSession.outputUrl:-\(String(describing: movieURL!))")
        DispatchQueue.main.async {
        let overlay = SCWatermarkOverlayView()
        overlay.date = self.recordSession?.date
        exportSession.videoConfiguration.overlay = overlay
        print("Starting exporting")
        }
        let time: CFTimeInterval = CACurrentMediaTime()
       exportSession.exportAsynchronously(completionHandler: {
            print("Export")
            if !exportSession.cancelled {
                print("Completed compression in \(CACurrentMediaTime() - time)")
            }

            let error: Error? = exportSession.error
            if exportSession.cancelled {
                print("Export was cancelled")
            }
            else if error == nil {
                if isSave == "1" {
                    DispatchQueue.main.async {
                        self.saveToCameraRoll(URL: exportSession.outputUrl as NSURL?)
                    }
                }
                else {
                    DispatchQueue.main.async(execute: {() -> Void in
                        self.playerView.clean()
                        self.playerView .removeFromSuperview()
                        self.stopAnimating()
                        print("dfr==================f\(exportSession.outputUrl!)")
                        self.effectVideoUrl = exportSession.outputUrl! as NSURL
                        self.playerView = GUIPlayerView(frame: CGRect(x: CGFloat(0), y: CGFloat(105), width:UIScreen.main.bounds.size.width, height:UIScreen.main.bounds.size.height/2))//1
                        self.playerView.delegate = self
                        self.view.addSubview(self.playerView)//2
                        self.playerView.videoURL = exportSession.outputUrl!
                        self.playerView.prepareAndPlayAutomatically(false)
                        self.playerView .stop()
                    })
                } 
            }else {
                DispatchQueue.main.async(execute: {() -> Void in
                    self.stopAnimating()
                    print("elseelseelseerrorerrorerror:66666-\(String(describing: error))")
                })
            }

        })
    }

链接说明

https://github.com/rFlex/SCRecorder/issues/425

1 个答案:

答案 0 :(得分:1)

我想我不能用您的库解决您的问题,但是通常,如果您裁剪视频并且该图层没有附加Alpha像素缓冲区,则Alpha像素将为黑色。

如果您使用AVPlayerLayer,则可以用一行代码解决问题。

playerLayer.pixelBufferAttributes = [(kCVPixelBufferPixelFormatTypeKey as String): kCVPixelFormatType_32BGRA]

也许它将帮助您解决问题。