In this example, we will show you how to initialize the CreativeEditor SDK with an initial video.
Starting from an existing video allows you to use the editor for customizing individual assets.
This is done by using func create(fromVideo url: URL) async throws -> DesignBlockID
and passing a URL as argument.
Specify the source to use for the initial video. This can be a relative path or a remote URL.
let scene = try await engine.scene.create(fromVideo: URL(string: "https://img.ly/static/ubq_video_samples/bbb.mp4")!)
We can retrieve the graphic block id of this initial video using func find(byType type: DesignBlockType) throws -> [DesignBlockID]
.
Note that that function returns an array.
Since there’s only a single graphic block in the scene, the block is at index 0
.
// Find the automatically added graphic block in the scene that contains the video fill.let block = try engine.block.find(byType: .graphic).first!
We can then manipulate and modify this block.
Here we modify its opacity with func setOpacity(_ id: DesignBlockID, value: Float) throws
.
See Modifying Scenes for more details.
// Change its opacity.try engine.block.setOpacity(block, value: 0.5)
When starting with an initial video, the scene’s page dimensions match the given resource and the scene is configured to be in pixel design units.
To later save your scene, see Saving Scenes.
Full Code
Here’s the full code:
import Foundationimport IMGLYEngine
@MainActorfunc createSceneFromVideoURL(engine: Engine) async throws { let scene = try await engine.scene.create(fromVideo: URL(string: "https://img.ly/static/ubq_video_samples/bbb.mp4")!)
// Find the automatically added graphic block in the scene that contains the video fill. let block = try engine.block.find(byType: .graphic).first!
// Change its opacity. try engine.block.setOpacity(block, value: 0.5)}