openharmony 鸿蒙 capi-native-avmuxer-h

2026-08-25 浏览 (1)

native_avmuxer.h

Overview

The file declares the native APIs used for audio and video multiplexing.

File to include: <multimedia/player_framework/native_avmuxer.h>

Library: libnative_media_avmuxer.so

System capability: SystemCapability.Multimedia.Media.Muxer

Since: 10

Related module: AVMuxer

Sample: AVCodec

Summary

Structs

Nametypedef KeywordDescription
OH_AVMuxerOH_AVMuxerDescribes a native object for the muxer interface.

Functions

NameDescription
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. This function must be called before OH_AVMuxer_Start.
OH_AVErrCode OH_AVMuxer_SetFormat(OH_AVMuxer *muxer, OH_AVFormat *format)Sets format data to the muxer.
Starting from API version 14, setting the creation time via OH_MD_KEY_CREATION_TIME is supported. 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.
Starting from API version 20, the following operations are supported:
- Setting the file description via OH_MD_KEY_COMMENT. If the setting fails, check whether OH_MD_KEY_COMMENT is a string within the range [1, 256].
- Setting the position of the MP4 moov via OH_MD_KEY_ENABLE_MOOV_FRONT. If OH_MD_KEY_ENABLE_MOOV_FRONT is set to 0, moov is placed at the end. If it is set to 1, moov is placed at the front. By default, moov is placed at the end.
OH_AVErrCode OH_AVMuxer_AddTrack(OH_AVMuxer *muxer, int32_t *trackIndex, OH_AVFormat *trackFormat)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.
OH_AVErrCode OH_AVMuxer_Start(OH_AVMuxer *muxer)Starts a muxer. This function must be called after OH_AVMuxer_AddTrack and before OH_AVMuxer_WriteSample.
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 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.
OH_AVErrCode OH_AVMuxer_WriteSampleBuffer(OH_AVMuxer *muxer, uint32_t trackIndex, const OH_AVBuffer *sample)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.
OH_AVErrCode OH_AVMuxer_Stop(OH_AVMuxer *muxer)Stops a muxer. Once the muxer is stopped, it cannot be restarted.
OH_AVErrCode OH_AVMuxer_Destroy(OH_AVMuxer *muxer)Clears internal resources and destroys an OH_AVMuxer instance.
Do not repeatedly destroy the instance. Otherwise, the program may crash.

Function Description

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

NameDescription
int32_t fdFile descriptor (FD). You must open the file in read/write mode (O_RDWR) and close the file after using it.
OH_AVOutputFormat formatFormat of the multiplexed output file.

Returns

TypeDescription
OH_AVMuxer *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_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

NameDescription
OH_AVMuxer *muxerPointer to an OH_AVMuxer instance.
int32_t rotationAngle to set. The value must be 0, 90, 180, or 270.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The muxer pointer is null or the value of rotation is invalid.
AV_ERR_OPERATE_NOT_PERMIT: 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.

Starting from API version 14, setting the creation time via OH_MD_KEY_CREATION_TIME is supported. 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.

Starting from API version 20, the following operations are supported:

  • Setting the file description via OH_MD_KEY_COMMENT. If the setting fails, check whether OH_MD_KEY_COMMENT is a string within the range [1, 256].
  • Setting the position of the MP4 moov via OH_MD_KEY_ENABLE_MOOV_FRONT. If OH_MD_KEY_ENABLE_MOOV_FRONT is set to 0, moov is placed at the end. If it is set to 1, moov is placed at the front. By default, moov is placed at the end.

System capability: SystemCapability.Multimedia.Media.Muxer

Since: 14

Parameters

NameDescription
OH_AVMuxer *muxerPointer to an OH_AVMuxer instance.
OH_AVFormat *formatPointer to an OH_AVFormat instance. It is a file-level metadata set.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The format parameter is correctly set.
AV_ERR_INVALID_VAL: The muxer pointer is null or the value of format is invalid.
AV_ERR_OPERATE_NOT_PERMIT: The function is called out of sequence.

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

NameDescription
OH_AVMuxer *muxerPointer to an OH_AVMuxer instance.
int32_t *trackIndexPointer 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.
OH_AVFormat *trackFormatPointer to an OH_AVFormat instance.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The muxer pointer is null, or the track index or track format is invalid.
AV_ERR_OPERATE_NOT_PERMIT: The function is called out of sequence.
AV_ERR_UNSUPPORT: The MIME type is not supported.
AV_ERR_NO_MEMORY: Memory allocation fails.
AV_ERR_UNKNOWN: An unknown error occurs.

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

NameDescription
OH_AVMuxer *muxerPointer to an OH_AVMuxer instance.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The muxer pointer is null.
AV_ERR_OPERATE_NOT_PERMIT: The function is called out of sequence.
AV_ERR_UNKNOWN: An unknown error occurs.

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: OH_AVMuxer_WriteSampleBuffer

Parameters

NameDescription
OH_AVMuxer *muxerPointer to an OH_AVMuxer instance.
uint32_t trackIndexIndex of the audio or video track corresponding to the data.
OH_AVMemory *samplePointer to the data obtained after encoding or demultiplexing.
OH_AVCodecBufferAttr infoSample description.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The muxer pointer is null, or the track index, sample, or info is invalid.
AV_ERR_OPERATE_NOT_PERMIT: The function is called out of sequence.
AV_ERR_NO_MEMORY: Memory allocation fails.
AV_ERR_UNKNOWN: An unknown error occurs.

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

NameDescription
OH_AVMuxer *muxerPointer to an OH_AVMuxer instance.
uint32_t trackIndexIndex of the audio or video track corresponding to the data.
const OH_AVBuffer *samplePointer to the data and properties obtained after encoding or demultiplexing.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The muxer pointer is null, or the track index or sample is invalid.
AV_ERR_OPERATE_NOT_PERMIT: The function is called out of sequence.
AV_ERR_NO_MEMORY: Memory allocation fails.
AV_ERR_UNKNOWN: An unknown error occurs.

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

NameDescription
OH_AVMuxer *muxerPointer to an OH_AVMuxer instance.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The muxer pointer is null.
AV_ERR_OPERATE_NOT_PERMIT: The function is called out of sequence.

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

NameDescription
OH_AVMuxer *muxerPointer to an OH_AVMuxer instance.

Returns

TypeDescription
OH_AVErrCodeAV_ERR_OK: The operation is successful.
AV_ERR_INVALID_VAL: The muxer pointer is null.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-native-avcodec-audiocodec-h

openharmony 鸿蒙 capi-avsource-oh-avsource

openharmony 鸿蒙 capi-native-cencinfo-h

openharmony 鸿蒙 capi-avmuxer

openharmony 鸿蒙 capi-multimedia-drm-oh-avcencinfo

openharmony 鸿蒙 capi-native-avdemuxer-h

openharmony 鸿蒙 capi-media-types-h

openharmony 鸿蒙 capi-native-audio-channel-layout-h

openharmony 鸿蒙 capi-native-avbuffer-info-h

openharmony 鸿蒙 capi-codecbase-oh-avcodecasynccallback

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/2aczsoel