Simple movie writing library for Swift
let movieWriter = MovieWriter(
outputUrl: outputURL, // Movie outpur URL
size: UIScreen.main.bounds.size, // frame size
codec: .h264, // video codec
audioFormatId: kAudioFormatMPEG4AAC, // audio format
audioSampleRate: 44100.0, // sample rate of audio
audioNumberOfChannel: 2, // number of channel
fileType: .mp4 // file type
)
If you want to write audio or microphone audio, you need to configure the following settings.
movieWriter.isAudioEnabled = true
movieWriter.isMicrophoneEnabled = true
If waitFirstWriting
is true, align the first write with the start time of the video.
Otherwise, the time when this method is called is the start time of the video, and the video will be blank until the time of the writing.
try movieWriter.start(waitFirstWriting: true)
try movieWriter.writeFrame(buffer) // write with `CMSampleBuffer`
/* or */
try movieWriter.writeFrame(buffer, at: time) // write with `CVSampleBuffer`
try movieWriter.writeAudio(buffer) // Audio
try movieWriter.writeMicrophone(buffer) // Audio
Specify an end time to finish writing.
If waitUntilFinish
is true, it will not return until the end process is completely finished
try movieWriter.end(at: time, waitUntilFinish: true)
The following import allows access to internal properties related to AVKit.
@_spi(AVKit) import MovieWriter
You will have access to the following properties
- assetWriter: AVAssetWriter?
- writerInput: AVAssetWriterInput?
- adaptor: AVAssetWriterInputPixelBufferAdaptor?
- audioWriterInput: AVAssetWriterInput?
- micWriterInput: AVAssetWriterInput?
MovieWriter is released under the MIT License. See LICENSE