Sharing and creating short videos has become a way for people to record a good life. Many users will encounter insufficient material when editing, and often choose to use a few pictures as supplementary material. However, the interspersed pictures in the video will make the transition part in the work appear very blunt and deliberate; then how to make up for the shortcomings of the pictures through the post-editing function, so that users can smoothly complete the video creation?
Adding motion effects to pictures can solve this problem. Motion effects can make static photos produce dynamic video effects, which can connect the clips naturally and smoothly, making the whole work more harmonious.
This kind of dynamic effect requires the user to manually set the anchor point in the professional special effect tool to produce the fluid motion effect, and the operation is complicated. Now, the integration of Huawei HMS Core video editing service "one-click dynamic effect" function allows users to quickly achieve this effect, so that the static landscape photos in the mobile phone album can be "moved" anytime, anywhere.
HMS Core Video Editing Service "One-Click Motion" Function
The "One-click dynamic effect" function can make the static landscape picture realize the video dynamic effect, enter a picture with the sky or water surface, and "one-click dynamic effect" makes the clouds in the sky flutter or the water surface flows. Developers can also manually set the movement speed, movement direction, one-click removal effect, etc. to make the animation more realistic.
Let's take a look at how to integrate Huawei's video editing service to realize the "one-click motion effect" function:
1. Development preparation
For detailed preparation steps, please refer to the official website of Huawei Developer Alliance
2. Edit project integration
2.1 Set the authentication information of the application
Application authentication information can be set through api_key or Access Token.
· Set the Access Token through the setAccessToken method, which can be initialized and set once when the application starts, and there is no need to set it multiple times.
MediaApplication.getInstance().setAccessToken("your access token");
· Set the api_key through the setApiKey method, which can be initialized and set once when the application starts, and does not need to be set multiple times.
MediaApplication.getInstance().setApiKey("your ApiKey");
2.2 Set the unique identification ID, that is, the License ID.
The license ID is a valid certificate for management and control. You must ensure that the license ID is unique.
MediaApplication.getInstance().setLicenseId("License ID");
To initialize the Editor runtime environment and create an editing project, you need to first create an Editor object and initialize its runtime environment. When leaving the editing project, the Editor instance should be released.
(1) Create Editor object
HuaweiVideoEditor editor = HuaweiVideoEditor.create(getApplicationContext());
(2) Specify the layout position of the preview window
The preview window is responsible for the rendering of video images, which is realized by creating SurfaceView inside the video editing atomic capability SDK. Before creating the window, you need to specify the layout position of the preview window in your app.
<LinearLayout
android:id="@+id/video_content_layout"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/video_edit_main_bg_color"
android:gravity="center"
android:orientation="vertical" />
// 指定预览窗口
LinearLayout mSdkPreviewContainer = view.findViewById(R.id.video_content_layout);
// 设置预览窗口承载的布局
editor.setDisplay(mSdkPreviewContainer);
(3) Initialize the running environment. If the license authentication fails, a LicenseException will be thrown.
After the Editor object is created, the actual system resources are not occupied at this time, and the timing of its environment initialization needs to be manually selected. At this time, the necessary threads and timers will be created inside the Video Editing Atomic Capability SDK.
try {
editor.initEnvironment();
} catch (LicenseException error) {
SmartLog.e(TAG, "initEnvironment failed: " + error.getErrorMsg());
finish();
return;
}
3 "One-click dynamic effect" capability integration
// 初始化一键动效AI引擎
imageAsset.initTimeLapseEngine(new HVEAIInitialCallback() {
@Override
public void onProgress(int progress) {
// 初始化进度
}
@Override
public void onSuccess() {
// 初始化成功
}
@Override
public void onError(int errorCode, String errorMessage) {
// 初始化失败
}
});
// 初始化成功后,检查图片中是否有天空或者水面
int motionType = -1;
imageAsset.detectTimeLapse(new HVETimeLapseDetectCallback() {
@Override
public void onResult(int state) {
// 记录state作为添加一键动效AI特效的参数
motionType = state;
}
});
// skySpeed:天空的运动速度; skyAngle:天空的运动方向; waterSpeed:水面的运动速度; waterAngle:水面的运动方向
HVETimeLapseEffectOptions options =
new HVETimeLapseEffectOptions.Builder().setMotionType(motionType)
.setSkySpeed(skySpeed)
.setSkyAngle(skyAngle)
.setWaterAngle(waterAngle)
.setWaterSpeed(waterSpeed)
.build();
// 添加一键动效AI特效
imageAsset.addTimeLapseEffect(options, new HVEAIProcessCallback() {
@Override
public void onProgress(int progress) {
}
@Override
public void onSuccess() {
}
@Override
public void onError(int errorCode, String errorMessage) {
}
});
// 中断一键动效AI特效处理
imageAsset.interruptTimeLapse();
// 移除一键动效AI特效
imageAsset.removeTimeLapseEffect();
In addition to supporting one-click motion effects, HMS Core video editing service also provides basic video editing, AI coloring, exclusive filters, highlight clips, one-click hair coloring, character tracking, face hiding and other video creation capabilities. Easily integrate video editing functions in the app.
Learn more details>>
Visit the official website of Huawei Developer Alliance
Get development guidance documents
Huawei Mobile Services Open Source Warehouse Address: GitHub , Gitee
Follow us to know the latest technical information of HMS Core for the first time~
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。