aboutsummaryrefslogtreecommitdiff
path: root/include/mp4v2/track.h
blob: 6e39e5a12241429263ccb85f4f97fc3ca6b737e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
#ifndef MP4V2_TRACK_H
#define MP4V2_TRACK_H

/**************************************************************************//**
 *
 *  @defgroup mp4_track MP4v2 Track
 *  @{
 *
 *****************************************************************************/

/** Add a user defined track.
 *
 *  MP4AddTrack adds a user defined track to the mp4 file. Care should be
 *  taken to avoid any of the standardized track type names. A useful
 *  convention is use only uppercase characters for user defined track types.
 *  The string should be exactly four characters in length, e.g. "MINE".
 *
 *  Note this should not be used to add any of the known track types defined
 *  in the MP4 standard (ISO/IEC 14496−1:2001).
 *
 *  @param hFile handle of file for operation.
 *  @param type specifies the type of track to be added.
 *
 *  @return On success, the track-id of new track.
 *      On failure, #MP4_INVALID_TRACK_ID.
 */
MP4V2_EXPORT
MP4TrackId MP4AddTrack(
    MP4FileHandle hFile,
    const char*   type );

/** Add an MPEG−4 systems track.
 *
 *  MP4AddSystemsTrack adds an MPEG−4 Systems track to the mp4 file. Note
 *  this should not be used to add OD or scene tracks, MP4AddODTrack() and
 *  MP4AddSceneTrack() should be used for those purposes. Other known
 *  MPEG−4 System track types are:
 *      @li #MP4_CLOCK_TRACK_TYPE
 *      @li #MP4_MPEG7_TRACK_TYPE
 *      @li #MP4_OCI_TRACK_TYPE
 *      @li #MP4_IPMP_TRACK_TYPE
 *      @li #MP4_MPEGJ_TRACK_TYPE
 *
 *  @param hFile handle of file for operation.
 *  @param type specifies the type of track to be added.
 *
 *  @return On success, the track-id of new track.
 *      On failure, #MP4_INVALID_TRACK_ID.
 */
MP4V2_EXPORT
MP4TrackId MP4AddSystemsTrack(
    MP4FileHandle hFile,
    const char*   type );

/** Add a object descriptor (OD) track.
 *
 *  MP4AddODTrack adds an object descriptor (aka OD) track to the mp4 file.
 *  MP4WriteSample() can then be used to add the desired OD commands to the
 *  track. The burden is currently on the calling application to understand
 *  OD.
 *
 *  Those wishing to have a simple audio/video scene without understanding
 *  OD may wish to use MP4MakeIsmaCompliant() to create the minimal OD and
 *  BIFS information.
 *
 *  @param hFile handle of file for operation.
 * 
 *  @return On success, the track-id of new track.
 *      On failure, #MP4_INVALID_TRACK_ID.
 */
MP4V2_EXPORT
MP4TrackId MP4AddODTrack(
    MP4FileHandle hFile );

/** Add a scene (BIFS) track.
 *
 *  MP4AddSceneTrack adds a scene (aka BIFS) track to the mp4 file.
 *  MP4WriteSample() can then be used to add the desired BIFS commands to
 *  the track. The burden is currently on the calling application to
 *  understand BIFS.
 *
 *  Those  wishing to have a simple audio/video scene without understanding
 *  BIFS may wish to use MP4MakeIsmaCompliant() to create the minimal OD
 *  and BIFS information.
 *
 *  @param hFile handle of file for operation.
 * 
 *  @return On success, the track-id of new track.
 *      On failure, #MP4_INVALID_TRACK_ID.
 */
MP4V2_EXPORT
MP4TrackId MP4AddSceneTrack(
    MP4FileHandle hFile );

/** Add audio track to mp4 file.
 *
 *  MP4AddAudioTrack adds an audio track to the mp4 file. MP4WriteSample()
 *  can then be used to add the desired audio samples.
 *
 *  It is recommended that the time scale be set to the sampling frequency
 *  (eg. 44100 Hz) of the audio so as to preserve the timing information
 *  accurately.
 *
 *  If the audio encoding uses a fixed duration for each sample that should
 *  be specified here. If not then the value #MP4_INVALID_DURATION
 *  should be given for the sampleDuration argument.
 *
 *  @param hFile handle of file for operation.
 *  @param timeScale the time scale in ticks per second of the track.
 *  @param sampleDuration the fixed  duration for all track samples.
 *      Caveat: the value should be in track-timescale units.
 *  @param audioType the audio encoding type.
 *      See MP4GetTrackEsdsObjectTypeId() for known values.
 *
 *  @return On success, the track-id of the new track.
 *      On error, #MP4_INVALID_TRACK_ID.
 */
MP4V2_EXPORT
MP4TrackId MP4AddAudioTrack(
    MP4FileHandle hFile,
    uint32_t      timeScale,
    MP4Duration   sampleDuration,
    uint8_t       audioType DEFAULT(MP4_MPEG4_AUDIO_TYPE) );

MP4V2_EXPORT
MP4TrackId MP4AddAC3AudioTrack(
    MP4FileHandle hFile,
    uint32_t      samplingRate,
    uint8_t       fscod,
    uint8_t       bsid,
    uint8_t       bsmod,
    uint8_t       acmod,
    uint8_t       lfeon,
    uint8_t       bit_rate_code );

MP4V2_EXPORT
MP4TrackId MP4AddAmrAudioTrack(
    MP4FileHandle hFile,
    uint32_t      timeScale,
    uint16_t      modeSet,
    uint8_t       modeChangePeriod,
    uint8_t       framesPerSample,
    bool          isAmrWB );

MP4V2_EXPORT
void MP4SetAmrVendor(
    MP4FileHandle hFile,
    MP4TrackId    trackId,
    uint32_t      vendor );

MP4V2_EXPORT
void MP4SetAmrDecoderVersion(
    MP4FileHandle hFile,
    MP4TrackId    trackId,
    uint8_t       decoderVersion );

MP4V2_EXPORT
void MP4SetAmrModeSet(
    MP4FileHandle hFile,
    MP4TrackId    trakId,
    uint16_t      modeSet );

MP4V2_EXPORT
uint16_t MP4GetAmrModeSet(
    MP4FileHandle hFile,
    MP4TrackId    trackId );

MP4V2_EXPORT
MP4TrackId MP4AddHrefTrack(
    MP4FileHandle hFile,
    uint32_t      timeScale,
    MP4Duration   sampleDuration,
    const char*   base_url DEFAULT(NULL) );

MP4V2_EXPORT
const char* MP4GetHrefTrackBaseUrl(
    MP4FileHandle hFile,
    MP4TrackId    trackId );

/** Add a video track.
 *
 *  MP4AddVideoTrack adds a video track to the mp4 file. MP4WriteSample()
 *  can then be used to add the desired video samples.
 *
 *  It is recommended that the time scale be set to 90000 so as to preserve
 *  the timing information accurately for the range of video frame rates
 *  commonly in use.
 *
 *  If the video frame rate is to be fixed then the sampleDuration argument
 *  should be give the appropriate fixed value. If the video frame rate is
 *  to be variable then the value #MP4_INVALID_DURATION should be
 *  given for the sampleDuration argument.
 *
 *  @param hFile handle of file for operation.
 *  @param timeScale the timescale in ticks per second of the track.
 *  @param sampleDuration specifies fixed sample duration for all track
 *      samples. Caveat: the value should be in track timescale units.
 *  @param width specifies the video frame width in pixels.
 *  @param height specifies the video frame height in pixels.
 *  @param videoType specifies the video encoding type.
 *      See MP4GetTrackVideoType() for known values.
 *
 *  @return On success, the track-id of the new track.
 *      On error, #MP4_INVALID_TRACK_ID.
 */
MP4V2_EXPORT
MP4TrackId MP4AddVideoTrack(
    MP4FileHandle hFile,
    uint32_t      timeScale,
    MP4Duration   sampleDuration,
    uint16_t      width,
    uint16_t      height,
    uint8_t       videoType DEFAULT(MP4_MPEG4_VIDEO_TYPE) );

MP4V2_EXPORT
MP4TrackId MP4AddH264VideoTrack(
    MP4FileHandle hFile,
    uint32_t      timeScale,
    MP4Duration   sampleDuration,
    uint16_t      width,
    uint16_t      height,
    uint8_t       AVCProfileIndication,
    uint8_t       profile_compat,
    uint8_t       AVCLevelIndication,
    uint8_t       sampleLenFieldSizeMinusOne );

MP4V2_EXPORT
void MP4AddH264SequenceParameterSet(
    MP4FileHandle  hFile,
    MP4TrackId     trackId,
    const uint8_t* pSequence,
    uint16_t       sequenceLen );

MP4V2_EXPORT
void MP4AddH264PictureParameterSet(
    MP4FileHandle  hFile,
    MP4TrackId     trackId,
    const uint8_t* pPict,
    uint16_t       pictLen );

MP4V2_EXPORT
void MP4SetH263Vendor(
    MP4FileHandle hFile,
    MP4TrackId    trackId,
    uint32_t      vendor );

MP4V2_EXPORT
void MP4SetH263DecoderVersion(
    MP4FileHandle hFile,
    MP4TrackId    trackId,
    uint8_t       decoderVersion );

MP4V2_EXPORT
void MP4SetH263Bitrates(
    MP4FileHandle hFile,
    MP4TrackId    trackId,
    uint32_t      avgBitrate,
    uint32_t      maxBitrate );

MP4V2_EXPORT
MP4TrackId MP4AddH263VideoTrack(
    MP4FileHandle hFile,
    uint32_t      timeScale,
    MP4Duration   sampleDuration,
    uint16_t      width,
    uint16_t      height,
    uint8_t       h263Level,
    uint8_t       h263Profile,
    uint32_t      avgBitrate,
    uint32_t      maxBitrate );

/** Add a hint track.
 *
 *  MP4AddHintTrack adds a hint track to the mp4 file. A hint track is used
 *  to describe how to send the reference media track over a particular
 *  network transport. In the case of the IETF RTP protocol, the hint track
 *  describes how the media data should be placed into packets and any
 *  media specific protocol headers that should be added.
 *
 *  Typically there is a one to one correspondence between reference  media
 *  track  samples  and  hint track samples. The start time, duration, and
 *  sync flags are typically the same, however provisions are made for
 *  deviations from this rule.
 *
 *  The MP4 library provides extensive support for RTP hint tracks. This
 *  includes a easy to use API to create RTP hint tracks, and read out
 *  fully constructed RTP packets based on the hint track.
 *
 *  @param hFile handle of file for operation.
 *  @param refTrackId specifies the reference media track for this hint track.
 *
 *  @return On success, the track-id of the new track.
 *      On error, #MP4_INVALID_TRACK_ID.
 */
MP4V2_EXPORT
MP4TrackId MP4AddHintTrack(
    MP4FileHandle hFile,
    MP4TrackId    refTrackId );

MP4V2_EXPORT
MP4TrackId MP4AddTextTrack(
    MP4FileHandle hFile,
    MP4TrackId    refTrackId );

MP4V2_EXPORT
MP4TrackId MP4AddSubtitleTrack(
    MP4FileHandle hFile,
    uint32_t      timescale,
    uint16_t      width,
    uint16_t      height );

MP4V2_EXPORT
MP4TrackId MP4AddPixelAspectRatio(
    MP4FileHandle hFile,
    MP4TrackId    refTrackId,
    uint32_t      hSpacing,
    uint32_t      vSpacing );

MP4V2_EXPORT
MP4TrackId MP4AddColr(
    MP4FileHandle hFile,
    MP4TrackId    refTrackId,
    uint16_t      primary,
    uint16_t      transfer,
    uint16_t      matrix );

MP4V2_EXPORT
MP4TrackId MP4CloneTrack(
    MP4FileHandle srcFile,
    MP4TrackId    srcTrackId,
    MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE),
    MP4TrackId    dstHintTrackReferenceTrack DEFAULT(MP4_INVALID_TRACK_ID) );

MP4V2_EXPORT
MP4TrackId MP4CopyTrack(
    MP4FileHandle srcFile,
    MP4TrackId    srcTrackId,
    MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE),
    bool          applyEdits DEFAULT(false),
    MP4TrackId    dstHintTrackReferenceTrack DEFAULT(MP4_INVALID_TRACK_ID) );

MP4V2_EXPORT
void MP4DeleteTrack(
    MP4FileHandle hFile,
    MP4TrackId    trackId );

MP4V2_EXPORT
uint32_t MP4GetNumberOfTracks(
    MP4FileHandle hFile,
    const char*   type DEFAULT(NULL),
    uint8_t       subType DEFAULT(0) );

MP4V2_EXPORT
MP4TrackId MP4FindTrackId(
    MP4FileHandle hFile,
    uint16_t      index,
    const char*   type DEFAULT(NULL),
    uint8_t       subType DEFAULT(0) );

MP4V2_EXPORT
uint16_t MP4FindTrackIndex(
    MP4FileHandle hFile,
    MP4TrackId    trackId );

/** Get maximum duration of chunk.
 *
 *  MP4GetTrackDurationPerChunk gets the maximum duration for each chunk.
 *
 *  @param hFile handle of file for operation.
 *  @param trackId id of track for operation.
 *  @param duration out value of duration in track timescale units.
 *
 *  return <b>true</b> on success, <b>false</b> on failure.
 */
MP4V2_EXPORT
bool MP4GetTrackDurationPerChunk(
    MP4FileHandle hFile,
    MP4TrackId    trackId,
    MP4Duration*  duration );

/** Set maximum duration of chunk.
 *
 *  MP4SetTrackDurationPerChunk sets the maximum duration for each chunk.
 *
 *  @param hFile handle of file for operation.
 *  @param trackId id of track for operation.
 *  @param duration in timescale units.
 *
 *  return <b>true</b> on success, <b>false</b> on failure.
 */
MP4V2_EXPORT
bool MP4SetTrackDurationPerChunk(
    MP4FileHandle hFile,
    MP4TrackId    trackId,
    MP4Duration   duration );

MP4V2_EXPORT
void MP4AddIPodUUID(
    MP4FileHandle hFile,
    MP4TrackId    trackId );

/** @} ***********************************************************************/

#endif /* MP4V2_TRACK_H */