• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# AVMuxer
2
3
4## Overview
5
6The **AVMuxer** module provides functions for audio and video encapsulation.
7
8\@syscap SystemCapability.Multimedia.Media.Muxer
9
10**Since**
11
1210
13
14
15## Summary
16
17
18### Files
19
20| Name| Description|
21| -------- | -------- |
22| [native_avmuxer.h](native__avmuxer_8h.md) | Declares native APIs used for audio and video encapsulation.<br>**File to include**: <multimedia/player_framework/native_avmuxer.h><br>**Library**: libnative_media_avmuxer.so|
23
24
25### Functions
26
27| Name| Description|
28| -------- | -------- |
29| \*[OH_AVMuxer_Create](#oh_avmuxer_create) (int32_t fd, OH_AVOutputFormat format) | Creates an **OH_AVMuxer** instance by using the file descriptor and encapsulation format.|
30| [OH_AVMuxer_SetRotation](#oh_avmuxer_setrotation) (OH_AVMuxer \*muxer, int32_t rotation) | Sets the rotation angle (clockwise) of an output video.|
31| [OH_AVMuxer_AddTrack](#oh_avmuxer_addtrack) (OH_AVMuxer \*muxer, int32_t \*trackIndex, OH_AVFormat \*trackFormat) | Adds a media track to the muxer.|
32| [OH_AVMuxer_Start](#oh_avmuxer_start) (OH_AVMuxer \*muxer) | Starts encapsulation.|
33| [OH_AVMuxer_WriteSample](#oh_avmuxer_writesample) (OH_AVMuxer \*muxer, uint32_t trackIndex, OH_AVMemory \*sample, OH_AVCodecBufferAttr info) | Writes data to the muxer.|
34| [OH_AVMuxer_Stop](#oh_avmuxer_stop) (OH_AVMuxer \*muxer) | Stops encapsulation.|
35| [OH_AVMuxer_Destroy](#oh_avmuxer_destroy) (OH_AVMuxer \*muxer) | Clears internal resources and destroys an **OH_AVMuxer** instance.|
36
37
38## Function Description
39
40
41### OH_AVMuxer_AddTrack()
42
43
44```
45OH_AVErrCode OH_AVMuxer_AddTrack (OH_AVMuxer *muxer, int32_t *trackIndex, OH_AVFormat *trackFormat)
46```
47
48**Description**
49
50Adds a media track to the muxer.
51
52This function must be called before **OH_AVMuxer_Start**.
53
54\@syscap SystemCapability.Multimedia.Media.Muxer
55
56**Parameters**
57
58  | Name| Description|
59| -------- | -------- |
60| muxer | Pointer to an **OH_AVMuxer** instance.|
61| 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.|
62| trackFormat | Pointer to an **OH_AVFormat** instance.|
63
64**Returns**
65
66Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode-1) otherwise.
67
68**Since**
69
7010
71
72
73### OH_AVMuxer_Create()
74
75
76```
77OH_AVMuxer* OH_AVMuxer_Create (int32_t fd, OH_AVOutputFormat format)
78```
79
80**Description**
81
82Creates an **OH_AVMuxer** instance by using the file descriptor and encapsulation format.
83
84\@syscap SystemCapability.Multimedia.Media.Muxer
85
86**Parameters**
87
88  | Name| Description|
89| -------- | -------- |
90| fd | File descriptor (FD). You must open the file in read/write mode (O_RDWR) and close the file after using it.|
91| format | Format of the encapsulated output file. For details, see [OH_AVOutputFormat](_codec_base.md#oh_avoutputformat).|
92
93**Returns**
94
95Returns the pointer to the **OH_AVMuxer** instance created. You must call **OH_AVMuxer_Destroy** to destroy the instance when it is no longer needed.
96
97**Since**
98
9910
100
101
102### OH_AVMuxer_Destroy()
103
104
105```
106OH_AVErrCode OH_AVMuxer_Destroy (OH_AVMuxer *muxer)
107```
108
109**Description**
110
111Clears internal resources and destroys an **OH_AVMuxer** instance.
112
113\@syscap SystemCapability.Multimedia.Media.Muxer
114
115**Parameters**
116
117  | Name| Description|
118| -------- | -------- |
119| muxer | Pointer to an **OH_AVMuxer** instance.|
120
121**Returns**
122
123Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode-1) otherwise. You must set the muxer to null.
124
125**Since**
126
12710
128
129
130### OH_AVMuxer_SetRotation()
131
132
133```
134OH_AVErrCode OH_AVMuxer_SetRotation (OH_AVMuxer *muxer, int32_t rotation)
135```
136
137**Description**
138
139Sets the rotation angle (clockwise) of an output video.
140
141This function must be called before **OH_AVMuxer_Start**.
142
143\@syscap SystemCapability.Multimedia.Media.Muxer
144
145**Parameters**
146
147  | Name| Description|
148| -------- | -------- |
149| muxer | Pointer to an **OH_AVMuxer** instance.|
150| rotation | Angle to set. The value must be 0, 90, 180, or 270.|
151
152**Returns**
153
154Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode-1) otherwise.
155
156**Since**
157
15810
159
160
161### OH_AVMuxer_Start()
162
163
164```
165OH_AVErrCode OH_AVMuxer_Start (OH_AVMuxer *muxer)
166```
167
168**Description**
169
170Starts encapsulation.
171
172This function must be called after **OH_AVMuxer_AddTrack** and before **OH_AVMuxer_WriteSample**.
173
174\@syscap SystemCapability.Multimedia.Media.Muxer
175
176**Parameters**
177
178  | Name| Description|
179| -------- | -------- |
180| muxer | Pointer to an **OH_AVMuxer** instance.|
181
182**Returns**
183
184Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode-1) otherwise.
185
186**Since**
187
18810
189
190
191### OH_AVMuxer_Stop()
192
193
194```
195OH_AVErrCode OH_AVMuxer_Stop (OH_AVMuxer *muxer)
196```
197
198**Description**
199
200Stops encapsulation.
201
202Once encapsulation is stopped, it cannot be restarted.
203
204\@syscap SystemCapability.Multimedia.Media.Muxer
205
206**Parameters**
207
208  | Name| Description|
209| -------- | -------- |
210| muxer | Pointer to an **OH_AVMuxer** instance.|
211
212**Returns**
213
214Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode-1) otherwise.
215
216**Since**
217
21810
219
220
221### OH_AVMuxer_WriteSample()
222
223
224```
225OH_AVErrCode OH_AVMuxer_WriteSample (OH_AVMuxer *muxer, uint32_t trackIndex, OH_AVMemory *sample, OH_AVCodecBufferAttr info)
226```
227
228**Description**
229
230Writes data to the muxer.
231
232This 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.
233
234\@syscap SystemCapability.Multimedia.Media.Muxer
235
236**Parameters**
237
238  | Name| Description|
239| -------- | -------- |
240| muxer | Pointer to an **OH_AVMuxer** instance.|
241| trackIndex | Index of the media track corresponding to the data.|
242| sample | Pointer to the buffer that stores the data written (data obtained after encoding or decapsulation).|
243| info | Information about the data written. For details, see [OH_AVCodecBufferAttr](_o_h___a_v_codec_buffer_attr.md).|
244
245**Returns**
246
247Returns **AV_ERR_OK** if the operation is successful; returns an error code defined in [OH_AVErrCode](_core.md#oh_averrcode-1) otherwise.
248
249**Since**
250
25110
252