ApsaraVideo VOD lets you migrate resources from third-party platforms to ApsaraVideo VOD and migrate video resources between Alibaba Cloud accounts. This topic describes how to perform these migrations.
Migration scenarios and methods
ApsaraVideo VOD supports multiple migration methods. You can migrate resources from personal websites or third-party cloud services, OSS resources within or between Alibaba Cloud accounts, and ApsaraVideo VOD resources between Alibaba Cloud accounts.
After a successful migration, ApsaraVideo VOD generates new video information, such as the video ID, playback URL, and thumbnail URL. You must manually associate the video information from before and after the migration.
Migration Scenarios | Migration Method | Migration tools |
Migrate third-party resources to ApsaraVideo VOD |
| |
Migrate OSS resources to ApsaraVideo VOD within an Alibaba Cloud account |
| |
Migrate OSS resources to ApsaraVideo VOD between Alibaba Cloud accounts |
| |
Migrate ApsaraVideo VOD resources between Alibaba Cloud accounts |
|
Before you begin
An Alibaba Cloud account is created and identity verification is complete. To create an Alibaba Cloud account, visit the Alibaba Cloud official website. For more information, see Create an Alibaba Cloud account.
Obtain an AccessKey pair to complete identity verification so that you can call ApsaraVideo VOD API operations. For more information about how to obtain an AccessKey pair, see Create an AccessKey pair.
NoteIf you use a RAM user to perform the migration, you must create the RAM user before you obtain the AccessKey pair. For more information, see Access ApsaraVideo VOD as a RAM user.
(Recommended) Upload resources in batches based on URLs
Scenarios
If the files that you want to migrate are not stored on local servers or devices but are publicly accessible over the Internet, you can use URL-based batch upload. This method lets you quickly upload many files over an internal network and reduces traffic usage.
Limits
URL-based batch upload is supported only in the China (Shanghai), China (Beijing), China (Shenzhen), Singapore, and US (Silicon Valley) regions. You must use other migration methods in other regions. For more information about endpoints, see ApsaraVideo VOD region IDs.
Usage notes
URL-based upload jobs are asynchronous. After you submit a job, the job may take hours or even days to complete. If you require high timeliness, use the upload SDK instead.
Each time you submit a URL-based upload job, ApsaraVideo VOD creates a new media resource with a new media ID.
Migration process
Procedure
Integrate the ApsaraVideo VOD server-side SDK.
This example uses the ApsaraVideo VOD SDK for Java. For more information about how to use the SDK in other programming languages, see Server-side SDK.
To download the SDK for Java, see Server-side SDK. To install the SDK for Java, see Installation.
Prepare the resources to migrate.
NotePrepare the download URLs for all files to migrate. If the URLs require signing, you must ensure that they remain valid during the download period.
The download URLs must be full paths that include file names and file name extensions, such as
https://****.mp4.
Call the UploadMediaByURL operation using the ApsaraVideo VOD server-side SDK to upload resources in batches.
The following example shows how to call the operation in Java. For examples in other programming languages, see UploadMediaByURL.
You can also perform online debugging using OpenAPI Explorer.
Retrieve the upload result.
Method 1: Use event notifications
ApsaraVideo VOD supports HTTP callbacks and MNS callbacks. After you configure event notifications, ApsaraVideo VOD sends a notification when media processing is complete, for example, when an upload or transcoding is finished. For more information about the configuration, see Event notifications.
The event type for URL-based batch upload is UploadByURLComplete. You can retrieve information such as the job status from the callback response.
Sample callback for a successful upload
{ "Status": "success", "EventTime": "2017-03-20T07:49:17Z", "EventType": "UploadByURLComplete", "VideoId": "43q9fjdun3f****", "JobId": "4c815bjs83j1****", "SourceURL ": "http://example.aliyundoc.com/27ffc438-164d55217ef-0005-6884-51a-1****.mp4", "Size":"123456" }Sample callback for a failed upload
{ "Status": "fail", "EventTime": "2017-03-20T07:49:17Z", "EventType": "UploadByURLComplete", "ErrorCode ": "URLInvalidError ", "ErrorMessage ": "download video failed by the url, please check it", "JobId": "4c815bjsued****" , "SourceURL ": "http://example.aliyundoc.com/27ffc438-164d55217ef-0005-6884-51a-1****.mp4", }
Method 2: Call an API operation
Call the GetURLUploadInfos operation to query the status of a URL-based upload job.
Upload resources using a self-built upload service
If URL-based batch upload is not supported in your service region or you require high upload timeliness, you can download the files and use the ApsaraVideo VOD upload SDK to upload them. If you deploy your upload service on an Elastic Compute Service (ECS) instance, you can choose to upload over an internal network or the Internet based on the region of the ECS instance.
Download and upload over the internal network
Scenarios
If your upload service runs on an ECS instance in the same region as the source video files, you can migrate OSS resources within or between Alibaba Cloud accounts, or ApsaraVideo VOD resources between Alibaba Cloud accounts over the internal network.
Migration process
Prerequisites
Your upload service runs on an ECS instance in the same region as the source video files.
Procedure
Prepare and save the internal network addresses of the OSS or ApsaraVideo VOD resources that you want to migrate.
NoteIf the resource URLs require signing, you must ensure that they remain valid during the download period.
Video-on-demand resources
Call the GetMezzanineInfo operation to retrieve the OSS addresses of the objects. Set the
OutputTypeparameter tooss.Add
-internalafter the OSS region to convert the OSS address to an internal network address.
OSS resources
You can list files to obtain a list of objects, from which you can retrieve and save the source address of a specific resource.
Add
-internalafter the OSS region to convert the OSS address to an internal network address.
The following examples show addresses before and after modification:
OSS Origin URL
Modified private 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 internal network addresses, see Access OSS resources from ECS instances using an internal endpoint of OSS.
Set up the upload service.
NoteDeploy the upload service on an ECS instance in the same region as the ApsaraVideo VOD OSS bucket. In the Chinese mainland, the default region for OSS buckets is China (Shanghai). After deployment, you must set the
regionIdparameter to this region. When you use the upload SDK, uploads automatically use the internal network.For sample code, see Set up an upload service. We recommend that you use the ApsaraVideo VOD upload SDK.
Run the upload code from Step 2 to upload videos to ApsaraVideo VOD.
Use the internal network addresses as file paths in the upload request.
Download and upload over the Internet
Scenarios
If you do not deploy the upload service on an ECS instance, or the ECS instance and source video files are in different regions, you can use the Internet to download and upload files.
Migration process
Procedure
Prepare and save the source file addresses of the resources that you want to migrate.
NoteIf the resource URLs require signing, you must ensure that they remain valid during the download period.
The source file addresses must be full paths that include file names and file name extensions, such as
https://****.mp4.
Video-on-demand resources
Call the SearchMedia operation to filter video IDs to migrate.
Call the GetMezzanineInfo operation to retrieve the source file addresses of all videos to migrate.
NoteThis example uses the GetMezzanineInfo operation to retrieve source file addresses. You can also retrieve them from the ApsaraVideo VOD console. For more information, see Export media assets.
If you want to use a transcoded stream as the source file, you can generate it using ApsaraVideo VOD. For more information, see Media asset management.
OSS resource
List the objects to migrate and retrieve their source file addresses. For more information, see List objects.
Third-party resources (data, such as videos, stored on personal websites or in the cloud)
Prepare and save the download URLs for all files to migrate.
Set up the upload service.
For sample code, see Set up an upload service. We recommend that you use the ApsaraVideo VOD upload SDK.
NoteTo track mappings between source file URLs and uploaded video IDs, you can record them in your upload program. For example, you can log them or write them to media asset metadata during the upload. Choose the method that fits your use case. If you use the UploadMediaByURL operation, the response includes the source file URLs. You can use this information as needed.
Run the upload code from Step 2 to upload videos to ApsaraVideo VOD.
Use the source file addresses directly in the upload request.
(Optional) Organize ApsaraVideo VOD resources.
After a successful migration, you can organize resources using the mappings between source file URLs and uploaded video IDs.
Add OSS buckets to ApsaraVideo VOD and register resources
Scenarios
If resources are stored in an OSS bucket under the same Alibaba Cloud account, you can add the bucket to ApsaraVideo VOD and register the resources. This method avoids the need to re-upload the resources.
Limits
Only OSS buckets with Standard storage class are supported.
Up to 10 OSS buckets can be added per region.
Procedure
Add the OSS bucket that contains the resources to migrate to ApsaraVideo VOD.
For step-by-step instructions and parameter descriptions, see Manage storage buckets.
Register the OSS resources with ApsaraVideo VOD by calling an API operation.
List all objects in the bucket using the OSS API or SDK. For more information, see List objects.
Call the RegisterMedia operation to register media files and generate media IDs. Set the
FileURLin theRegisterMetadatasparameter to the full path of the object, including the OSS domain name. For example:https://oss-cn-hangzhou.aliyuncs.com/video/example.mp4
Set up an upload service
To migrate third-party resources or resources between Alibaba Cloud accounts, you must download the original videos and upload them to ApsaraVideo VOD. ApsaraVideo VOD provides two upload tools: the upload SDK and the server-side API. You can implement your upload service using either tool. We recommend that you use the upload SDK because it performs synchronous uploads and is more efficient. Using the server-side API is complex and error-prone.
Steps to set up an upload service
Integrate the upload SDK or server-side SDK.
Choose the SDK based on your programming language. For more information about how to integrate the upload SDK, see Upload SDK overview. For more information about how to integrate the server-side SDK, see Server-side SDK.
Write the upload service code. See the following examples.
Upload SDK code sample (recommended)
The following example uses Java. For examples in other programming languages, see Upload SDK 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);
/* Specify custom callback settings for event notifications. For more information about the parameters, see Basic data types. */
//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 region. */
//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 video ID is empty, the upload fails. 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();
}
// The AccessKey pair of an Alibaba Cloud account has permissions to call all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M.
// We recommend that you do not include your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised.
// In this example, ApsaraVideo VOD reads the AccessKey pair from the environment variables to implement identity verification for API access. Before you run the sample code, configure the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET.
String accessKeyId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
String accessKeySecret = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
// 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 that includes a filename extension, such as video-1.mp4.
testUploadStream(accessKeyId, accessKeySecret, "<Your Video Title>", "<Your Video with File Extension>", inputStream);
}
}Server-side API code example (not recommended)
To set up an upload service using the server-side API, you must implement the entire upload logic yourself. This includes retrieving upload URLs and credentials from ApsaraVideo VOD, Base64-decoding the credentials and URLs, and using the OSS SDK to upload media files. This method is complex and error-prone. We recommend that you use the upload SDK instead. For the complete upload logic, see Upload media files by calling the ApsaraVideo VOD API.