-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Timer Label Overlay #43
Comments
Can you be more specific? Are you asking how to add UI to the recorder view or how to record some UI elements to the video? |
Yes, add an overlay view (UI element) to the recorder view and get at the end video-recording from the camera and overlay elements on top |
If the UI / Video clock sync is not your concern, you can use this utility to snapshot your view's content into a You can then use this /// Snapshot a view using a CGContext that is backed by a CVPixelBuffer from a CVPixelBufferPool.
class ViewSnapshoter {
private var pixelBufferPool: MTICVPixelBufferPool?
enum Error: String, LocalizedError {
case cannotCreateCGContext
}
func snapshot(_ view: UIView, afterScreenUpdates: Bool, renderScale: CGFloat = 2) throws -> CVPixelBuffer {
let renderWidth = Int(view.frame.width * renderScale)
let renderHeight = Int(view.frame.height * renderScale)
let pool: MTICVPixelBufferPool
if let pixelBufferPool = pixelBufferPool {
if pixelBufferPool.pixelBufferWidth == renderWidth && pixelBufferPool.pixelBufferHeight == renderHeight {
pool = pixelBufferPool
} else {
pool = try MTICVPixelBufferPool(pixelBufferWidth: renderWidth, pixelBufferHeight: renderHeight, pixelFormatType: kCVPixelFormatType_32BGRA, minimumBufferCount: 16)
self.pixelBufferPool = pool
}
} else {
pool = try MTICVPixelBufferPool(pixelBufferWidth: renderWidth, pixelBufferHeight: renderHeight, pixelFormatType: kCVPixelFormatType_32BGRA, minimumBufferCount: 16)
self.pixelBufferPool = pool
}
let pixelBuffer = try pool.makePixelBuffer(allocationThreshold: 16)
CVPixelBufferLockBaseAddress(pixelBuffer, [])
defer {
CVPixelBufferUnlockBaseAddress(pixelBuffer, [])
}
guard let cgContext = CGContext(data: CVPixelBufferGetBaseAddress(pixelBuffer), width: renderWidth, height: renderHeight, bitsPerComponent: 8, bytesPerRow: CVPixelBufferGetBytesPerRow(pixelBuffer), space: CGColorSpaceCreateDeviceRGB(), bitmapInfo: CGBitmapInfo.byteOrder32Little.rawValue | CGImageAlphaInfo.premultipliedFirst.rawValue /* 32-bit BGRA */) else {
throw Error.cannotCreateCGContext
}
// Apply transform for UIKit coordinate system.
cgContext.concatenate(CGAffineTransform(translationX: 0, y: CGFloat(renderHeight)))
cgContext.concatenate(CGAffineTransform(scaleX: renderScale, y: -renderScale))
UIGraphicsPushContext(cgContext)
view.drawHierarchy(in: view.bounds, afterScreenUpdates: afterScreenUpdates)
UIGraphicsPopContext()
return pixelBuffer
}
} |
thanks for the answer! I will try your method
|
I can't see you append any video buffer to the recorder. The internal writer cannot start without receiving video buffers so "Unexpected status". Also I don't think you want to use the Overlay blend mode. |
Yeah, you’re right, I missed adding a buffer to the recorder, my bad.
|
You need to use a filter to compose the two image together, you can use a MultilayerCompositingFilter or a normal blend filter. Make sure you read the "CameraFilterView" example. |
@MelnykovDenys are you able to share how you got it to work? |
unfortunately not, because it doesn’t work |
Hi!
Thanks for the awesome Utilities!
Could you clarify me please how I can add a timer-label (for ex.: UILabel with a special color and font) on top of the camera , update the text (for ex., every second), add UIImage and eventually record a video?
The text was updated successfully, but these errors were encountered: