Platforms to show: All Mac Windows Linux Cross-Platform
/AVFoundation/SDAVAssetExportSessionMBS test
Required plugins for this example: MBS AVFoundation Plugin, MBS MacCF Plugin, MBS MacCG Plugin, MBS Main Plugin, MBS MacBase Plugin, MBS Util Plugin
Last modified Sun, 18th Jul 2020.
You find this example project in your MBS Xojo Plugin download as a Xojo project file within the examples folder: /AVFoundation/SDAVAssetExportSessionMBS test
Download this example: SDAVAssetExportSessionMBS test.zip
Project "SDAVAssetExportSessionMBS test.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control bar Inherits ProgressBar
ControlInstance bar Inherits ProgressBar
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action()
bar.Value = 1000 * encoder.progress
End EventHandler
End Control
EventHandler Sub Open()
Dim file As FolderItem = SpecialFolder.Desktop.Child("video.mov")
Dim asset As AVAssetMBS = AVAssetMBS.assetWithFile(file)
encoder = New MySDAVAssetExportSessionMBS(asset)
encoder.outputFileType = AVFoundationMBS.AVFileTypeMPEG4
encoder.outputFile = SpecialFolder.Desktop.Child("output.mp4")
Dim CompressionProperties As New Dictionary
CompressionProperties.Value(AVFoundationMBS.AVVideoAverageBitRateKey) = 6000000
CompressionProperties.Value(AVFoundationMBS.AVVideoProfileLevelKey) = AVFoundationMBS.AVVideoProfileLevelH264High40
Dim videoSettings As New Dictionary
videoSettings.Value(AVFoundationMBS.AVVideoCodecKey) = AVFoundationMBS.AVVideoCodecH264
videoSettings.Value(AVFoundationMBS.AVVideoWidthKey) = 1920
videoSettings.Value(AVFoundationMBS.AVVideoHeightKey) = 1080
videoSettings.Value(AVFoundationMBS.AVVideoCompressionPropertiesKey) = CompressionProperties
encoder.videoSettings = videoSettings
Dim audioSettings As New Dictionary
audioSettings.Value(AVFoundationMBS.AVFormatIDKey) = OSTypeFromStringMBS(AVFoundationMBS.kAudioFormatMPEG4AAC)
audioSettings.Value(AVFoundationMBS.AVNumberOfChannelsKey) = 2
audioSettings.Value(AVFoundationMBS.AVSampleRateKey) = 44100
audioSettings.Value(AVFoundationMBS.AVEncoderBitRateKey) = 128000
encoder.audioSettings = audioSettings
encoder.exportAsynchronously
End EventHandler
Property encoder As MySDAVAssetExportSessionMBS
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class MySDAVAssetExportSessionMBS Inherits SDAVAssetExportSessionMBS
EventHandler Sub exportAsynchronouslyCompleted()
If (Me.status = StatusCompleted) Then
MsgBox "Video export succeeded"
Elseif (Me.status = StatusCancelled) then
MsgBox "Video export cancelled"
Else
MsgBox "Video export failed with error: " + me.error.localizedDescription
end if
End EventHandler
End Class
End Project
Download this example: SDAVAssetExportSessionMBS test.zip
The items on this page are in the following plugins: MBS AVFoundation Plugin.