ApsaraVideo VOD (VOD) allows you to migrate resources from third-party platforms to VOD and migrate video resources across different Alibaba Cloud accounts. This topic describes how to migrate resources.

Migration sources and methods

VOD supports the migration of the following resources:

  • Third-party resources: Migrate data resources such as videos that are stored on personal websites or in third-party clouds to VOD.
  • Resources that belong to different Alibaba Cloud accounts: Migrate VOD videos that are stored in an Object Storage Service (OSS) bucket to another Alibaba Cloud account.

The following table describes the methods, tools, and processes for resource migration.

Source Method Tool Process
Third-party resources Download and upload resources over the Internet.
  • ApsaraVideo VOD upload SDK (recommended)
  • ApsaraVideo VOD server API
Upload resources over the Internet
  1. Prepare the download URL of the resources that you want to migrate.
  2. Set up an upload service by using the upload SDK or the server API.
  3. Upload video resources.
  4. (Optional) Sort the video resources that you uploaded.
Resources that belong to different Alibaba Cloud accounts Upload resources over an internal network.
Notice The following requirements must be met:
  • The source video files are stored in OSS.
  • The VOD account and the OSS account are the same.
  • The Elastic Compute Service (ECS) instance and the source video files reside in the same region.
  • ApsaraVideo VOD upload SDK (recommended)
  • ApsaraVideo VOD server API
Upload resources over an internal network
  1. Obtain the URL of video resources and change the URL to the internal address of OSS.
  2. Set up an upload service by using the upload SDK or the server API.
  3. Upload video resources.
Resources that belong to different Alibaba Cloud accounts Upload resources over the Internet.
  • ApsaraVideo VOD upload SDK (recommended)
  • ApsaraVideo VOD server API
  1. Obtain the URL of the video resources from VOD.
  2. Set up an upload service by using the upload SDK or the server API.
  3. Upload video resources.

Prerequisites

  • An Alibaba Cloud account is created and real-name verification is complete. To create an Alibaba Cloud account, visit the Alibaba Cloud official website. For more information about how to create an Alibaba Cloud account, see Create an Alibaba Cloud account.

  • Obtain an AccessKey pair to complete identity verification so that you can call server API operations. For more information about how to obtain an AccessKey pair, see Obtain an AccessKey pair.

    Note To migrate resources as a RAM user, you must create a RAM user before you obtain the AccessKey ID and AccessKey secret. For more information, see Create and grant permissions to a RAM user.

Migrate third-party resources

Third-party resources refer to video resources that are stored on personal websites or in third-party clouds. To migrate third-party resources to VOD, perform the following steps:

  1. Prepare the resources that you want to migrate. You can save the download URL of the files that you want to migrate based on your business requirements.
    Note You must prepare the download URL of all files that you want to migrate. If the URL requires authentication, make sure that the URL is valid during download.
  2. Set up the upload service.
    For more information about the sample code, see Upload service setup and sample code. We recommend that you use the VOD upload SDK to migrate resources.
    Note If you want to sort videos after the migration, configure the upload service to record the mappings between the URL of the source video files and the video IDs that are generated after the video files are uploaded. You can select a method to record the mappings based on your business requirements. For example, you can record the mappings in logs or write the URL of the source video files to the media file records of videos during upload. If you call the UploadMediaByURL operation to upload resources, the response of this operation contains the URL of the uploaded source files. You can use the information based on your business requirements.
  3. Run the code that is written in Step 2 to upload videos to VOD.
  4. (Optional) Sort the video resources that you uploaded.

    After you migrate the video resources, you can sort the video resources based on the mappings between the URL of the source files and the video IDs that are generated after the video resources are uploaded to VOD.

Migrate resources that belong to different Alibaba Cloud accounts over the Internet

If you want to use the VOD solution in more regions, you can migrate VOD video resources that belong to an Alibaba Cloud account to another Alibaba Cloud account. To upload video resources over the Internet, perform the following steps:

Note In this example, the GetMezzanineInfo operation is called to obtain the URL of the source file. You can also obtain the URL of the source files in the ApsaraVideo VOD console. For more information, see Export media assets.
  1. Call the SearchMedia operation of VOD to query the IDs of the videos that you want to migrate.
  2. Call the GetMezzanineInfo operation of VOD and use the IDs of the videos that you obtained in Step 1 as the request parameter to obtain the URL of the source video files that you want to migrate. Then, save the URL.
    Note If you want to use transcoded videos as the source videos, you must upload the transcoded videos in the VOD console. For more information, see Manage media assets.
  3. Set up the upload service.

    For more information about the sample code, see Upload service setup and sample code. We recommend that you use the VOD upload SDK to migrate resources.

  4. Run the code that is written in Step 3 to upload videos to VOD.

Migrate resources that belong to different Alibaba Cloud accounts over an internal network

