Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/computer-graphics-tools/core-video-tools
A set of extensions and utilities to work with CoreVideo types.
https://github.com/computer-graphics-tools/core-video-tools
corevideo graphics-programming image-processing swift
Last synced: 3 months ago
JSON representation
A set of extensions and utilities to work with CoreVideo types.
- Host: GitHub
- URL: https://github.com/computer-graphics-tools/core-video-tools
- Owner: computer-graphics-tools
- License: mit
- Created: 2022-04-25T12:13:06.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-03T14:07:32.000Z (6 months ago)
- Last Synced: 2024-10-09T16:30:03.404Z (3 months ago)
- Topics: corevideo, graphics-programming, image-processing, swift
- Language: Swift
- Homepage:
- Size: 430 KB
- Stars: 21
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CoreVideoTools
[![Platform Compatibility](https://img.shields.io/badge/Platforms-iOS%20|%20macOS-brightgreen)](https://swift.org/platforms/)
[![Swift Version](https://img.shields.io/badge/Swift-5.9-orange)](https://swift.org)
## Overview
CoreVideoTools offers a more idiomatic Swift interface to `CoreVideo` functionality, making it easier and safer to work with `CVPixelBuffers`, `IOSurfaces`, and related `CoreVideo` concepts in Swift code.
Please see [the package's documentation](https://swiftpackageindex.com/computer-graphics-tools/core-video-tools/documentation/corevideotools)
for more detailed usage instructions.## CVPixelBuffer
There are a lot Swift wrappers over vanilla CVPixelBuffer C-style API:
**Swifty API:**
```swift
let width = pixelBuffer.width
let height = pixelBuffer.height
let format = pixelBuffer.cvPixelFormat
let bytesPerRow = pixelBuffer.bytesPerRow
```**Convenience Init:**
```swift
let pixelBuffer = try CVPixelBuffer.create(
width: 1920,
height: 1080,
cvPixelFormat: .type_32BGRA
)
```Check out more examples in the [Working With CVPixelBuffer](Sources/CoreVideoTools/CoreVideoTools.docc/WorkingWithCVPixelBuffer.md).
## IOSurface
**Convenience Init:**
```swift
let surface = try IOSurface.create(
width: 1920,
height: 1080,
cvPixelFormat: .type_32BGRA,
bytesPerElement: 4,
bytesPerRow: 1920 * 4
)
```For more detail, please checkout [Working With IOSurface](Sources/CoreVideoTools/CoreVideoTools.docc/WorkingWithIOSurface.md).
## CVPixelFormat
While debuging `Core Video` objects, you need to understand what pixel format is used in them.
To do this using vanilla API you are forced to find a matching `OSType` value, because `OSType` if basically a number.
This project uses [`CVPixelFormat`](Sources/CoreVideoTools/CVPixelFormat.swift) enum istead of vanilla `OSType` public vars which is much more handy, and you can easily get a `description` of a current pixel format.```swift
let cvPixelFormat: CVPixelFormat = cvPixelBuffer.cvPixelFormat
let description = cvPixelFormat.description
```## CVReturn Result & CVError
There are some functions in Core Video that return a code which helps if the operation succeeded.
This project aims to simplify this error checking. `CVReturn` [`Result`](Sources/CoreVideoTools/Extensions/CoreVideo/CVReturn/CVReturn+Result.swift) and [`CVError`](Sources/CoreVideoTools/CVError.swift) types are used to wrap vanilla API with thowable functions.**Vanilla API:**
```swift
let returnCode = CVPixelBufferLockBaseAddress(cvPixelBuffer, lockFlags)
guard returnCode == kCVReturnSuccess else { /* handle the error ... */ }
```**Swifty API:**
```swift
try cvPixelBuffer.lockBaseAddress(lockFlags: lockFlags)
```## License
MetalTools is licensed under [MIT license](LICENSE).