Platforms to show: All Mac Windows Linux Cross-Platform

Back to AVAssetExportSessionMBS class.

AVAssetExportSessionMBS.cancelExport

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 13.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Cancels the execution of an export session.

AVAssetExportSessionMBS.Constructor(asset as AVAssetMBS, presetName as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 13.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Initializes an asset export session with a specified asset and preset.

asset: The asset you want to export.
presetName: A string constant specifying the name of the preset template for the export.

AVAssetExportSessionMBS.determineCompatibleFileTypes(tag as Variant = nil)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 14.0 ✅ Yes ❌ No ❌ No ✅ Yes All
Reports the compatible file types for the current export session to the event.

calls later AVFoundationMBS.determineCompatibleFileTypesCompleted event.

This method operates on the asset object and preset information that was used to initialize the export session. It uses this information to determine the file types that the export session can write.

This method performs its checks asynchronously on a secondary thread and returns immediately. The results are similarly reported to the specified block on a secondary thread. Because this method actually inspects the asset's tracks, the tracks are loaded if they have not been already.
Available in OS X v10.9 and later.

With tag you can pass any value you like to the event later. This can be for example an object reference or a number in an array. Be aware that the reference to this tag value is kept until the event is called and can cause memory reference cycles.

AVAssetExportSessionMBS.exportAsynchronously(tag as Variant = nil)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 13.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Starts the asynchronous execution of an export session.
Example
dim f as FolderItem = SpecialFolder.Desktop.Child("test.m4v")
dim a as AVAssetMBS = AVAssetMBS.assetWithFile(f)
dim p as string = AVAssetExportSessionMBS.AVAssetExportPresetAppleM4VCellular
dim e as new AVAssetExportSessionMBS(a, p)

dim FileTypes() as string = e.supportedFileTypes
e.outputFileType = FileTypes(0)
e.OutputFile = SpecialFolder.Desktop.Child("small.m4v")
e.exportAsynchronously

// instead of waiting for event, we simply wait for it to finish
do
app.YieldToNextThread
loop until e.status <> e.AVAssetExportSessionStatusExporting

This method starts an asynchronous export operation and returns immediately. status signals the terminal state of the export session, and if a failure occurs, error describes the problem.

This method calls AVFoundationMBS.exportAsynchronouslyCompleted event later. Tag is passed so you can pass information needed to finish work.

If internal preparation for export fails, event is invoked synchronously. The event may also be called asynchronously, after the method returns, in the following cases:

  • If a failure occurs during the export, including failures of loading, re-encoding, or writing media data to the output.
  • If cancelExport is invoked.
  • After the export session succeeds, having completely written its output to the outputURL.

With tag you can pass any value you like to the event later. This can be for example an object reference or a number in an array. Be aware that the reference to this tag value is kept until the event is called and can cause memory reference cycles.

AVAssetExportSessionMBS.exportMT

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 18.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Starts the synchronous execution of an export session.

Same as exportAsynchronously, but run synchronous, so the plugin waits.

The work is performed on a preemptive thread, so this function does not block the application and can yield time to other Xojo threads. Must be called in a Xojo thread to enjoy benefits. If called in main thread will block, but keep other background threads running.

AVAssetExportSessionMBS.metadata as AVMetadataItemMBS()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 13.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Returns the metadata to be written to the output file by the export session.

AVAssetExportSessionMBS.outputFileExtension as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 13.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Convenience method to query the preferred file extension for current output file type.
Example
dim f as FolderItem = SpecialFolder.Desktop.Child("test.m4v")
dim a as AVAssetMBS = AVAssetMBS.assetWithFile(f)
dim p as string = AVAssetExportSessionMBS.AVAssetExportPresetAppleM4VCellular
dim e as new AVAssetExportSessionMBS(a, p)
dim filetypes() as string = e.supportedFileTypes
e.outputFileType = FileTypes(0)

// shows the output file extension
MsgBox "outputFileExtension: "+e.outputFileExtension

Some examples using this method:

AVAssetExportSessionMBS.setMetadata(items() as AVMetadataItemMBS)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 13.2 ✅ Yes ❌ No ❌ No ✅ Yes All
Sets the metadata to be written to the output file by the export session.
Example
dim e as AVAssetExportSessionMBS // your export session
dim asset as AVAssetMBS // your asset

// query metadata
dim a() as AVMetadataItemMBS = asset.metadata

// make new
dim m as new AVMutableMetadataItemMBS

// add common key with author
m.keySpace = AVFoundationMBS.AVMetadataKeySpaceCommon
m.key = AVFoundationMBS.AVMetadataCommonKeyAuthor
m.Value = "Hello World"

// append to array and use as metadata:
a.Append m
e.setMetadata a

If the array is empty, any existing metadata in the exported asset will be translated as accurately as possible into the appropriate metadata key space for the output file and written to the output.

AVAssetExportSessionMBS.supportedFileTypes as string()

Type Topic Plugin Version macOS Windows Linux iOS Targets
method AVFoundation MBS AVFoundation Plugin 13.2 ✅ Yes ❌ No ❌ No ✅ Yes All
The types of files the session can write. (read-only)
Example
dim f as FolderItem = SpecialFolder.Desktop.Child("test.m4v")
dim a as AVAssetMBS = AVAssetMBS.assetWithFile(f)
dim p as string = AVAssetExportSessionMBS.AVAssetExportPresetAppleM4VCellular
dim e as new AVAssetExportSessionMBS(a, p)
// shows supported file types
MsgBox join(e.supportedFileTypes, EndOfLine)

The types of files the session can write are determined by the asset and and export preset with which the session was initialized. If you need to determine the compatible file formats before initiating the export operation, use the determineCompatibleFileTypesWithCompletionHandler: method.

Some examples using this method:

AVAssetExportSessionMBS.timeRange as CMTimeRangeMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
property AVFoundation MBS AVFoundation Plugin 13.2 ✅ Yes ❌ No ❌ No ✅ Yes All
The time range to be exported from the source.
Example
dim a as AVAssetMBS // your asset to export
dim preset as string = AVAssetExportSessionMBS.AVAssetExportPresetPassthrough // your settings
dim e as new AVAssetExportSessionMBS(a, preset)

dim t as CMTimeMBS = CMTimeMBS.MakeWithSeconds(5) // start at 5
dim d as CMTimeMBS = CMTimeMBS.MakeWithSeconds(10) // duration 10
dim r as CMTimeRangeMBS = CMTimeRangeMBS.Make(t,d)

e.timeRange = r // or your time range!
e.shouldOptimizeForNetworkUse = true

dim filetypes() as string = e.supportedFileTypes
e.outputFileType = FileTypes(0)
e.OutputFile = SpecialFolder.Desktop.Child("test."+e.outputFileExtension)

e.exportAsynchronously(nil)

// keep e and check for events

// or instead of waiting for event, we simply wait for it to finish
do
app.YieldToNextThread
loop until e.status <> e.AVAssetExportSessionStatusExporting

The default time range of an export session is kCMTimeZero to kCMTimePositiveInfinity, meaning that (modulo a possible limit on file length) the full duration of the asset will be exported.
(Read and Write computed property)

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


The biggest plugin in space...