If you want to use the VOD solution in more regions, you can migrate VOD video resources that are stored in an OSS bucket to another Alibaba Cloud account. You can upload video resources over an internal network. Before you upload video resources over an internal network, make sure that the following requirements are met:
  • The source video files are stored in OSS.
  • The VOD account and the OSS account are the same.
  • The ECS instance and the source video files reside in the same region.

To migrate resources, perform the following steps:

  1. Call the GetMezzanineInfo operation of the VOD server to obtain the OSS address of the files that you want to migrate.
    Note Set the OutputType parameter to oss.
  2. Add -internal after the OSS region to modify the OSS address to an internal network address. The following example shows the address before and after modification:
    OSS address Internal network address
    outin-67870fd5b29****98a3900163e1c35d5.oss-cn-shanghai.aliyuncs.com/customerTrans/2a13b91506f9158f****7317f4a9d4c9/30f24681-1718d5c6237-**4bd.mp4 outin-67870fd5b29****98a3900163e1c35d5.oss-cn-shanghai-internal.aliyuncs.com/customerTrans/2a13b91506f9158f****7317f4a9d4c9/30f24681-1718d5c6237-**4bd.mp4

    For more information about how to access OSS resources over an internal network, see Access to OSS resources from ECS instances by using an internal endpoint of OSS.

  3. Set up the upload service.
    Note If you want to upload resources over the internal network when you migrate resources across Alibaba Cloud accounts, we recommend that you deploy the upload service on an ECS instance that resides in the same region as the OSS bucket of VOD. By default, the OSS bucket is located in the China (Shanghai) region. After you deploy the upload service on an ECS instance that resides in the same region as the OSS bucket, set the regionId parameter to the preceding region. If you use the upload SDK to upload resources, the resources are uploaded over the internal network.

    For more information about the sample code, see Upload service setup and sample code. We recommend that you use the VOD upload SDK to migrate resources.

  4. Run the code that is written in Step 3 to upload videos to VOD.

Upload service setup and sample code

If you want to migrate third-party resources or resources that belong to different Alibaba Cloud accounts, you must download the original video resources, and then use the upload tool to upload the resources to VOD. ApsaraVideo VOD allows you to upload resources by using the upload SDK or the server API. The upload service can be implemented by using the upload SDK or the server API. We recommend that you use the upload SDK. This way, the resources are uploaded in a synchronous and efficient manner. If you use the server API, the resources are uploaded in an asynchronous manner, and the timeliness of the upload process cannot be guaranteed.

Procedure to set up the upload service

  1. Integrate the upload SDK or the server SDK.

    You can integrate the upload SDK or the server SDK based on the programming language that you use. For more information about how to integrate the upload SDK, see Overview. For more information about how to integrate the server SDK, see Usage notes.

  2. Write the code of the upload service. The following example shows how to write the code:

Sample code for the upload SDK (recommended)

The following sample code shows the code of the upload SDK in Java. For more information about the upload SDK in other programming languages, see Overview.

import com.aliyun.vod.upload.impl.UploadVideoImpl;
import com.aliyun.vod.upload.req.UploadStreamRequest;
import com.aliyun.vod.upload.resp.UploadStreamResponse;
import java.io.*;
import java.net.URL;

/**
 * Use the upload SDK to upload video files.
 */
public class UploadStreamDemo {
    /**
     * The stream upload operation.
     *
     * @param accessKeyId
     * @param accessKeySecret
     * @param title
     * @param fileName
     * @param inputStream
     */
    private static void testUploadStream(String accessKeyId, String accessKeySecret, String title, String fileName, InputStream inputStream) {
        UploadStreamRequest request = new UploadStreamRequest(accessKeyId, accessKeySecret, title, fileName, inputStream);
        
        /* Create custom callback configurations for event notifications. For more information about the parameters, see Basic structures. */
        //request.setUserData(""{\"Extend\":{\"test\":\"www\",\"localId\":\"xxxx\"},\"MessageCallback\":{\"CallbackURL\":\"http://example.aliyundoc.com\"}}"");
        /* Optional. Specify the category ID of the video. */
        //request.setCateId(0);
        /* Optional. Specify the tags of the video. Separate multiple tags with commas (,). */
        //request.setTags("tag 1,tag 2");
        /* Optional. Specify the description of the video. */
        //request.setDescription("video description");
        /* Optional. Specify the URL of the thumbnail. Example: http://****.example.com/image_01.jpg. */
        //request.setCoverURL("<Your CoverURL>");
        /* Optional. Specify the ID of the template group. */
        //request.setTemplateGroupId("8c4792cbc8694e****fd5330e56a33d");
        /* Optional. Specify the ID of the workflow. */
        //request.setWorkflowId("d4430d07361f****1339577859b0177b");
        /* Optional. Specify the storage location. */
        //request.setStorageLocation("outin-20170323****266-5sejdln9o.oss-cn-shanghai.aliyuncs.com");
        /* Specify the access region of VOD. */
        request.setApiRegionId("cn-shanghai");
        /* Specify the region in which the ECS instance is deployed. */
        // request.setEcsRegionId("cn-shanghai");
        UploadVideoImpl uploader = new UploadVideoImpl();
        UploadStreamResponse response = uploader.uploadStream(request);
        System.out.print("RequestId=" + response.getRequestId() + "\n"); // Specify the ID of the request that is sent to VOD.
        if (response.isSuccess()) {
            System.out.print("VideoId=" + response.getVideoId() + "\n");
        } else { // If the callback URL that you specify is invalid, the upload process is not affected. The video ID and an error code are returned. If the upload fails in other cases, the video ID is empty. You need to analyze the cause based on the returned error code.
            System.out.print("VideoId=" + response.getVideoId() + "\n");
            System.out.print("ErrorCode=" + response.getCode() + "\n");
            System.out.print("ErrorMessage=" + response.getMessage() + "\n");
        }
    }

