How are interesting still photos dynamized?
Huawei Video Editor Kit's newly launched "Dynamic Photo" capability uses AI algorithms such as face detection, facial key point detection, expression feature extraction, and target character expression drive. Just upload a static character photo, You can generate actions such as people's smiles, easily realize dynamic static photos, and make photos more vivid.
It is also very simple to implement this function, let's take a look at the integration steps!
integration code
1 Development preparation
For detailed preparation steps, please refer to the official website of Huawei Developer Alliance:
https://developer.huawei.com/consumer/cn/doc/development/Media-Guides/config-agc-0000001101108580?ha_source=hms1
2 Editing project integration
2.1 Set the authentication information of the application
Application authentication information can be set through api_key or Access Token.
The Access Token is set 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");
The api_key is set by the setApiKey method, which can be initialized and set once when the application starts, and there is no need to set it 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");
2.2.1 Initialize the Editor runtime environment
To 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;
}
2.2.2 Adding videos and pictures
Create a video swimlane, then add pictures or video footage to the swimlane. Images and video clips need to be added to the swimlane via the file path.
// 获取时间线对象
HVETimeLine timeline = editor.getTimeLine();
// 创建视频泳道
HVEVideoLane videoLane = timeline.appendVideoLane();
// 在视频泳道的末尾,添加视频资源
HVEVideoAsset videoAsset = videoLane.appendVideoAsset("test.mp4");
// 在视频泳道的末尾,添加图片资源
HVEImageAsset imageAsset = videoLane.appendImageAsset("test.jpg");
3 Dynamic Photo Integration
// 添加动态照片特效
videoAsset.addFaceReenactAIEffect(new HVEAIProcessCallback() {
@Override
public void onProgress(int progress) {
// 动态照片处理进度
}
@Override
public void onSuccess() {
// 动态照片处理成功
}
@Override
public void onError(int errorCode, String errorMessage) {
// 动态照片处理失败
}
});
// 移除动态照片特效
videoAsset.removeFaceReenactAIEffect();
Demo
During the process of integrated development, you can place a bill of lading online if you have any questions, and someone will answer it for you.
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) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。