All Products
Search
Document Center

Video upload

Last Updated: Aug 01, 2019

Overview

The ApsaraVideo for VOD upload SDK plays an important role in ApsaraVideo's mission for connecting devices through the cloud. If you integrate the upload SDK, you can upload various data files including image, video, and audio files. ApsaraVideo for VOD provides multiple versions of the upload SDK, such as that for the web client (JavaScript), mobile client (Android and iOS), and server (Java). To upload files, you can also call APIs or use the Alibaba Cloud console.

Quickly integrate the upload SDK

1. Copy files

Copy the code and relevant resource files in the com/aliyun/apsara/alivclittlevideo/view/publish directory of the AlivcLittleVideo module. Copy files for upload

2. Use the feature

  • Call the addView method to add an AlivcVideoPublishView instance to the UI.
// Creates an upload view object.
mAlivcVideoPublishView = new AlivcVideoPublishView(this);
// Configures a listener for the expiration of the upload credential.
mAlivcVideoPublishView.setOnAuthInfoExpiredListener(new OnAuthInfoExpiredListener() {
@Override
public void onImageAuthInfoExpired() {
// TODO: Updates the image upload credential.
//......
// Updates the image upload credential.
mAlivcVideoPublishView.refreshImageUploadAuthInfo(data.getImageId(),
    data.getImageURL(),
    data.getUploadAddress(),
    data.getUploadAuth());
    }
@Override
public void onVideoAuthInfoExpired(String videoId) {
// TODO: Updates the video upload credential.
//......
// Updates the video upload credential.
mAlivcVideoPublishView.refreshVideoAuth(data.getUploadAddress(),
    data.getUploadAuth());
    }
});
// Configures a listener for the callback of the upload result.
mAlivcVideoPublishView.setOnUploadCompleteListener(new MyUploadCompleteListener(this));
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
    FrameLayout.LayoutParams.MATCH_PARENT,
    FrameLayout.LayoutParams.MATCH_PARENT);
mContentView.addView(mAlivcVideoPublishView, params);
  • Use the AlivcVideoPublishView class to call the startUpload method and start to produce and upload a video.
mAlivcVideoPublishView.startUpload(
    // The path of the editing configuration file in JSON format.
    mConfigPath,
    // The output path of the produced video.
    mComposeOutputPath,
    // The video ID.
    mVideoUploadAuthInfo.getVideoId(),
    // The video upload URL.
    mVideoUploadAuthInfo.getUploadAddress(),
    // The video upload credential.
    mVideoUploadAuthInfo.getUploadAuth(),
    // The video description.
    mVideoDesc,
    // The image path of the video thumbnail.
    mThumbnailPath,
    // The image ID.
    mImageUploadAuthInfo.getImageId(),
    // The image URL.
    mImageUploadAuthInfo.getImageURL(),
    // The image upload URL.
    mImageUploadAuthInfo.getUploadAddress(),
    // The image upload credential.
    mImageUploadAuthInfo.getUploadAuth());

Video upload solution

The short video production and upload process is as follows: After editing a video, produce a video based on the edited video and upload the produced video to ApsaraVideo for VOD. However, because the video production and upload process is time-consuming, many users hope that they can still use other features of the same application properly during this process. This solution is developed to solve this problem.

Video production

You can produce a video in two ways: on the current page (foreground production) and other pages (background production, where you do not need to move the application to the background).

  • Foreground production: Use the AliyunIEditor class to call the compose method after editing to produce a video based on the edited video. In this case, users have to stay on the current page and can go to other pages only after video production.

  • Background production: Use the AliyunICompose class to call the compose method based on the received configuration file path to produce a video based on the edited video on other pages.

This solution uses background production to ensure that users can perform other operations during video production. The implementation procedure is as follows:

  1. Set the redirect page after editing.

    Using the activity registration feature provided by the editing module, register a redirect activity to replace the publish page that users are redirected to by default after editing. The sample code is as follows:

// Registers a redirect page after editing.
AliyunSvideoActionConfig.getInstance().registerPublishActivity(PublishActivity.class.getName());

You must run the preceding code to register a redirect activity before editing.

  1. Set the parameters to be received.

    Enable users to receive the parameters required by video production on their own publish UI.

// Enables users to receive the path of the editing configuration file in JSON format.
mConfigPath = intent.getStringExtra("project_json_path");
// Enables users to receive the image path of the video thumbnail.
mThumbnailPath = intent.getStringExtra("svideo_thumbnail");

Users can receive the preceding parameters only in the registered activity.

  1. Start video production.

    Use the AliyunICompose class to call the compose method based on the received configuration file path to produce a video based on the edited video.

// Creates an AliyunICompose object.
AliyunIVodCompose mCompose = AliyunComposeFactory.createAliyunVodCompose();
mCompose.init(context);
// Starts video production.
mCompose.compose(
// The path of the configuration file.
mConfigPath,
// The output path of the produced video.
DefaultSvideoParam.DIR_COMPOSE+"/output_compose_video.mp4",
// The listener for the callback of video production.
new AliyunIComposeCallBack() {
@Override
public void onComposeError(int i) {
// TODO: Configures the callback that is to be fired when an error occurs during video production.
}
@Override
public void onComposeProgress(int i) {
// TODO: Configures the callback that is to be fired when the specified progress of video production is reached.
}
@Override
public void onComposeCompleted() {
// TODO: Configures the callback that is to be fired when video production completes.
}
});

Video upload

The client upload SDK allows you to upload videos to ApsaraVideo for VOD in the following two authorization modes:

This solution uses the upload URL and credential to upload videos. The implementation procedure is as follows: Use the AliyunIVodCompose class to call the uploadImageWithVod method to upload a video thumbnail based on the specified image upload URL and credential and image path, and then call the uploadVideoWithVod method to upload a video based on the specified video information. The sample code is as follows:

// Uploads a video thumbnail.
mCompose.uploadImageWithVod(
// The image path of the video thumbnail.
mThumbnailPath,
// The image upload URL.
mImageAddress ,
// The upload credential.
mImageAuth,
// The progress callback.
aliyunIVodUploadCallBack );
// Uploads a video.
mCompose.uploadVideoWithVod(
// The file path of the video.
mOutputFilePath,
// The video upload URL.
mVideoAddress,
// The upload credential.
mVideoAuth ,
// The progress callback.
aliyunIVodUploadCallBack);