Skip to main content

Video Decoding Tutorial

1. Overview

To decode video streams using the AUTEL SDK, you can either customize AutelCodecView or use the listener of the SDK video decoding service. This tutorial aims to help you learn how to implement video decoding using the above two methods. We can customize AutelCodecView to directly show the video data transmitted in real time by the aircraft camera or obtain decoded data by using the data listener APIs provided by the video decoding service.

2. Specific Implementation

2.1 Customize AutelCodecView to Display Videos Captured by the Aircraft Camera in Real Time

2.1.1 Import the Customized AutelCodecView

Add the following lines of code to the layout file:

<com.autel.sdk.widget.AutelCodecView 

android:layout_width="match_parent"

android:layout_height="match_parent" />

Alternatively, you can instantiate an object through AutelCodecView.

AutelCodecView autelCodeView = new AutelCodecView(CodecActivity.this);

2.1.2 Description of AutelCodecView APIs

/**
* Starts decoding
*
* @param texture: texture to be rendered
*
* @param surfaceWidth: the texture width
*
* @param surfaceHeight: the texture height
*
* @param useOpenGL: indicates whether to use openGL for rendering
*/
void startDecode(SurfaceTexture texture,int surfaceWidth,int surfaceHeight,boolean useOpenGL);

/**
*
* Pauses the rendering
*/
void pause();

/**
* Resumes the rendering
*/
void resume();

/**
* Listens for the rendering frame callback event
*
* @param listener object for listening for rendering frame information
*/
void setOnRenderFrameInfoListener(OnRenderFrameInfoListener listener);

/**
*
* Configures to whether enable overexposure or background overexposure
*
* @param enable: indicates whether to enable overexposure
*
* @param resId: the ID of the resource loaded when overexposure is enabled
*/
void setOverExposure(boolean enable,int resId);

/**
*
* Configures to change the width and height of the screen to be rendered
*
* @param surfaceWidht: the width
*
* @param surfaceHeight: the height
*/
void surfaceSizeChanged(int surfaceWidth,int surfaceHeight);

/**
*
* Stops decoding
*/
void stopCodec();

2.1.3 OnRenderFrameInfoListener Method

/**
* PTS callback of the current rendering frame
* @param pts: PTS value returned by the callback function
*/
void onRenderFrameTimestamp(long pts);

/**
* Callback of the width and height of the current rendering frame
* @param width: returns the width of the current video
* @param height: returns the height of the current video
*/
void onRenderFrameSizeChanged(int width,int height);

2.2 Listen for Video Streams Through the AutelCodec API

2.2.1 Generate the AutelCodec Object

Obtain the object directly through the getCodec method in the BaseProduct class

BaseProduct product;

...

AutelCodec codec = product.getCodec();

2.2.2 AutelCodec API

/**
* Configures to listen for decoding result
* @param listener object for listening for decoding result
* @param handler
*/
void setCodecListener(AutelCodecListener listener,Handler handler);

/**
* Cancels decoding
*/
void cancel();

2.2.3 AutelCodecListener API

/**
* Callback for returning the video stream data
* @param videoBuffer: video streams
* @param isIFrame: indicates whether it is key frame
* @param size: video stream size
* @param pts: PTS value of the current video frame
*/
void onFrameStream(byte[] videoBuffer,boolean isIFrame,int size,long pts);

/**
* Callback for returning the result after the current video decoding method is canceled
*/
void onCanceled();