Example: /AVFoundation/Extract video frames

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

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.


💬 Ask a question or report a problem