harmony 鸿蒙VideoEncoder

  • 2023-06-24
  • 浏览 (665)

VideoEncoder

Overview

The VideoEncoder module provides the functions for video encoding.

\@syscap SystemCapability.Multimedia.Avcodec.VideoEncoder

Since

9

Summary

Files

Name Description
native_avcodec_videoencoder.h Declares the native APIs used for video encoding.
File to include:
Library: libnative_media_venc.so

Types

Name Description
OH_VideoEncodeBitrateMode Defines an enum that enumerates the bit rate modes of a video encoder.

Enums

Name Description
OH_VideoEncodeBitrateMode {
    CBR = 0,
    VBR = 1,
    CQ = 2
}
Enumerates the bit rate modes of a video encoder.

Functions

Name Description
*OH_VideoEncoder_CreateByMime (const char *mime) Creates a video encoder instance based on a Multipurpose Internet Mail Extension (MIME) type. This function is recommended in most cases.
*OH_VideoEncoder_CreateByName (const char *name) Creates a video encoder instance based on an encoder name. To use this function, you must know the exact name of the encoder.
OH_VideoEncoder_Destroy (OH_AVCodec *codec) Clears the internal resources of a video encoder and destroys the encoder instance.
OH_VideoEncoder_SetCallback (OH_AVCodec *codec, OH_AVCodecAsyncCallback callback, void *userData) Sets an asynchronous callback so that your application can respond to events generated by a video encoder.
OH_VideoEncoder_Configure (OH_AVCodec *codec, OH_AVFormat *format) Configures a video encoder. Typically, you need to configure the description information about the video track to be encoded.
OH_VideoEncoder_Prepare (OH_AVCodec *codec) Prepares internal resources for a video encoder. This function must be called after Configure.
OH_VideoEncoder_Start (OH_AVCodec *codec) Starts a video encoder. This function can be called only after the encoder is prepared successfully.
OH_VideoEncoder_Stop (OH_AVCodec *codec) Stops a video encoder.
OH_VideoEncoder_Flush (OH_AVCodec *codec) Clears the input and output data in the internal buffer of a video encoder.
OH_VideoEncoder_Reset (OH_AVCodec *codec) Resets a video encoder.
*OH_VideoEncoder_GetOutputDescription (OH_AVCodec *codec) Obtains the description information about the output data of a video encoder. For details, see OH_AVFormat .
OH_VideoEncoder_SetParameter (OH_AVCodec *codec, OH_AVFormat *format) Sets dynamic parameters for a video encoder.
OH_VideoEncoder_GetSurface (OH_AVCodec *codec, OHNativeWindow **window) Sets an input surface for a video encoder. This function must be called prior to Prepare.
OH_VideoEncoder_FreeOutputData (OH_AVCodec *codec, uint32_t index) Frees an output buffer of a video encoder.
OH_VideoEncoder_NotifyEndOfStream (OH_AVCodec *codec) Notifies a video encoder that input streams end. You are advised to use this function for notification.
OH_VideoEncoder_PushInputData (OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr) Pushes the input buffer filled with data to a video encoder.
*OH_VideoEncoder_GetInputDescription (OH_AVCodec *codec) Obtains the description information received by the video encoder. This function must be called after Configure. For details, see OH_AVFormat.
OH_VideoEncoder_IsValid (OH_AVCodec *codec, bool *isValid) Checks whether a video encoder instance is valid.

Type Description

OH_VideoEncodeBitrateMode

typedef enum OH_VideoEncodeBitrateMode OH_VideoEncodeBitrateMode

Description

Defines the bit rate mode of a video encoder.

\@syscap SystemCapability.Multimedia.Media.VideoEncoder

Since

9

Enum Description

OH_VideoEncodeBitrateMode

enum OH_VideoEncodeBitrateMode

Description

Enumerates the bit rate modes of a video encoder.

\@syscap SystemCapability.Multimedia.Media.VideoEncoder

Since

9

Value Description
CBR Constant bit rate.
VBR Variable bit rate.
CQ Constant quality.

Function Description

OH_VideoEncoder_Configure()

OH_AVErrCode OH_VideoEncoder_Configure (OH_AVCodec *codec, OH_AVFormat *format)

Description

Configures a video encoder. Typically, you need to configure the description information about the video track to be encoded.

This function must be called prior to Prepare.

\@syscap SystemCapability.Multimedia.Media.VideoEncoder

Parameters

Name Description
codec Pointer to an OH_AVCodec instance.
format Pointer to an OH_AVFormat instance, which provides the description information about the video track to be encoded.

Returns

Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.

Since

9

OH_VideoEncoder_CreateByMime()

OH_AVCodec* OH_VideoEncoder_CreateByMime (const char *mime)

Description

Creates a video encoder instance based on a MIME type. This function is recommended in most cases.

\@syscap SystemCapability.Multimedia.Media.VideoEncoder

Parameters

Name Description
mime Pointer to a string that describes the MIME type. For details, see AVCODEC_MIMETYPE.

Returns

Returns the pointer to the OH_AVCodec instance created. You must call OH_VideoEncoder_Destroy to destroy the instance when it is no longer needed.

Since

9

OH_VideoEncoder_CreateByName()

OH_AVCodec* OH_VideoEncoder_CreateByName (const char *name)

Description

Creates a video encoder instance based on an encoder name. To use this function, you must know the exact name of the encoder.

\@syscap SystemCapability.Multimedia.Media.VideoEncoder

Parameters

Name Description
name Pointer to a video encoder name.

Returns

Returns the pointer to an OH_AVCodec instance.

Since

9

OH_VideoEncoder_Destroy()

OH_AVErrCode OH_VideoEncoder_Destroy (OH_AVCodec *codec)

Description

Clears the internal resources of a video encoder and destroys the encoder instance.

\@syscap SystemCapability.Multimedia.Media.VideoEncoder

Parameters

Name Description
codec Pointer to an OH_AVCodec instance.

Returns

Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.

Since

9

OH_VideoEncoder_Flush()

OH_AVErrCode OH_VideoEncoder_Flush (OH_AVCodec *codec)

Description

Clears the input and output data in the internal buffer of a video encoder.

This function invalidates the indexes of all buffers previously reported through the asynchronous callback. Therefore, before calling this function, ensure that the buffers with the specified indexes are no longer required.

\@syscap SystemCapability.Multimedia.Media.VideoEncoder

Parameters

Name Description
codec Pointer to an OH_AVCodec instance.

Returns

Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.

Since

9

OH_VideoEncoder_FreeOutputData()

OH_AVErrCode OH_VideoEncoder_FreeOutputData (OH_AVCodec *codec, uint32_t index)

Description

Frees an output buffer of a video encoder.

\@syscap SystemCapability.Multimedia.Media.VideoEncoder

Parameters

Name Description
codec Pointer to an OH_AVCodec instance.
index Index of the output buffer.

Returns

Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.

Since

9

OH_VideoEncoder_GetInputDescription()

OH_AVFormat* OH_VideoEncoder_GetInputDescription (OH_AVCodec *codec)

Description

Obtains the description information received by the video encoder. This function must be called after Configure. For details, see OH_AVFormat.

The caller must manually release the OH_AVFormat instance in the return value.

\@syscap SystemCapability.Multimedia.Media.VideoEncoder

Parameters

Name Description
codec Pointer to an OH_AVCodec instance.

Returns

Returns the pointer to an OH_AVFormat instance.

Since

10

OH_VideoEncoder_GetOutputDescription()

OH_AVFormat* OH_VideoEncoder_GetOutputDescription (OH_AVCodec *codec)

Description

Obtains the description information about the output data of a video encoder. For details, see OH_AVFormat.

The caller must manually release the OH_AVFormat instance in the return value.

\@syscap SystemCapability.Multimedia.Media.VideoEncoder

Parameters

Name Description
codec Pointer to an OH_AVCodec instance.

Returns

Returns the pointer to an OH_AVFormat instance.

Since

9

OH_VideoEncoder_GetSurface()

OH_AVErrCode OH_VideoEncoder_GetSurface (OH_AVCodec *codec, OHNativeWindow **window)

Description

Sets an input surface for a video encoder. This function must be called prior to Prepare.

The application manages the lifecycle of the window and calls OH_NativeWindow_DestroyNativeWindow() to release the window when the lifecycle ends.

\@syscap SystemCapability.Multimedia.Media.VideoEncoder

Parameters

Name Description
codec Pointer to an OH_AVCodec instance.
window Pointer to an OHNativeWindow instance. For details, see OHNativeWindow.

Returns

Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.

Since

9

OH_VideoEncoder_IsValid()

OH_AVErrCode OH_VideoEncoder_IsValid (OH_AVCodec *codec, bool *isValid)

