AVMuxer
Overview
The AVMuxer module provides the functions for audio and video muxing.
System capability: SystemCapability.Multimedia.Media.Muxer
Since: 10
Summary
Files
Name | Description |
---|---|
native_avmuxer.h | Declares the native APIs used for audio and video muxing. |
Types
Name | Description |
---|---|
typedef struct OH_AVMuxer OH_AVMuxer | Defines a struct that describes a native object for the muxer interface. |
Functions
Name | Description |
---|---|
OH_AVMuxer * OH_AVMuxer_Create (int32_t fd, OH_AVOutputFormat format) | Creates an OH_AVMuxer instance by using the file descriptor and encapsulation format. |
OH_AVErrCode OH_AVMuxer_SetRotation (OH_AVMuxer *muxer, int32_t rotation) | Sets the rotation angle (clockwise) of an output video. |
OH_AVErrCode OH_AVMuxer_AddTrack (OH_AVMuxer *muxer, int32_t *trackIndex, OH_AVFormat *trackFormat) | Adds a media track to the muxer. |
OH_AVErrCode OH_AVMuxer_Start (OH_AVMuxer *muxer) | Starts the muxer. |
OH_AVErrCode OH_AVMuxer_WriteSample (OH_AVMuxer *muxer, uint32_t trackIndex, OH_AVMemory *sample, OH_AVCodecBufferAttr info) | Writes data to the muxer. |
OH_AVErrCode OH_AVMuxer_WriteSampleBuffer (OH_AVMuxer *muxer, uint32_t trackIndex, const OH_AVBuffer *sample) | Writes data to the muxer. |
OH_AVErrCode OH_AVMuxer_Stop (OH_AVMuxer *muxer) | Stops the muxer. |
OH_AVErrCode OH_AVMuxer_Destroy (OH_AVMuxer *muxer) | Clears internal resources and destroys an OH_AVMuxer instance. |
Type Description
OH_AVMuxer
typedef struct OH_AVMuxer OH_AVMuxer
Description
Defines a struct that describes a native object for the muxer interface.
Since: 10
Function Description
OH_AVMuxer_AddTrack()
OH_AVErrCode OH_AVMuxer_AddTrack (OH_AVMuxer *muxer, int32_t *trackIndex, OH_AVFormat *trackFormat)
Description
Adds a media track to the muxer.
This function must be called before OH_AVMuxer_Start.
System capability: SystemCapability.Multimedia.Media.Muxer
Since: 10
Parameters
Name | Description |
---|---|
muxer | Pointer to an OH_AVMuxer instance. |
trackIndex | Pointer to the index of the media track. The index will be used in the OH_AVMuxer_WriteSample function. If the media track is added, the index value is greater than or equal to 0; otherwise, the value is less than 0. |
trackFormat | Pointer to an OH_AVFormat instance. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
OH_AVMuxer_Create()
OH_AVMuxer* OH_AVMuxer_Create (int32_t fd, OH_AVOutputFormat format)
Description
Creates an OH_AVMuxer instance by using the file descriptor and encapsulation format.
System capability: SystemCapability.Multimedia.Media.Muxer
Since: 10
Parameters
Name | Description |
---|---|
fd | File descriptor (FD). You must open the file in read/write mode (O_RDWR) and close the file after using it. |
format | Format of the encapsulated output file. For details, see OH_AVOutputFormat. |
Returns
Returns the pointer to the OH_AVMuxer instance created. You must call OH_AVMuxer_Destroy to destroy the instance when it is no longer needed.
OH_AVMuxer_Destroy()
OH_AVErrCode OH_AVMuxer_Destroy (OH_AVMuxer *muxer)
Description
Clears internal resources and destroys an OH_AVMuxer instance.
System capability: SystemCapability.Multimedia.Media.Muxer
Since: 10
Parameters
Name | Description |
---|---|
muxer | Pointer to an OH_AVMuxer instance. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise. You must set the muxer to null.
OH_AVMuxer_SetRotation()
OH_AVErrCode OH_AVMuxer_SetRotation (OH_AVMuxer *muxer, int32_t rotation)
Description
Sets the rotation angle (clockwise) of an output video.
This function must be called before OH_AVMuxer_Start.
System capability: SystemCapability.Multimedia.Media.Muxer
Since: 10
Parameters
Name | Description |
---|---|
muxer | Pointer to an OH_AVMuxer instance. |
rotation | Angle to set. The value must be 0, 90, 180, or 270. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
OH_AVMuxer_Start()
OH_AVErrCode OH_AVMuxer_Start (OH_AVMuxer *muxer)
Description
Starts the muxer.
This function must be called after OH_AVMuxer_AddTrack and before OH_AVMuxer_WriteSample.
System capability: SystemCapability.Multimedia.Media.Muxer
Since: 10
Parameters
Name | Description |
---|---|
muxer | Pointer to an OH_AVMuxer instance. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
OH_AVMuxer_Stop()
OH_AVErrCode OH_AVMuxer_Stop (OH_AVMuxer *muxer)
Description
Stops the muxer.
Once the muxer is stopped, it cannot be restarted.
System capability: SystemCapability.Multimedia.Media.Muxer
Since: 10
Parameters
Name | Description |
---|---|
muxer | Pointer to an OH_AVMuxer instance. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
OH_AVMuxer_WriteSample()
OH_AVErrCode OH_AVMuxer_WriteSample (OH_AVMuxer *muxer, uint32_t trackIndex, OH_AVMemory *sample, OH_AVCodecBufferAttr info)
Description
Writes data to the muxer.
This function must be called after OH_AVMuxer_Start and before OH_AVMuxer_Stop. You must ensure that the data is written to the correct media track in ascending order by time.
System capability: SystemCapability.Multimedia.Media.Muxer
Since: 10
Deprecated from: 11
Substitute API: OH_AVMuxer_WriteSampleBuffer
Parameters
Name | Description |
---|---|
muxer | Pointer to an OH_AVMuxer instance. |
trackIndex | Index of the media track corresponding to the data. |
sample | Pointer to the buffer that stores the data written (data obtained after encoding or demuxing). |
info | Information about the data written. For details, see OH_AVCodecBufferAttr. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
OH_AVMuxer_WriteSampleBuffer()
OH_AVErrCode OH_AVMuxer_WriteSampleBuffer (OH_AVMuxer *muxer, uint32_t trackIndex, const OH_AVBuffer *sample)
Description
Writes data to the muxer.
This function must be called after OH_AVMuxer_Start and before OH_AVMuxer_Stop. You must ensure that the data is written to the correct media track in ascending order by time.
System capability: SystemCapability.Multimedia.Media.Muxer
Since: 11
Parameters
Name | Description |
---|---|
muxer | Pointer to an OH_AVMuxer instance. |
trackIndex | Index of the media track corresponding to the data. |
sample | Pointer to the buffer that stores the data written (data obtained after encoding or demuxing). Contains data and data attributes. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.