Nowadays, video is the most popular way for users to record their life, and various apps provide the function of simple video editing in the video publishing interface. In addition to adding basic functions such as music, filters, and stickers, users are increasingly pursuing a sense of lens, which often requires manual keyframes through professional video editing software, and operations such as zooming in, zooming out, and moving can be achieved, which increases the number of users The threshold for sharing videos is not conducive to the production of UGC content.
Is there an open capability that can automatically generate a dynamic tracking lens video with the character displacement from a fixed-lens video?
The HMS Core video editing service provides developers with the ability to quickly build character tracking, allowing users to automatically lock the center position when editing videos, and easily generate professional videos with a sense of protagonist shots.
Features
Person tracking supports automatic locking of a specific person in the video input by the user, and easily generates a protagonist video of a specific person. For example, in travel scenarios, videos shot by users in scenic spots tend to have cluttered backgrounds and many people, but using the character tracking function during editing allows users to stay in the "C position" without fear of confusion.
Show results
Before and after using person tracking
Development steps
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.
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 running 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 swim lane, and then add pictures or video material to the swim lane. 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. Character tracking capability integration
// 初始化人物跟踪引擎
visibleAsset.initHumanTrackingEngine(new HVEAIInitialCallback() {
@Override
public void onProgress(int progress) {
// 初始化进度
}
@Override
public void onSuccess() {
// 初始化成功
}
@Override
public void onError(int errorCode, String errorMessage) {
// 初始化失败
}
});
// 通过坐标点选中指定的人物进行跟踪,返回人物的矩形轮廓坐标
List<Float> rects = visibleAsset.selectHumanTrackingPerson(bitmap, position2D);
// 开启人物跟踪特效
visibleAsset.addHumanTrackingEffect(new HVEAIProcessCallback() {
@Override
public void onProgress(int progress) {
// 处理进度
}
@Override
public void onSuccess() {
// 处理成功
}
@Override
public void onError(int errorCode, String errorMessage) {
// 处理失败
}
});
// 中断人物跟踪
visibleAsset.interruptHumanTracking();
// 移除人物跟踪特效
visibleAsset.removeHumanTrackingEffect();
Learn more details>>
Visit the official website of the Video Editing Service Developer Alliance
Get the video editing service development guidance document
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) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。