Description

Checks whether a video encoder instance is valid.

\@syscap SystemCapability.Multimedia.Media.VideoEncoder

Parameters

Name Description
codec Pointer to an OH_AVCodec instance.
isValid Pointer to an instance of the Boolean type. The value true means that the encoder instance is valid and false means the opposite.

Returns

Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.

Since

10

OH_VideoEncoder_NotifyEndOfStream()

OH_AVErrCode OH_VideoEncoder_NotifyEndOfStream (OH_AVCodec *codec)

Description

Notifies a video encoder that input streams end. You are advised to use this function for notification.

This function is recommended in surface mode.

\@syscap SystemCapability.Multimedia.Media.VideoEncoder

Parameters

Name Description
codec Pointer to an OH_AVCodec instance.

Returns

Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.

Since

9

OH_VideoEncoder_Prepare()

OH_AVErrCode OH_VideoEncoder_Prepare (OH_AVCodec *codec)

Description

Prepares internal resources for a video encoder. This function must be called after Configure.

\@syscap SystemCapability.Multimedia.Media.VideoEncoder

Parameters

Name Description
codec Pointer to an OH_AVCodec instance.

Returns

Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.

Since

9

OH_VideoEncoder_PushInputData()

OH_AVErrCode OH_VideoEncoder_PushInputData (OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr)

Description

Pushes the input buffer filled with data to a video encoder.

\@syscap SystemCapability.Multimedia.Media.VideoEncoder

Parameters

Name Description
codec Pointer to an OH_AVCodec instance.
index Index of the input buffer.
attr Description of the data contained in the buffer.

Returns

Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.

Since

10

OH_VideoEncoder_Reset()

OH_AVErrCode OH_VideoEncoder_Reset (OH_AVCodec *codec)

Description

Resets a video encoder. To continue encoding, you must call Configure to configure the encoder again.

\@syscap SystemCapability.Multimedia.Media.VideoEncoder

Parameters

Name Description
codec Pointer to an OH_AVCodec instance.

Returns

Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.

Since

9

OH_VideoEncoder_SetCallback()

OH_AVErrCode OH_VideoEncoder_SetCallback (OH_AVCodec *codec, OH_AVCodecAsyncCallback callback, void *userData)

Description

Sets an asynchronous callback so that your application can respond to events generated by a video encoder.

This function must be called prior to Prepare.

\@syscap SystemCapability.Multimedia.Media.VideoEncoder

Parameters

Name Description
codec Pointer to an OH_AVCodec instance.
callback Callback function to set. For details, see OH_AVCodecAsyncCallback.
userData User-specific data.

Returns

Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.

Since

9

OH_VideoEncoder_SetParameter()

OH_AVErrCode OH_VideoEncoder_SetParameter (OH_AVCodec *codec, OH_AVFormat *format)

Description

Sets dynamic parameters for a video encoder.

This function can be called only after the encoder is started. Incorrect parameter settings may cause encoding failure.

\@syscap SystemCapability.Multimedia.Media.VideoEncoder

Parameters

Name Description
codec Pointer to an OH_AVCodec instance.
format Handle to an OH_AVFormat instance.

Returns

Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.

Since

9

OH_VideoEncoder_Start()

OH_AVErrCode OH_VideoEncoder_Start (OH_AVCodec *codec)

Description

Starts a video encoder. This function can be called only after the encoder is prepared successfully.

After being started, the encoder starts to report the NeedInputData event.

\@syscap SystemCapability.Multimedia.Media.VideoEncoder

Parameters

Name Description
codec Pointer to an OH_AVCodec instance.

Returns

Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.

Since

9

OH_VideoEncoder_Stop()

OH_AVErrCode OH_VideoEncoder_Stop (OH_AVCodec *codec)

Description

Stops a video encoder. After the encoder is stopped, you can call Start to start it again.

\@syscap SystemCapability.Multimedia.Media.VideoEncoder

Parameters

Name Description
codec Pointer to an OH_AVCodec instance.

Returns

Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.

Since

9

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Native APIs

harmony 鸿蒙AVCapability

harmony 鸿蒙AVDemuxer

harmony 鸿蒙AVMuxer

harmony 鸿蒙AVScreenCapture

harmony 鸿蒙AVSource

harmony 鸿蒙AudioDecoder

harmony 鸿蒙AudioEncoder

harmony 鸿蒙CodecBase

harmony 鸿蒙Core

0  赞