https://github.com/p-x9/moviewriter
🎥 Simple movie writing library for Swift
https://github.com/p-x9/moviewriter
coremedia movie swiftpackage swiftpackagemanager video
Last synced: 8 months ago
JSON representation
🎥 Simple movie writing library for Swift
- Host: GitHub
- URL: https://github.com/p-x9/moviewriter
- Owner: p-x9
- License: mit
- Created: 2023-06-02T04:44:25.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-14T23:08:19.000Z (almost 3 years ago)
- Last Synced: 2025-02-17T03:44:36.504Z (over 1 year ago)
- Topics: coremedia, movie, swiftpackage, swiftpackagemanager, video
- Language: Swift
- Homepage:
- Size: 11.7 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MovieWriter
Simple movie writing library for Swift
[](https://github.com/p-x9/MovieWriter/issues)
[](https://github.com/p-x9/MovieWriter/network/members)
[](https://github.com/p-x9/MovieWriter/stargazers)
[](https://github.com/p-x9/MovieWriter/)
## Document
### Import and create instance of `MovieWriter`
```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 use Audio or Microphone
If you want to write audio or microphone audio, you need to configure the following settings.
```swift
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.
```swift
try movieWriter.start(waitFirstWriting: true)
```
### Write Buffer
#### Video
```swift
try movieWriter.writeFrame(buffer) // write with `CMSampleBuffer`
/* or */
try movieWriter.writeFrame(buffer, at: time) // write with `CVSampleBuffer`
```
#### Audio and Microphone
```swift
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
```swift
try movieWriter.end(at: time, waitUntilFinish: true)
```
### Access to AVKit-related properties
The following import allows access to internal properties related to AVKit.
```swift
@_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](./LICENSE)