harmony 鸿蒙AVMuxer
AVMuxer
Overview
The AVMuxer module provides the APIs for audio and video multiplexing.
For details about the development guide and sample, see Media Data Multiplexing.
System capability: SystemCapability.Multimedia.Media.Muxer
Since: 10
Summary
Files
Name | Description |
---|---|
native_avmuxer.h | Declares the native APIs used for audio and video multiplexing. |
Types
Name | Description |
---|---|
typedef struct OH_AVMuxer OH_AVMuxer | Defines a struct for the 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 container format. |
OH_AVErrCode OH_AVMuxer_SetRotation (OH_AVMuxer *muxer, int32_t rotation) | Sets the rotation angle (clockwise), which must be 0, 90, 180, or 270, of an output video. |
OH_AVErrCode OH_AVMuxer_SetFormat (OH_AVMuxer *muxer, OH_AVFormat *format) | Sets format data to the muxer. |
OH_AVErrCode OH_AVMuxer_AddTrack (OH_AVMuxer *muxer, int32_t *trackIndex, OH_AVFormat *trackFormat) | Adds an audio or video track to a muxer. |
OH_AVErrCode OH_AVMuxer_Start (OH_AVMuxer *muxer) | Starts a muxer. |
OH_AVErrCode OH_AVMuxer_WriteSample (OH_AVMuxer *muxer, uint32_t trackIndex, OH_AVMemory *sample, OH_AVCodecBufferAttr info) | Writes a sample to a muxer. (This function is deprecated from API version 11.) |
OH_AVErrCode OH_AVMuxer_WriteSampleBuffer (OH_AVMuxer *muxer, uint32_t trackIndex, const OH_AVBuffer *sample) | Writes a sample to a muxer. |
OH_AVErrCode OH_AVMuxer_Stop (OH_AVMuxer *muxer) | Stops a 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 for the 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 an audio or video track to a muxer.
Each time this function is called, an audio or video track is added 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 audio or video 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.
Returns AV_ERR_INVALID_VAL if the muxer pointer is null, or the track index or track format is invalid.
Returns AV_ERR_OPERATE_NOT_PERMIT if the function is called out of sequence.
Returns AV_ERR_UNSUPPORT if the MIME type is not supported. Returns AV_ERR_NO_MEMORY if memory allocation fails.
Returns AV_ERR_UNKNOWN in the case of an unknown error.
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 container 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 multiplexed output file. For details, see OH_AVOutputFormat. |
Returns
Returns the pointer to the OH_AVMuxer instance created. After the multiplexing process is complete, call OH_AVMuxer_Destroy to destroy the instance.
OH_AVMuxer_Destroy()
OH_AVErrCode OH_AVMuxer_Destroy (OH_AVMuxer *muxer)
Description
Clears internal resources and destroys an OH_AVMuxer instance.
Do not repeatedly destroy the instance. Otherwise, the program may crash.
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.
- Returns AV_ERR_INVALID_VAL if the muxer pointer is null.
OH_AVMuxer_SetRotation()
OH_AVErrCode OH_AVMuxer_SetRotation (OH_AVMuxer *muxer, int32_t rotation)
Description
Sets the rotation angle (clockwise), which must be 0, 90, 180, or 270, 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.
Returns AV_ERR_INVALID_VAL if the muxer pointer is null or the value of rotation is invalid.
Returns AV_ERR_OPERATE_NOT_PERMIT if the function is called out of sequence.
OH_AVMuxer_SetFormat()
OH_AVErrCode OH_AVMuxer_SetFormat(OH_AVMuxer *muxer, OH_AVFormat *format)
Description
Sets format data to the muxer.
Currently, only OH_MD_KEY_CREATION_TIME can be set.
If the setting fails, check whether the value of OH_MD_KEY_CREATION_TIME complies with the ISO 8601 standard and whether the UTC time is used.
System capability: SystemCapability.Multimedia.Media.Muxer
Since: 14
Parameters
Name | Description |
---|---|
muxer | Pointer to an OH_AVMuxer instance. |
format | Pointer to an OH_AVFormat instance. It is a file-level metadata set. |
Returns
Returns AV_ERR_OK if the format parameter is correctly set.
Returns AV_ERR_INVALID_VAL if the muxer pointer is null or the value of format is invalid.
Returns AV_ERR_OPERATE_NOT_PERMIT if the function is called out of sequence.
OH_AVMuxer_Start()
OH_AVErrCode OH_AVMuxer_Start (OH_AVMuxer *muxer)
Description
Starts a 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.
Returns AV_ERR_INVALID_VAL if the muxer pointer is null.
Returns AV_ERR_OPERATE_NOT_PERMIT if the function is called out of sequence.
Returns AV_ERR_UNKNOWN in the case of an unknown error.
OH_AVMuxer_Stop()
OH_AVErrCode OH_AVMuxer_Stop (OH_AVMuxer *muxer)
Description
Stops a 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.
Returns AV_ERR_INVALID_VAL if the muxer pointer is null.
Returns AV_ERR_OPERATE_NOT_PERMIT if the function is called out of sequence.
OH_AVMuxer_WriteSample()
OH_AVErrCode OH_AVMuxer_WriteSample (OH_AVMuxer *muxer, uint32_t trackIndex, OH_AVMemory *sample, OH_AVCodecBufferAttr info)
Description
Writes a sample to a muxer.
This function must be called after OH_AVMuxer_Start and before OH_AVMuxer_Stop. The caller must write the sample to the correct audio or video track based on the timing in info.
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 audio or video track corresponding to the data. |
sample | Pointer to the data obtained after encoding or demultiplexing. |
info | Sample description. For details, see OH_AVCodecBufferAttr. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
Returns AV_ERR_INVALID_VAL if the muxer pointer is null, or the track index, sample, or info is invalid.
Returns AV_ERR_OPERATE_NOT_PERMIT if the function is called out of sequence.
Returns AV_ERR_NO_MEMORY if memory allocation fails. Returns AV_ERR_UNKNOWN in the case of an unknown error.
OH_AVMuxer_WriteSampleBuffer()
OH_AVErrCode OH_AVMuxer_WriteSampleBuffer (OH_AVMuxer *muxer, uint32_t trackIndex, const OH_AVBuffer *sample)
Description
Writes a sample to a muxer.
This function must be called after OH_AVMuxer_Start and before OH_AVMuxer_Stop. The caller must write the sample to the correct audio or video track based on the timing in sample.
System capability: SystemCapability.Multimedia.Media.Muxer
Since: 11
Parameters
Name | Description |
---|---|
muxer | Pointer to an OH_AVMuxer instance. |
trackIndex | Index of the audio or video track corresponding to the data. |
sample | Pointer to the data and properties obtained after encoding or demultiplexing. |
Returns
Returns AV_ERR_OK if the operation is successful; returns an error code defined in OH_AVErrCode otherwise.
Returns AV_ERR_INVALID_VAL if the muxer pointer is null, or the track index or sample is invalid.
Returns AV_ERR_OPERATE_NOT_PERMIT if the function is called out of sequence.
Returns AV_ERR_NO_MEMORY if memory allocation fails. Returns AV_ERR_UNKNOWN in the case of an unknown error.
你可能感兴趣的鸿蒙文章
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