Library to make pixel buffer for video frame formatted 420YpCbCr8BiPlanarFullRange from UIKit/SwiftUI view or UIImage.
This library dose NOT written for real-time application.
- Swift Package Manager
Canvas
is a class to manage pixel buffer as a source of video frame.
let canvasFactory = FrameMint.CanvasFactory()
let canvas = try canvasFactory.makeCanvas(width: width, height: height, extent: extent)
Example to add and draw SwiftUI contents on canvas.
// Add SwiftUI contents on canvas.
canvas.addSwiftUIContents {
ZStack(alignment: .center) {
Color.white
Text("Hello, world!")
.font(.system(size: 40, weight: .medium))
}
}
// Draw current canvas contents on pixel buffer managed by canvas.
canvas.drawContents()
Example to add and draw UIKit contents on canvas.
// Create drawn view (Here is a simple UILabel).
let label = UILabel(frame: canvas.content.bounds)
label.backgroundColor = .white
label.text = "Hello, world!"
label.font = .systemFont(ofSize: 40, weight: .medium)
label.textAlignment = .center
// Add drawn view on content view managed by canvas.
canvas.content.addSubview(label)
// Draw current canvas contents on pixel buffer managed by canvas.
canvas.drawContents()
Example to draw UIImage resource on canvas.
// Prepare image to draw.
let image: UIImage = ...
// Draw image on pixel buffer managed by canvas in same rect of pixel buffer.
canvas.drawImage(image)
Example to make 420YpCbCr8BiPlanarFullRange format pixel buffer from canvas.
let pixelBuffer: CVPixelBuffer = canvas.make420YpCbCr8BiPlanarFullRangePixelBuffer()
Example to make 420YpCbCr8BiPlanarFullRange format sample buffer from canvas.
// `orientation` is a value about frame orientation related with RPVideoSampleOrientationKey
let sampleBuffer: CMSampleBuffer = canvas.make420YpCbCr8BiPlanarFullRangeSampleBuffer(orientation: orientation)
Remove all SWiftUI/UIKit contents on canvas.
canvas.clearContents()
Sample application framemint_app
to check detail of usage of this library contained in ./App Directory.
Home | An example of preview for video frame |
---|---|