Skip to content

🎥 Simple movie writing library for Swift

License

Notifications You must be signed in to change notification settings

p-x9/MovieWriter

Repository files navigation

MovieWriter

Simple movie writing library for Swift

Github issues Github forks Github stars Github top language

Document

Import and create instance of MovieWriter

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 use Audio or Microphone

If you want to write audio or microphone audio, you need to configure the following settings.

movieWriter.isAudioEnabled = true
movieWriter.isMicrophoneEnabled = true

Start Writing

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)

Write Buffer

Video

try movieWriter.writeFrame(buffer) // write with `CMSampleBuffer`
/* or */
try movieWriter.writeFrame(buffer, at: time) // write with `CVSampleBuffer`

Audio and Microphone

try movieWriter.writeAudio(buffer) // Audio
try movieWriter.writeMicrophone(buffer) // Audio

End Writing

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)

Access to AVKit-related properties

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?

License

MovieWriter is released under the MIT License. See LICENSE