    public static void main(String[] args) {
        /**
         * Specify the URL of the source video, pass the information about the video, and upload the video.
         */
        InputStream inputStream = null;
        // The URL of the video. Example: http://example.aliyundoc.com/video/****.mp4.
        String url = "<Your File URL>";
        try {
            inputStream = new URL(url).openStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
        // In the following code, the AccessKey ID and the AccessKey Secret are the AccessKey pair that you obtained. <Your Video Title> is the title of the video. <Your Video with File Extension> is the name of a video file with a filename extension, for example, video-1.mp4. 
        testUploadStream("<AccessKey Id>", "<AccessKey Secret>", "<Your Video Title>", "<Your Video with File Extension>", inputStream);
    }
}

Sample code for the server API (not recommended)

You can call the UploadMediaByURL operation to upload media files based on the URLs of source files. You can also upload information about the media files, for example, the title, category, and description of each video, when you upload the files based on your business requirements. When you use the server API, resources are uploaded in an asynchronous manner. This method is not recommended.

Sample code:

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.UploadMediaByURLRequest;
import com.aliyuncs.vod.model.v20170321.UploadMediaByURLResponse;
import java.net.URLEncoder;

/**
 * Upload videos based on the URLs of source files in an asynchronous manner.
 * Before you call the UploadMediaByURL operation, we recommend that you read API references to understand the advantages and disadvantages of this operation.
 * For more information, see UploadMediaByURL.
 */
public class UploadMediaByURLDemo {
    public static DefaultAcsClient initVodClient(String accessKeyId, String accessKeySecret) throws ClientException {
        String regionId = "cn-shanghai";  // Specify the access region of VOD.
        DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(profile);
        return client;
    }

    /**
     * Upload media files based on the URLs of source files.
     * @param client The client that sends a request.
     * @return UploadMediaByURLResponse The response to the request to upload videos based on the URLs of source files.
     * @throws Exception
     */
    public static UploadMediaByURLResponse uploadMediaByURL(DefaultAcsClient client,String url) throws Exception{
        UploadMediaByURLRequest request = new UploadMediaByURLRequest();
        //String url = "http://xxxx.mp4";
        String encodeUrl = URLEncoder.encode(url, "UTF-8");
        request.setUploadURLs(encodeUrl);

        // The metadata of the uploaded video files. The value is a JSON string.
        JSONObject uploadMetadata = new JSONObject();
        uploadMetadata.put("SourceUrl", encodeUrl);
        uploadMetadata.put("Title", "upload by url sample");
        JSONArray uploadMetadataList = new JSONArray();
        uploadMetadataList.add(uploadMetadata);
        request.setUploadMetadatas(uploadMetadataList.toJSONString());
        JSONObject userData = new JSONObject();
        
    // The callback configuration. If you configure the Video Upload Completed event in the VOD console, VOD sends a notification to the specified callback URL when video files are uploaded.
        JSONObject messageCallback = new JSONObject();
        messageCallback.put("CallbackURL", "<Your Callback URL>");// The URL that is used to receive callbacks. Example: http://example.com/callback****.
        messageCallback.put("CallbackType", "http");
        userData.put("MessageCallback", messageCallback.toJSONString());
        JSONObject extend = new JSONObject();// The content of the message. The value is written to the callback message and is transparently transmitted.
        extend.put("MyId", "user-defined-id");
        userData.put("Extend", extend.toJSONString());
        request.setUserData(userData.toJSONString());
        return client.getAcsResponse(request);
    }

    // Sample requests
    public static void main(String[] argv) throws ClientException {
        DefaultAcsClient client = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
        UploadMediaByURLResponse response = new UploadMediaByURLResponse();
        try { 
    // You can modify the code to read the text file that contains the URLs of source files that you want to migrate.
            response = uploadMediaByURL(client,"<Your File URL>");// The upload URL in the file. Example: http://example.aliyundoc.com.****.mp4.
            System.out.print("UploadJobs = " + JSON.toJSONString(response.getUploadJobs()) + "\n");
        } catch (Exception e) {
            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
        }
        System.out.print("RequestId = " + response.getRequestId() + "\n");
    }
}