This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - Functions | |
/// Until the spm proposal to import things in swift scripts we have to copy this | |
/// [SwiftPM support for Swift scripts - Evolution / Pitches - Swift Forums](https://forums.swift.org/t/swiftpm-support-for-swift-scripts/33126) | |
extension Process { | |
func runAsync() async throws { | |
let command = "\(executableURL?.lastPathComponent ?? "") \(arguments?.joined(separator: " ") ?? "")" | |
print(command) | |
try run() | |
try await Task { | |
waitUntilExit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// DictionaryBuilder.swift | |
// | |
// From blog of alejandrom: https://alejandromp.com/blog/better-dictionary-literals-with-swift-result-builders/ | |
// | |
import Foundation | |
/// Based on https://alejandromp.com/blog/better-dictionary-literals-with-swift-result-builders/ | |
/// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func createEmptyVideo() -> CMSampleBuffer { | |
var pixelBuffer : CVPixelBuffer? = nil | |
CVPixelBufferCreate(kCFAllocatorDefault, 100, 100, kCVPixelFormatType_444YpCbCr10BiPlanarVideoRange, nil, &pixelBuffer) | |
var info = CMSampleTimingInfo() | |
info.presentationTimeStamp = .zero | |
info.duration = .invalid | |
info.decodeTimeStamp = .invalid | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AVFoundation | |
func createSilentAudio(startFrm: Int64, nFrames: Int, sampleRate: Float64, numChannels: UInt32) -> CMSampleBuffer { | |
let bytesPerFrame = UInt32(2 * numChannels) | |
let blockSize = nFrames*Int(bytesPerFrame) | |
var block: CMBlockBuffer? | |
var status = CMBlockBufferCreateWithMemoryBlock( | |
allocator: kCFAllocatorDefault, | |
memoryBlock: nil, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Array { | |
func indexes<T>(xs: [T], check: T -> Bool) -> [Int] { | |
var result = [Int]() | |
var i = 0 | |
for x in xs { | |
if check(x) { | |
result.append(i) | |
} | |
i++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Layout.swift | |
// | |
// Created by Stijn Willems on 10/06/15. | |
// Copyright (c) 2015 dooZ. All rights reserved. | |
// | |
import Foundation | |