Skip to content

Instantly share code, notes, and snippets.

func savePNG(_ frame: AVFrame, to url: String) throws {
let fmtCtx = try AVFormatContext(format: nil, filename: url)
guard let codec = AVCodec.findEncoderById(.PNG) else {
fatalError("png codec doesn't exist")
}
guard let codecCtx = AVCodecContext(codec: codec) else {
fatalError("Could not allocate video codec context")
}
codecCtx.width = frame.width