You can implement video decoding by constructing an instance of the VideoDecoder class. For details about the decoding configuration items and restrictions, see VideoDecodeConfig.
Video decoding supports customized output data formats. You can use a customized callback function to input the decoding configuration items to use the decoded data. For details, see VencCallBacker.
For details about video decoding APIs, see VideoDecoder.
Define the output data combination mode as required, refer to VdecCallBacker to define the callback function, and input decoding configuration items. Instantiate the VideoDecoder class, and call the member function of decode to complete decoding and obtain data.
The following figure shows the process of calling APIs of video decoding.

Vision SDK provides the VideoDecoder class for video decoding. The key steps are described as follows:
For details about the configuration items and restrictions, see the data structure description of VideoDecodeConfig.
Input the configured VideoDecodeConfig to the constructor API to instantiate the video decoding class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | import os import numpy as np import time from mindx.sdk import base from mindx.sdk.base import Image, ImageProcessor from mindx.sdk.base import VideoDecoder, VideoDecodeConfig, VdecCallBacker decoded_data_list = [] # Video decoding callback function def vdec_callback(decodedImage, channelId, frameId): # Save the decoded Image class to the list. decoded_data_list.append(decodedImage) def process(): # Initialize the VdecCallBacker class and register the callback function. vdecCallBacker = VdecCallBacker() vdecCallBacker.registerVdecCallBack(vdec_callback) # Initialize the VideoDecodeConfig class and set parameters. vdecConfig = VideoDecodeConfig() vdecConfig.skipInterval = 0 vdecConfig.inputVideoFormat = base.h264_main_level vdecConfig.outputImageFormat = base.nv12 vdecConfig.width = 1920 vdecConfig.height = 1080 # Initialize the VideoDecoder. videoDecoder = VideoDecoder(vdecConfig, vdecCallBacker, device_id, channel_id) # Obtain the name of the video frame file to be decoded. srcDataList = ["frame-{}.data".format(i) for i in range(100)] # Obtain frames repeatedly for decoding. for i, fileName in enumerate(srcDataList): # Read the video frame data and save it to the file. file = np.fromfile(fileName, dtype='uint8') # Decode video frame data. videoDecoder.decode(file, i) if __name__ == "__main__": base.mx_init() # Initialize resources. process() base.mx_deinit() # Deinitialize resources. |