All Products
Search
Document Center

ApsaraVideo VOD:Video tools

Last Updated:Apr 19, 2022

The short video SDK for iOS provides tools to parse video files and obtain video thumbnails so that you can edit and record videos in a more convenient manner.

Supported editions

Edition

Supported

Professional

Yes

Standard

Yes

Basic

Yes

Related classes

Class

Description

AliyunNativeParser

A core class that is used to parse information about the video, audio, and file.

AliyunThumbnailParser

A core class that is used to configure thumbnail parameters, such as the cropping scope, output size, and parameters that specify when to start and cancel capturing thumbnails.

Parse video files

The core class that is used to parse video files is AliyunNativeParser. You can use this class to obtain the following information:

  • Video: video stream encoding format, width and height, start time, duration, bitrate, frame rate, keyframe interval, total number of frames, format, and rotation angle.

  • Audio: audio stream encoding format, start time, duration, total number of frames, sample rate, number of audio tracks, bitrate, and audio format.

  • File: file name, start time, duration, and file format.

//1. Initialize the class.
AliyunNativeParser *parser = [[AliyunNativeParser alloc] initWithPath:videoPath];

// 2. Obtain video information.
// Obtain video information by calling API operations.
NSInteger videoWidth = [parser getVideoWidth];
NSInteger videoHeight = [parser getVideoHeight];

// Obtain video information by using keys.
float videoDuration = [parser getValueForKey:ALIYUN_VIDEO_DURATION].floatValue;
NSInteger videoBitrate = [parser getValueForKey:ALIYUN_VIDEO_BIT_RATE].integerValue;

Obtain video thumbnails

You can obtain thumbnails by using the core class AliyunThumbnailParser or the AliyunNativeParser class. These classes allow you to display the thumbnail of each frame on the video track. In most cases, you need to use these thumbnails when you edit or crop the video.

  • Use the AliyunNativeParser class

    //1. Initialize the class. 
    self.parser = [[AliyunNativeParser alloc] initWithPath:videoPath];
    
    // 2. Obtain thumbnails.
    // Call the API operation that allows you to obtain thumbnails based on time intervals.
    [self.parser loadThumbnailListWithDuration:1.0 imageWidth:100 complete:^(int errorCode, NSArray<UIImage *> *imageList) {
     }];
     
    // Call the API operation that allows you to obtain thumbnails based on time arrays.
    NSArray<NSNumber *> *timeList = @[@0,@1.0,@2.5,@6];
     [self.parser loadThumbnailWithTimeList: timeList imageWidth:100 complete:^(int errorCode, NSArray<UIImage *> *imageList) {
     }];
    Note

    Thumbnails are obtained in an asynchronous manner. During the process, ensure that the AliyunNativeParser instance is not released.

  • Use the AliyunThumbnailParser class

//1. Initialize the class.
self.parser = [[AliyunThumbnailParser alloc]initWithPath:self.videoPath delegate:self];

//2. Configure image parameters.
// Specify the image cropping scope.
[self.parser setCutFrame:CGRectMake(0, 0, 200, 200)];

// Specify the image output size.
CGFloat ouputSizeWidth = 200;
[self.parser setOutputSize:CGSizeMake(ouputSizeWidth, ouputSizeWidth)];

//3. Specify the points in time at which thumbnails are obtained.
NSArray<NSNumber *> *timeList = @[@0,@1.0,@2.5,@6];
[self.parser addThumbnailTimeList:timeList]; 

//4. Start obtaining thumbnails.
[self.parser start];

//5. Perform callbacks.
// An error occurs when you obtain thumbnails. Perform the callback in the sub-thread.
- (void)thumbnailParser:(AliyunThumbnailParser *)parser onError:(int)code {
}

// An error occurs when you obtain an image. Perform the callback in the sub-thread.
- (void)thumbnailParser:(AliyunThumbnailParser *)parser onPicError:(int)code time:(float)time {
}

// An image is obtained. Perform the callback in the sub-thread.
- (void)thumbnailParser:(AliyunThumbnailParser *)parser onGetPicture:(UIImage *)image time:(float)time {
}

// All images are obtained. Perform the callback in the sub-thread.
- (void)thumbnailParserOnCompleted:(AliyunThumbnailParser *)parser {
}