Upload and media processing

更新时间:
复制 MD 格式

VodAppServer provides upload and media processing capabilities backed by the ApsaraVideo VOD upload SDK.

Upload feature

VodAppServer supports uploading audio files, video files, images, and auxiliary media assets using the ApsaraVideo VOD upload SDK.

Audio and video upload

Four upload methods are available for audio and video files:

  • Local files: Supports multipart upload and resumable upload. Use this method for large files.

  • Network streams: Upload files using a URL. Resumable upload is supported.

  • File streams: Upload local files. Resumable upload is not supported.

  • Streaming: Supports file stream and network stream inputs.

The following example uploads a local audio or video file:

UploadVideoRequest request = new UploadVideoRequest(accessKeyId, accessKeySecret, title, fileName);
/* Specify the size of each part for multipart upload. The default size is 2 MB. */
request.setPartSize(2 * 1024 * 1024L);
/* Specify the number of concurrent threads for multipart upload. The default value is 1. */
request.setTaskNum(1);
/* Specifies whether to enable resumable upload. */
request.setEnableCheckpoint(true);

UploadVideoImpl uploader = new UploadVideoImpl();
UploadVideoResponse response = uploader.uploadVideo(request);

if (response.isSuccess()) {
    System.out.print("VideoId=" + response.getVideoId() + "\n");
} else {
    System.out.print("ErrorCode=" + response.getCode() + "\n");
    System.out.print("ErrorMessage=" + response.getMessage() + "\n");
}

Image and auxiliary media asset upload

Two upload methods are available for images and auxiliary media assets:

  • Local files: Resumable upload is not supported.

  • Streaming: Supports file stream and network stream inputs.

The following example uploads a local image:

// The image type. This parameter is required. Valid values: default, cover, and watermark.
String imageType = "cover";
UploadImageRequest request = new UploadImageRequest(accessKeyId, accessKeySecret, imageType);
request.setImageType("cover");
// The image title. This parameter is optional.
request.setTitle("Short Drama Thumbnail");
// The path of the local file.
String fileName = "/Users/test/image/cover.png";
request.setFileName(fileName);

UploadImageImpl uploadImage = new UploadImageImpl();
UploadImageResponse response = uploadImage.upload(request);

if (response.isSuccess()) {
    System.out.print("ImageId=" + response.getImageId() + "\n");
    System.out.print("ImageURL=" + response.getImageURL() + "\n");
} else {
    System.out.print("ErrorCode=" + response.getCode() + "\n");
    System.out.print("ErrorMessage=" + response.getMessage() + "\n");
}

M3U8 file upload

Two upload methods are available for M3U8 files:

  • Local files: Specify the M3U8 manifest and all segment files.

  • Network files: Specify the URL of the M3U8 manifest and the URLs of the segment files.

Upload using Security Token Service

To upload files using Security Token Service (STS), implement the onRefreshSTSToken method of the VoDRefreshSTSTokenListener interface. This method refreshes STS credentials when an upload times out.

Upload progress callback

The upload SDK supports two types of progress callbacks:

  • Default callback: Enabled by default in the SDK.

  • Custom callback: Implement a custom event handler as needed.

Internal network upload optimization

Specify the ECS region for the upload. If the ECS region matches the ApsaraVideo VOD storage region, internal network upload is automatically enabled, which accelerates transmission and reduces Internet traffic costs.

Media processing

VodAppServer integrates with ApsaraVideo Media Processing (MPS) and supports transcoding, snapshots, and watermarks.

Media transcoding

Call SubmitTranscodeJobs to submit a transcoding job and specify a transcoding template group.

The following example submits a transcoding job:

@RestController
public class MpsController {
    @Autowired
    private VodSdkService vodSdkService;
    
    /**
     * Submits a transcoding job.
     *
     * @param videoId         The ID of the video to transcode.
     * @param templateGroupId The ID of the transcoding template group to use.
     * @return The result of the transcoding job submission.
     */
    @RequestMapping(value = "/submitTranscodeJob", method = {RequestMethod.GET, RequestMethod.POST})
    public SubmitTranscodeJobsResponse submitTranscodeJob(
            @RequestParam("videoId") String videoId, 
            @RequestParam("templateGroupId") String templateGroupId) {
        return vodSdkService.SubmitTranscodeJobs(videoId, templateGroupId);
    }
}
Note

For more information about how to create a transcoding template group and obtain its ID, see Transcoding template groups.

ApsaraVideo MPS also supports video snapshots, media review, video AI, and image and text watermarks. It also supports batch processing of media assets.