Skip to main content
Language:

From Resources

VideoEditor SDK supports adding custom filters from the resources. In this example, we add custom LUT and duotone filters.

WARNING: Be sure to put the drawables for the filters in the res/drawable-nodpi folder. Otherwise, they will be scaled by the Android system.

LUT and Duotone Filters#

For the custom LUT filter to invert the video colors we construct a LutColorFilterAsset object providing the local resource drawable. The duotone filter, additionally, requires passing the light and dark color of the filter.

Add filters to AssetConfig#

To use the filters, they must first be available in the SDK's backend. This is done by adding the filters to the AssetConfig.

Create filter group#

In cases where we want to simplify navigation and discovery, we can group sets of related filters that will appear in a single folder in the filter tool.

Create a FolderItem passing a unique identifier, a display name for the group and a thumbnail for the group folder.

Configure UiConfigFilter#

Here, we configure UiConfigFilter and add the custom FolderItem we created above to the filterList. Alternatively, we could have directly added the FilterItems to the filterList without creating a folder.

File:
class VideoAddFiltersFromResources(private val activity: AppCompatActivity) : Example(activity) {
override fun invoke() {
// In this example, we do not need access to the Uri(s) after the editor is closed
// so we pass false in the constructor
val settingsList = VideoEditorSettingsList(false)
// Set the source as the Uri of the video to be loaded
.configure<LoadSettings> {
it.source = activity.resourceUri(R.raw.skater)
}
// Create a custom LUT filter
val customLUTFilter = LutColorFilterAsset("custom_lut_filter", ImageSource.create(R.drawable.custom_lut_invert), 5, 5, 128)
// Create a custom DuoTone filter
val customDuoToneFilter = DuotoneFilterAsset("custom_duotone_filter", -0x100, -0xffff01)
// Add assets to AssetConfig
settingsList.config.addAsset(customLUTFilter, customDuoToneFilter)
// Create custom filters folder
val customFiltersFolder = FolderItem(
"custom_filter_category", "Custom", ImageSource.create(R.drawable.custom_filter_category), listOf(
FilterItem("custom_lut_filter", "Invert"),
FilterItem("custom_duotone_filter", "YellowBlue")
)
)
settingsList.configure<UiConfigFilter> {
// Alternatively, we could have directly added FilterItem(s) here without creating a folder.
it.filterList.add(customFiltersFolder)
}
// Start the video editor using VideoEditorBuilder
// The result will be obtained in onActivityResult() corresponding to EDITOR_REQUEST_CODE
VideoEditorBuilder(activity)
.setSettingsList(settingsList)
.startActivityForResult(activity, EDITOR_REQUEST_CODE)
// Release the SettingsList once done
settingsList.release()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
intent ?: return
if (requestCode == EDITOR_REQUEST_CODE) {
// Wrap the intent into an EditorSDKResult
val result = EditorSDKResult(intent)
when (result.resultStatus) {
EditorSDKResult.Status.CANCELED -> showMessage("Editor cancelled")
EditorSDKResult.Status.EXPORT_DONE -> showMessage("Result saved at ${result.resultUri}")
else -> {
}
}
}
}
}