Video tools
The short video Software Development Kit (SDK) provides tools to parse video files and retrieve video thumbnails for video editing and recording.
Supported editions
Edition | Supported |
|---|---|
Professional Edition | Support |
Standard Edition | Support |
Basic Edition | Support |
Video file parsing
The core class for video file parsing is NativeParser. This class parses video information such as width, height, format, duration, bitrate, and sound channels.
You can obtain information using keys. The keys are described below.
Key | Description |
|---|---|
VIDEO_STREAM_INDEX | The index of the video stream. |
VIDEO_CODEC | The video encoder. |
VIDEO_DURATION | The duration of the video stream. |
VIDEO_FRAME_COUNT | The total number of frames. |
VIDEO_BIT_RATE | The bitrate (average bitrate). |
VIDEO_WIDTH | The width. |
VIDEO_HEIGHT | The height. |
VIDEO_FORMAT | The video format. |
VIDEO_GOP | The Group of Pictures (GOP) interval. |
AUDIO_CODEC | The index of the audio stream. |
AUDIO_DURATION | The duration of the audio stream. |
AUDIO_CHANNELS | The number of audio channels. |
AUDIO_BIT_RATE | The bitrate of the audio stream. |
AUDIO_SAMPLE_RATE | The audio sampling rate. |
AUDIO_FORAMT | The audio format. |
// 1. Initialize.
NativeParser parser = new NativeParser();
// 2. Parse the video.
// Parse Video 1.
parser.init(path1);
// Obtain information using keys.
String videoWidth1 = parser.getValue(NativeParser.VIDEO_WIDTH);
// After parsing is complete, call release.
parser.release();
// Parse Video 2.
parser.init(path2);
// Obtain information using keys.
String videoWidth2 = parser.getValue(NativeParser.VIDEO_WIDTH);
// After parsing is complete, call release.
parser.release();
// 3. Destroy the instance.
parser.dispose();Video thumbnails
The core class for video thumbnails is AliyunIThumbnailFetcher. Use this class to display the thumbnail of each frame on the video track. This is often used during video editing or clipping.
// 1. Create an instance.
// AlivcSdkCore.register(getApplicationContext()); Before creating a thumbnail, confirm that the SDK is initialized.
AliyunIThumbnailFetcher fetcher = AliyunThumbnailFetcherFactory.createThumbnailFetcher();
// 2. Add a video or image source.
// Method 1: Add from a configuration file. This applies to project.json files generated by operations within the SDK.
fetcher.fromConfigJson(xxxx.json);
// Method 2: Add manually.
// Add a video.
fetcher.addVideoSource(path1, startTimeMills1, endTimeMills1, overlapDurationMills1);
// Add an image.
fetcher.addImageSource(path2, startTimeMills2, endTimeMills2, overlapDurationMills2);
// 3. Set the thumbnail output size and other information.
// cropMode
CropMode cropMode = CropMode.Mediate; // Image clipping mode.
VideoDisplayMode videoDisplayMode = VideoDisplayMode.Scale; // Image padding mode.
int cacheSize = 10; // Number of cached thumbnails.
fetcher.setParameters(width, height, cropMode, videoDisplayMode, cacheSize);
// For a series of thumbnails, set fastMode to true for faster generation. For a single thumbnail or a thumbnail at a precise time, set fastMode to false.
fetcher.setFastMode(true);
// 4. The final thumbnail is returned in the callback.
long[] times = {1000, 2000, 3000}; // Thumbnail timestamps.
fetcher.requestThumbnailImage(times, new AliyunIThumbnailFetcher.OnThumbnailCompletion() {
@Override
public void onThumbnailReady(Bitmap frameBitmap, long time, int index) {
// The returned thumbnail.
}
@Override
public void onError(int errorCode) {
// Error code information.
}
});
// Alternatively, use requestThumbnailImage(count, callback) to request a specific number of thumbnails that are evenly distributed over time.
fetcher.requestThumbnailImage(10, new AliyunIThumbnailFetcher.OnThumbnailCompletion() {
@Override
public void onThumbnailReady(Bitmap frameBitmap, long time, int index) {
// The time parameter is a timestamp that corresponds to a value in the previously passed times array. The index parameter is the array index of the input time slice.
}
@Override
public void onError(int errorCode) {
}
});
// 5. Destroy the instance after use.
fetcher.release();Use the setFastMode() method to specify the thumbnail retrieval mode. If you pass true, fast mode is enabled. In this mode, the nearest preceding keyframe to the requested time slice is used, which allows for fast thumbnail retrieval. If you pass false, precise mode is enabled. This mode precisely locates the specific frame at the requested time slice. For example, to retrieve 10 thumbnails from a 30 second 1080p video, it takes about 1 second in fast mode and about 5 seconds in precise mode.