This repository contains code for an iOS app that utilizes FFmpegKit to perform audio and video conversion operations. The app includes a ConverterViewModel
class responsible for handling the conversion logic and a ViewController
class to demonstrate the functionality.
The ConverterViewModel
class manages the conversion process using FFmpegKit. It includes methods for converting audio from an input URL and adding a watermark to a video. The progress, percentage, and completion URL are published properties, allowing the UI to react to changes during the conversion process.
The bitrate
enumeration defines different bitrates for audio conversion.
completedAtUrl
: Published property for the completion URL.progressTime
: Published property for the progress time.percentage
: Published property for the conversion percentage.progress
: Published property for the overall progress.cancellables
: Set of Combine cancellables.
convertAudioFrom(url:quality:)
: Converts audio from the input URL with the specified bitrate.addWatermarkToVideo(video:watermark:)
: Adds a watermark to the video from the input URLs.cancelConvertProgress()
: Cancels the ongoing conversion process.
createAudioOutputPath(from:)
: Creates an output path for converted audio.createVideoOutputPath(from:)
: Creates an output path for converted video.checkFileExistance(in:)
: Checks and removes existing files.calculateTotalTime(url:)
: Calculates the total duration of the input audio file.calculateProgress(currentTime:)
: Calculates the conversion progress based on the current time.
The ViewController
class serves as the main view controller for the app. It includes UI elements such as a progress view and a label to display the conversion percentage. The class initializes a ConverterViewModel
instance, triggers a conversion from a local file on viewDidLoad
, and binds UI elements to the conversion progress.
progressView
: UIProgressView to visualize the conversion progress.progressPercentageLabel
: UILabel to display the conversion percentage.
convertViewModel
: Instance ofConverterViewModel
for handling conversion logic.
ConvertLocalFile()
: Initiates the conversion of a local video file with a watermark.bindProgress()
: Binds the UI progress view to the conversion progress.bindPercentage()
: Binds the UI label to the conversion percentage.bindCompletedProgress()
: Binds the UI to display the completed video.
To use this code, follow these steps:
- Integrate the code into your iOS project.
- Ensure FFmpegKit is included in your project.
- Initialize a
ConverterViewModel
instance. - Trigger audio or video conversion using the appropriate methods.
- Bind UI elements to the published properties for real-time updates.
Feel free to customize the code based on your specific requirements.
- FFmpegKit: FFmpeg library for iOS.
This code is licensed under the MIT License.