Video tools

更新时间:
复制 MD 格式

The short video SDK for iOS provides video file parsing and thumbnail generation tools to help you edit and record videos more efficiently.

Supported editions

Edition

Supported

Professional

Yes

Standard

Yes

Basic

Yes

Related classes

Class

Description

AliyunNativeParser

Parses video, audio, and file information.

AliyunThumbnailParser

Configures thumbnail parameters such as cropping scope, output size, and start and cancel timing.

Parse video files

Use the AliyunNativeParser 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 AliyunThumbnailParser or AliyunNativeParser class. Use these thumbnails to display each frame on the video track when editing or cropping videos.

  • 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 asynchronously. Do not release the AliyunNativeParser instance during this process.

  • 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 {
}