|
@@ -63,7 +63,9 @@ public class MovieOutput: ImageConsumer, AudioEncodingTarget {
|
|
|
imageProcessingShareGroup = sharedImageProcessingContext.context.sharegroup
|
|
|
let movieProcessingContext = OpenGLContext()
|
|
|
|
|
|
- self.size = size
|
|
|
+
|
|
|
+ self.size = Size(width: size.width == 0 ? 1080 : size.width,
|
|
|
+ height: size.height == 0 ? 1080 : size.height)
|
|
|
|
|
|
assetWriter = try AVAssetWriter(url: URL, fileType: fileType)
|
|
|
|
|
@@ -288,8 +290,13 @@ public class MovieOutput: ImageConsumer, AudioEncodingTarget {
|
|
|
let bufferSize = GLSize(size)
|
|
|
var cachedTextureRef: CVOpenGLESTexture?
|
|
|
_ = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, movieProcessingContext.coreVideoTextureCache, pixelBuffer, nil, GLenum(GL_TEXTURE_2D), GL_RGBA, bufferSize.width, bufferSize.height, GLenum(GL_BGRA), GLenum(GL_UNSIGNED_BYTE), 0, &cachedTextureRef)
|
|
|
- let cachedTexture = CVOpenGLESTextureGetName(cachedTextureRef!)
|
|
|
+
|
|
|
+ //cachedTextureRef可能为空,导致使用 cachedTextureRef! 语法崩溃
|
|
|
+ guard let newCachedTextureRef = cachedTextureRef else {
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
+ let cachedTexture = CVOpenGLESTextureGetName(newCachedTextureRef)
|
|
|
renderFramebuffer = try Framebuffer(context: movieProcessingContext, orientation: .portrait, size: bufferSize, textureOnly: false, overriddenTexture: cachedTexture)
|
|
|
|
|
|
renderFramebuffer.activateFramebufferForRendering()
|