All Products
Search
Document Center

Video upload

Last Updated: Apr 03, 2020

Overview

The ApsaraVideo for VOD upload SDK plays an important role in the mission of ApsaraVideo for connecting devices through the cloud. The upload SDK allows you to conveniently upload files to ApsaraVideo for VOD and Object Storage Service (OSS). 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

Step 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 integrating the upload SDK

Step 2. Set parameters for the upload SDK

  1. Call the addView method to add an AlivcVideoPublishView instance to the UI. The sample code is as follows:
  1. // Create an upload view object.
  2. mAlivcVideoPublishView = new AlivcVideoPublishView(this);
  3. // Configure a listener for the expiration of the upload credential.
  4. mAlivcVideoPublishView.setOnAuthInfoExpiredListener(new OnAuthInfoExpiredListener() {
  5. @Override
  6. public void onImageAuthInfoExpired() {
  7. // TODO: Update the image upload credential.
  8. //......
  9. // Update the image upload credential.
  10. mAlivcVideoPublishView.refreshImageUploadAuthInfo(data.getImageId(),
  11. data.getImageURL(),
  12. data.getUploadAddress(),
  13. data.getUploadAuth());
  14. }
  15. @Override
  16. public void onVideoAuthInfoExpired(String videoId) {
  17. // TODO: Update the video upload credential.
  18. //......
  19. // Update the video upload credential.
  20. mAlivcVideoPublishView.refreshVideoAuth(data.getUploadAddress(),
  21. data.getUploadAuth());
  22. }
  23. });
  24. // Configure a listener for the callback of the upload result.
  25. mAlivcVideoPublishView.setOnUploadCompleteListener(new MyUploadCompleteListener(this));
  26. FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
  27. FrameLayout.LayoutParams.MATCH_PARENT,
  28. FrameLayout.LayoutParams.MATCH_PARENT);
  29. mContentView.addView(mAlivcVideoPublishView, params);
  1. Use the AlivcVideoPublishView class to call the startUpload method and start to produce and upload a video.
  1. mAlivcVideoPublishView.startUpload(
  2. // The path of the editing configuration file in JSON format.
  3. mConfigPath,
  4. // The output path of the produced video.
  5. mComposeOutputPath,
  6. // The video ID.
  7. mVideoUploadAuthInfo.getVideoId(),
  8. // The video upload URL.
  9. mVideoUploadAuthInfo.getUploadAddress(),
  10. // The video upload credential.
  11. mVideoUploadAuthInfo.getUploadAuth(),
  12. // The video description.
  13. mVideoDesc,
  14. // The image path of the video thumbnail.
  15. mThumbnailPath,
  16. // The image ID.
  17. mImageUploadAuthInfo.getImageId(),
  18. // The image URL.
  19. mImageUploadAuthInfo.getImageURL(),
  20. // The image upload URL.
  21. mImageUploadAuthInfo.getUploadAddress(),
  22. // The image upload credential.
  23. 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 issue.

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 AliyunIVodCompose 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 guarantee that users can perform other operations during video production. The implementation procedure is as follows:

  1. Set the redirect page after editing.

    By 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:

    ```java

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

  1. > Note: You must run the preceding code to register a redirect activity before editing.
  2. 2. Set the parameters to be received.
  3. Enable users to receive the parameters required by video production on their own publish UI.
  4. ```java
  5. // Enable users to receive the path of the editing configuration file in JSON format.
  6. mConfigPath = intent.getStringExtra("project_json_path");
  7. // Enable users to receive the image path of the video thumbnail.
  8. mThumbnailPath = intent.getStringExtra("svideo_thumbnail");

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

  1. Start video production.

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

  1. // Create an AliyunIVodCompose object.
  2. AliyunIVodCompose mCompose = AliyunComposeFactory.createAliyunVodCompose();
  3. mCompose.init(context);
  4. // Start video production.
  5. mCompose.compose(
  6. // The path of the configuration file.
  7. mConfigPath,
  8. // The output path of the produced video.
  9. DefaultSvideoParam.DIR_COMPOSE+"/output_compose_video.mp4",
  10. // The listener for the callback of video production.
  11. new AliyunIComposeCallBack() {
  12. @Override
  13. public void onComposeError(int i) {
  14. // TODO: Configure the callback that is to be fired when an error occurs during video production.
  15. }
  16. @Override
  17. public void onComposeProgress(int i) {
  18. // TODO: Configure the callback that is to be fired when the specified progress of video production is reached.
  19. }
  20. @Override
  21. public void onComposeCompleted() {
  22. // TODO: Configure the callback that is to be fired when video production completes.
  23. }
  24. });

Video upload

The client upload SDK allows you to upload videos to ApsaraVideo for VOD by using Security Token Service (STS) or the upload URL and credential.

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:

  1. // Upload a video thumbnail.
  2. mCompose.uploadImageWithVod(
  3. // The image path of the video thumbnail.
  4. mThumbnailPath,
  5. // The image upload URL of the video thumbnail.
  6. mImageAddress ,
  7. // The upload credential.
  8. mImageAuth,
  9. // The progress callback.
  10. aliyunIVodUploadCallBack );
  1. // Upload a video.
  2. mCompose.uploadVideoWithVod(
  3. // The file path of the video.
  4. mOutputFilePath,
  5. // The video upload URL.
  6. mVideoAddress,
  7. // The upload credential.
  8. mVideoAuth ,
  9. // The progress callback.
  10. aliyunIVodUploadCallBack);