4

Many old photos or movies are limited by the technology of the times and can only be saved in black and white; the edited black and white videos and pictures have long lost their original color images, which is a pity for the savers. How can a single boring, old and mottled black and white photo be turned into a vivid and bright color photo, and more characteristic details can be retrieved from the photo, so that the viewer has a stronger sense of substitution and emotional resonance?

Huawei's video editing service (Video Editor Kit) has new "161df8eb94ce89 AI Coloring " capability, providing developers with a black and white one-click coloring solution. After the application integrates the "AI coloring" capability of the video editing service, users only need to upload a black-and-white photo or a black-and-white video to obtain vivid and colorful color photos or videos.

The operation is simple and the effect is very good!

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 = vidoeLane.appendVideoAsset("test.mp4");

// 在视频泳道的末尾,添加图片资源 
HVEImageAsset imageAsset = vidoeLane.appendImageAsset("test.jpg");

3 AI Shading Integration

AI coloring supports picture and video resources, and the video size is limited to 100M.

// 添加AI着色特效
videoAsset.addColorAIEffect(new HVEAIProcessCallback() {
        @Override
        public void onProgress(int progress) {
        // AI着色处理进度
        }

        @Override
        public void onSuccess() {
        // AI着色处理成功
        }

        @Override
        public void onError(int errorCode, String errorMessage) {
        // AI着色处理失败
        }
    });

// 移除AI着色特效
videoAsset.removeAIColorEffect();

Demo

In the process of integrated development, you can online bill of lading if you have any questions, and someone will answer it for you.

Learn more >>

Visit Huawei Developer Alliance official website
Get development guidance document
Huawei Mobile Services open source warehouse address: GitHub , Gitee

us and know the latest technical information of HMS Core for the first time~


HarmonyOS_SDK
596 声望11.7k 粉丝

HarmonyOS SDK通过将HarmonyOS系统级能力对外开放,支撑开发者高效打造更纯净、更智能、更精致、更易用的鸿蒙原生应用,和开发者共同成长。