Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

/AVFoundation/Make Video From Images
Function:
Required plugins for this example: MBS AVFoundation Plugin, MBS MacBase Plugin, MBS MacCG Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /AVFoundation/Make Video From Images
This example is the version from Fri, 23th May 2013.
Project "Make Video From Images.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open() if AVAssetExportSessionMBS.available = false then MsgBox "Please run on Mac OS X 10.7 or newer." quit end if End EventHandler
End Class
Class Window1 Inherits Window
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() if adaptor.assetWriterInput.isReadyForMoreMediaData = false then Return dim g as Graphics = pic.Graphics dim c as integer = counter*255/pic.height g.ForeColor = rgb(c, 0, 0) g.Drawline 0, counter, g.Width, counter buffer.Flush dim t as CMTimeMBS = CMTimeMBS.Make(600/30*counter, 600) // 30fps in 600 time units per second0 call adaptor.appendPixelBuffer(buffer, t) 'call adaptor.appendPicture(pic, t) counter = counter + 1 if counter = g.Height then // finish me.mode = 0 videoWriterInput.markAsFinished dim endtime as CMTimeMBS = CMTimeMBS.Make(600/30*counter, 600) // 30fps in 600 time units per second0 videoWriter.endSessionAtSourceTime endtime if not videoWriter.finishWriting then MsgBox "Failed to finish writing file." 'break return end if adaptor = nil videoWriterInput = nil videoWriter = nil // done beep file.Launch end if Backdrop = pic End EventHandler
End Control
EventHandler Sub Open() AVFoundation = new MyAVFoundationMBS pic = new Picture(Width, Height, 32) buffer = new CVPixelBufferMBS(pic) file = SpecialFolder.Desktop.Child("test.m4v") if file.Exists then file.Delete dim error as NSErrorMBS videoWriter = New AVAssetWriterMBS(file, AVFoundation.AVFileTypeMPEG4, error) if videoWriter = nil then MsgBox "Failed to create video writer!" break Return end if dim videoSettings as new Dictionary videoSettings.Value(AVFoundation.AVVideoCodecKey) = AVFoundation.AVVideoCodecH264 videoSettings.Value(AVFoundation.AVVideoWidthKey) = Width videoSettings.Value(AVFoundation.AVVideoHeightKey) = height videoWriterInput = AVAssetWriterInputMBS.assetWriterInputWithMediaType(AVFoundation.AVMediaTypeVideo, videoSettings) if videoWriterInput = nil then MsgBox "Failed to create video writer input!" break Return end if dim options as new Dictionary options.Value(CVPixelBufferMBS.kCVPixelBufferWidthKey) = buffer.Width options.Value(CVPixelBufferMBS.kCVPixelBufferHeightKey) = buffer.Height options.Value(CVPixelBufferMBS.kCVPixelBufferPixelFormatTypeKey) = buffer.kCVPixelFormatType_32ARGB adaptor = AVAssetWriterInputPixelBufferAdaptorMBS.assetWriterInputPixelBufferAdaptorWithAssetWriterInput(videoWriterInput, options) if adaptor = nil then MsgBox "Failed to create adaptor!" break Return end if if not videoWriter.canAddInput(videoWriterInput) then break end if // allows to go faster than real time... videoWriterInput.expectsMediaDataInRealTime = true videoWriter.addInput videoWriterInput //Start a session: if not videoWriter.startWriting then MsgBox "Failed to start writing." break Return end if videoWriter.startSessionAtSourceTime CMTimeMBS.kCMTimeZero if buffer.Handle = 0 then MsgBox "Failed to create CVPixelBufferMBS." break Return end if timer1.mode = 2 End EventHandler
Property AVFoundation As MyAVFoundationMBS
Property adaptor As AVAssetWriterInputPixelBufferAdaptorMBS
Property buffer As CVPixelBufferMBS
Property counter As Integer
Property file As FolderItem
Property pic As Picture
Property videoWriter As AVAssetWriterMBS
Property videoWriterInput As AVAssetWriterInputMBS
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class MyAVFoundationMBS Inherits AVFoundationMBS
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS AVFoundation Plugin.




Links
MBS FileMaker Plugins