Skip to main content
VESDK/Android/Concepts

Background Export

A quick guide on how to enable the background export feature in VideoEditor SDK for Android.

VideoEditor SDK allows headless rendering or exporting in background using WorkManager and a SettingsList object that contains information about all the edits made to the video.

Include module#

To start using headless rendering or background export, include the backend:headless module in your project's imglyConfig modules block -

imglyConfig {
...
modules {
...
include 'backend:headless'
}
}

Enabling Background Export#

When creating the VideoEditorSettingsList as mentioned in the Configuration section, configure the VideoEditorSaveSettings to export only the SettingsList:

VideoEditorSettingsList(true)
.configure<VideoEditorSaveSettings> {
it.outputMode = OutputMode.EXPORT_ONLY_SETTINGS_LIST
}

This indicates to the Editor to only export the SettingsList object immediately (instead of the full video) which can be used to start a background export at any point in the future. The SettingsList object can be obtained in your Activity's onActivityResult() and then passed to the DocumentRenderWorker to start the background export.

override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
super.onActivityResult(requestCode, resultCode, intent)
intent ?: return
val result = EditorSDKResult(intent)
when (result.resultStatus) {
EditorSDKResult.Status.DONE_WITHOUT_EXPORT -> {
result.settingsList.use { document ->
if (document[SaveSettings::class.java].outputMode == OutputMode.EXPORT_ONLY_SETTINGS_LIST) {
WorkManager.getInstance(this).enqueue(DocumentRenderWorker.createWorker(document))
}
}
}
else -> {
}
}
}

DocumentRenderWorker.createWorker() creates a WorkRequest that handles the background export.

Observing Progress#

You can observe progress information for your scheduled background exports by using one of the getWorkInfosByTag() or getWorkInfosByTagLiveData() methods. These methods return instances of WorkInfo, which has a getProgress() method.

DocumentRenderWorker uses the DocumentRenderWorker.DEFAULT_WORK_INFO_TAG tag and the progress can be obtained using the DocumentRenderWorker.FLOAT_PROGRESS_KEY key:

WorkManager.getInstance(this)
.getWorkInfosByTagLiveData(DocumentRenderWorker.DEFAULT_WORK_INFO_TAG)
.observe(this) {
val progress = it.firstOrNull()?.progress?.getFloat(DocumentRenderWorker.FLOAT_PROGRESS_KEY, 0f)
}
}