|
@@ -24,6 +24,8 @@ class OJADecoder: NSObject {
|
|
|
//可以是OJAAlphaMovieFrameInput 或者OJAMovieFrameInput
|
|
|
fileprivate var timeMovieInput: OJAFrameInput
|
|
|
|
|
|
+ fileprivate var fgMovieInput: OJAFrameInput? // 实现 “时空穿越 ” 需要用到新的 fg、fgm 参数实现
|
|
|
+
|
|
|
fileprivate var allInputArray = [OJAFrameInput]()
|
|
|
|
|
|
fileprivate var lastInputArray = [OJAFrameInput]()
|
|
@@ -64,6 +66,11 @@ class OJADecoder: NSObject {
|
|
|
self.backgroundColor = OJSColor(hexRGBValue: compositionInput.templateModel.bgColor)
|
|
|
super.init()
|
|
|
|
|
|
+ if let fgItemModel = compositionInput.templateModel.fg,
|
|
|
+ let fgMaskItemModel = compositionInput.templateModel.fgm {
|
|
|
+ self.fgMovieInput = OJAAlphaMovieFrameInput(backgroundItem: fgItemModel, maskItem: fgMaskItemModel, bottomItem: nil)
|
|
|
+ }
|
|
|
+
|
|
|
//初始化的时候要设置一次filter链,因为可能最开始currentInputArray和lastInputArray都是0
|
|
|
self.lastInputArray = self.currentInputArray()
|
|
|
self.buildChain()
|
|
@@ -127,6 +134,12 @@ private extension OJADecoder {
|
|
|
self.backgroundColor.getRed(&cr, green: &cg, blue: &cb, alpha: &ca)
|
|
|
blendFilter.setBackgroundColorRed(GLfloat(cr), green: GLfloat(cg), blue: GLfloat(cb), alpha: GLfloat(ca))
|
|
|
var tempArray = lastInputArray
|
|
|
+
|
|
|
+ /// 如果有前景添加前景素材
|
|
|
+ if let fgInput = fgMovieInput {
|
|
|
+ tempArray.append(fgInput)
|
|
|
+ }
|
|
|
+
|
|
|
if self.templateDataModel.blend == 1 {
|
|
|
tempArray = tempArray.sorted(by: { (input1, input2) -> Bool in
|
|
|
return input1.zIndex < input2.zIndex
|
|
@@ -233,6 +246,14 @@ extension OJADecoder {
|
|
|
input.processFrame(atSampleTime: sampleBufferTime)
|
|
|
}
|
|
|
|
|
|
+ /// 读取 fg 和 fgMask 素材,并且上传纹理
|
|
|
+ if let fgMovieInput = self.fgMovieInput as? OJAAlphaMovieFrameInput{
|
|
|
+ if let fgBufferTemp = fgMovieInput.readCoverFrameBuffer(),
|
|
|
+ let fgMaskBufferTemp = fgMovieInput.readMaskFrameBuffer() {
|
|
|
+ fgMovieInput.processFrame(atSampleTime: sampleBufferTime, coverBuffer: fgBufferTemp, maskBuffer: fgMaskBufferTemp)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
alphaMovieInput.processFrame(atSampleTime: sampleBufferTime, coverBuffer: coverBuffer, maskBuffer: maskBuffer, bottomBuffer: bottomBufferTemp)
|
|
|
print(self.currentFrame)
|
|
|
self.currentFrame += 1
|