Platforms to show: All Mac Windows Linux Cross-Platform

/AVFoundation/Extract video frames


Required plugins for this example: MBS AVFoundation Plugin, MBS MacCG Plugin, MBS MacCF Plugin, MBS Main Plugin, MBS MacBase Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /AVFoundation/Extract video frames

This example is the version from Sat, 3rd May 2019.

Project "Extract video frames.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open() dim av as new MyAVFoundationMBS // load a movie dim f as FolderItem = SpecialFolder.Desktop.Child("test.mov") dim a as AVAssetMBS = AVAssetMBS.assetWithFile(f) // wait for loading? dim e as NSErrorMBS 'dim status as integer = a.statusOfValueForKey("duration", e) 'while status = a.AVKeyValueStatusLoading 'status = a.statusOfValueForKey("duration", e) 'wend // create an asset reader dim ar as new AVAssetReaderMBS(a, e) if e <> nil then MsgBox e.localizedDescription Return end if // find the video track dim VideoTracks() as AVAssetTrackMBS = a.tracksWithMediaType(av.AVMediaTypeVideo) dim VideoTrack as AVAssetTrackMBS = VideoTracks(0) // setup track output dim d as new Dictionary d.Value(CVPixelBufferMBS.kCVPixelBufferPixelFormatTypeKey) = CVPixelBufferMBS.kCVPixelFormatType_32ARGB dim arto as new AVAssetReaderTrackOutputMBS(VideoTrack, d) ar.addOutput arto // start it! ar.startReading dim folder as FolderItem = SpecialFolder.Desktop.Child(f.name+" frames") folder.CreateAsFolder // look over track and get all samples and write them to disk as jpg files dim n as integer = 0 while ar.status = ar.AVAssetReaderStatusReading dim b as CMSampleBufferMBS = arto.NextSampleBuffer if b <> nil then dim buf as CVImageBufferMBS = b.ImageBuffer if buf <> nil then 'dim ci as CIImageMBS = buf.CIImage 'dim nsi as NSImageMBS = buf.NSImage 'dim pic as Picture = nsi.CopyPicture dim jpegData as MemoryBlock = buf.JPEG n = n + 1 if jpegData <> nil then dim name as string = str(n, "00000")+".jpg" dim file as FolderItem = folder.child(name) dim bb as BinaryStream = BinaryStream.Create(file, true) bb.Write jpegData end if end if end if wend End EventHandler
End Class
Class Window1 Inherits Window
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

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


The biggest plugin in space...