12typedef void* MP4FileHandle;
13typedef uint32_t MP4TrackId;
14typedef uint32_t MP4SampleId;
15typedef uint64_t MP4Timestamp;
16typedef uint64_t MP4Duration;
17typedef uint32_t MP4EditId;
32typedef void (*MP4LogCallback)(
44typedef uint32_t (*
encryptFunc_t)( uint32_t, uint32_t, uint8_t*, uint32_t*, uint8_t** );
48#define MP4_INVALID_FILE_HANDLE ((MP4FileHandle)NULL)
49#define MP4_INVALID_TRACK_ID ((MP4TrackId)0)
50#define MP4_INVALID_SAMPLE_ID ((MP4SampleId)0)
51#define MP4_INVALID_TIMESTAMP ((MP4Timestamp)-1)
52#define MP4_INVALID_DURATION ((MP4Duration)-1)
53#define MP4_INVALID_EDIT_ID ((MP4EditId)0)
56#define MP4_IS_VALID_FILE_HANDLE(x) ((x) != MP4_INVALID_FILE_HANDLE)
57#define MP4_IS_VALID_TRACK_ID(x) ((x) != MP4_INVALID_TRACK_ID)
58#define MP4_IS_VALID_SAMPLE_ID(x) ((x) != MP4_INVALID_SAMPLE_ID)
59#define MP4_IS_VALID_TIMESTAMP(x) ((x) != MP4_INVALID_TIMESTAMP)
60#define MP4_IS_VALID_DURATION(x) ((x) != MP4_INVALID_DURATION)
61#define MP4_IS_VALID_EDIT_ID(x) ((x) != MP4_INVALID_EDIT_ID)
69#define MP4_OD_TRACK_TYPE "odsm"
70#define MP4_SCENE_TRACK_TYPE "sdsm"
71#define MP4_AUDIO_TRACK_TYPE "soun"
72#define MP4_VIDEO_TRACK_TYPE "vide"
73#define MP4_HINT_TRACK_TYPE "hint"
74#define MP4_CNTL_TRACK_TYPE "cntl"
75#define MP4_TEXT_TRACK_TYPE "text"
76#define MP4_SUBTITLE_TRACK_TYPE "sbtl"
77#define MP4_SUBPIC_TRACK_TYPE "subp"
82#define MP4_CLOCK_TRACK_TYPE "crsm"
83#define MP4_MPEG7_TRACK_TYPE "m7sm"
84#define MP4_OCI_TRACK_TYPE "ocsm"
85#define MP4_IPMP_TRACK_TYPE "ipsm"
86#define MP4_MPEGJ_TRACK_TYPE "mjsm"
88#define MP4_IS_VIDEO_TRACK_TYPE(type) \
89 (!strcasecmp(type, MP4_VIDEO_TRACK_TYPE))
91#define MP4_IS_AUDIO_TRACK_TYPE(type) \
92 (!strcasecmp(type, MP4_AUDIO_TRACK_TYPE))
94#define MP4_IS_CNTL_TRACK_TYPE(type) \
95 (!strcasecmp(type, MP4_CNTL_TRACK_TYPE))
97#define MP4_IS_OD_TRACK_TYPE(type) \
98 (!strcasecmp(type, MP4_OD_TRACK_TYPE))
100#define MP4_IS_SCENE_TRACK_TYPE(type) \
101 (!strcasecmp(type, MP4_SCENE_TRACK_TYPE))
103#define MP4_IS_HINT_TRACK_TYPE(type) \
104 (!strcasecmp(type, MP4_HINT_TRACK_TYPE))
106#define MP4_IS_SYSTEMS_TRACK_TYPE(type) \
107 (!strcasecmp(type, MP4_CLOCK_TRACK_TYPE) \
108 || !strcasecmp(type, MP4_MPEG7_TRACK_TYPE) \
109 || !strcasecmp(type, MP4_OCI_TRACK_TYPE) \
110 || !strcasecmp(type, MP4_IPMP_TRACK_TYPE) \
111 || !strcasecmp(type, MP4_MPEGJ_TRACK_TYPE))
114#define MP4_INVALID_AUDIO_TYPE 0x00
115#define MP4_MPEG1_AUDIO_TYPE 0x6B
116#define MP4_MPEG2_AUDIO_TYPE 0x69
117#define MP4_MP3_AUDIO_TYPE MP4_MPEG2_AUDIO_TYPE
118#define MP4_MPEG2_AAC_MAIN_AUDIO_TYPE 0x66
119#define MP4_MPEG2_AAC_LC_AUDIO_TYPE 0x67
120#define MP4_MPEG2_AAC_SSR_AUDIO_TYPE 0x68
121#define MP4_MPEG2_AAC_AUDIO_TYPE MP4_MPEG2_AAC_MAIN_AUDIO_TYPE
122#define MP4_MPEG4_AUDIO_TYPE 0x40
123#define MP4_PRIVATE_AUDIO_TYPE 0xC0
124#define MP4_PCM16_LITTLE_ENDIAN_AUDIO_TYPE 0xE0
125#define MP4_VORBIS_AUDIO_TYPE 0xE1
126#define MP4_AC3_AUDIO_TYPE 0xE2
127#define MP4_ALAW_AUDIO_TYPE 0xE3
128#define MP4_ULAW_AUDIO_TYPE 0xE4
129#define MP4_G723_AUDIO_TYPE 0xE5
130#define MP4_PCM16_BIG_ENDIAN_AUDIO_TYPE 0xE6
133#define MP4_MPEG4_INVALID_AUDIO_TYPE 0
134#define MP4_MPEG4_AAC_MAIN_AUDIO_TYPE 1
135#define MP4_MPEG4_AAC_LC_AUDIO_TYPE 2
136#define MP4_MPEG4_AAC_SSR_AUDIO_TYPE 3
137#define MP4_MPEG4_AAC_LTP_AUDIO_TYPE 4
138#define MP4_MPEG4_AAC_HE_AUDIO_TYPE 5
139#define MP4_MPEG4_AAC_SCALABLE_AUDIO_TYPE 6
140#define MP4_MPEG4_CELP_AUDIO_TYPE 8
141#define MP4_MPEG4_HVXC_AUDIO_TYPE 9
142#define MP4_MPEG4_TTSI_AUDIO_TYPE 12
143#define MP4_MPEG4_MAIN_SYNTHETIC_AUDIO_TYPE 13
144#define MP4_MPEG4_WAVETABLE_AUDIO_TYPE 14
145#define MP4_MPEG4_MIDI_AUDIO_TYPE 15
146#define MP4_MPEG4_ALGORITHMIC_FX_AUDIO_TYPE 16
147#define MP4_MPEG4_ALS_AUDIO_TYPE 31
148#define MP4_MPEG4_LAYER1_AUDIO_TYPE 32
149#define MP4_MPEG4_LAYER2_AUDIO_TYPE 33
150#define MP4_MPEG4_LAYER3_AUDIO_TYPE 34
151#define MP4_MPEG4_SLS_AUDIO_TYPE 35
154#define MP4_IS_MP3_AUDIO_TYPE(type) \
155 ((type) == MP4_MPEG1_AUDIO_TYPE || (type) == MP4_MPEG2_AUDIO_TYPE)
157#define MP4_IS_MPEG2_AAC_AUDIO_TYPE(type) \
158 (((type) >= MP4_MPEG2_AAC_MAIN_AUDIO_TYPE \
159 && (type) <= MP4_MPEG2_AAC_SSR_AUDIO_TYPE))
161#define MP4_IS_MPEG4_AAC_AUDIO_TYPE(mpeg4Type) \
162 (((mpeg4Type) >= MP4_MPEG4_AAC_MAIN_AUDIO_TYPE \
163 && (mpeg4Type) <= MP4_MPEG4_AAC_HE_AUDIO_TYPE) \
164 || (mpeg4Type) == MP4_MPEG4_AAC_SCALABLE_AUDIO_TYPE \
165 || (mpeg4Type) == 17)
167#define MP4_IS_AAC_AUDIO_TYPE(type) \
168 (MP4_IS_MPEG2_AAC_AUDIO_TYPE(type) \
169 || (type) == MP4_MPEG4_AUDIO_TYPE)
172#define MP4_INVALID_VIDEO_TYPE 0x00
173#define MP4_MPEG1_VIDEO_TYPE 0x6A
174#define MP4_MPEG2_SIMPLE_VIDEO_TYPE 0x60
175#define MP4_MPEG2_MAIN_VIDEO_TYPE 0x61
176#define MP4_MPEG2_SNR_VIDEO_TYPE 0x62
177#define MP4_MPEG2_SPATIAL_VIDEO_TYPE 0x63
178#define MP4_MPEG2_HIGH_VIDEO_TYPE 0x64
179#define MP4_MPEG2_442_VIDEO_TYPE 0x65
180#define MP4_MPEG2_VIDEO_TYPE MP4_MPEG2_MAIN_VIDEO_TYPE
181#define MP4_MPEG4_VIDEO_TYPE 0x20
182#define MP4_JPEG_VIDEO_TYPE 0x6C
183#define MP4_PRIVATE_VIDEO_TYPE 0xD0
184#define MP4_YUV12_VIDEO_TYPE 0xF0
185#define MP4_H263_VIDEO_TYPE 0xF2
186#define MP4_H261_VIDEO_TYPE 0xF3
189#define MP4_IS_MPEG1_VIDEO_TYPE(type) \
190 ((type) == MP4_MPEG1_VIDEO_TYPE)
192#define MP4_IS_MPEG2_VIDEO_TYPE(type) \
193 (((type) >= MP4_MPEG2_SIMPLE_VIDEO_TYPE \
194 && (type) <= MP4_MPEG2_442_VIDEO_TYPE) \
195 || MP4_IS_MPEG1_VIDEO_TYPE(type))
197#define MP4_IS_MPEG4_VIDEO_TYPE(type) \
198 ((type) == MP4_MPEG4_VIDEO_TYPE)
201#define MPEG4_SP_L1 (0x1)
202#define MPEG4_SP_L2 (0x2)
203#define MPEG4_SP_L3 (0x3)
204#define MPEG4_SP_L0 (0x8)
205#define MPEG4_SSP_L1 (0x11)
206#define MPEG4_SSP_L2 (0x12)
207#define MPEG4_CP_L1 (0x21)
208#define MPEG4_CP_L2 (0x22)
209#define MPEG4_MP_L2 (0x32)
210#define MPEG4_MP_L3 (0x33)
211#define MPEG4_MP_L4 (0x34)
212#define MPEG4_NBP_L2 (0x42)
213#define MPEG4_STP_L1 (0x51)
214#define MPEG4_SFAP_L1 (0x61)
215#define MPEG4_SFAP_L2 (0x62)
216#define MPEG4_SFBAP_L1 (0x63)
217#define MPEG4_SFBAP_L2 (0x64)
218#define MPEG4_BATP_L1 (0x71)
219#define MPEG4_BATP_L2 (0x72)
220#define MPEG4_HP_L1 (0x81)
221#define MPEG4_HP_L2 (0x82)
222#define MPEG4_ARTSP_L1 (0x91)
223#define MPEG4_ARTSP_L2 (0x92)
224#define MPEG4_ARTSP_L3 (0x93)
225#define MPEG4_ARTSP_L4 (0x94)
226#define MPEG4_CSP_L1 (0xa1)
227#define MPEG4_CSP_L2 (0xa2)
228#define MPEG4_CSP_L3 (0xa3)
229#define MPEG4_ACEP_L1 (0xb1)
230#define MPEG4_ACEP_L2 (0xb2)
231#define MPEG4_ACEP_L3 (0xb3)
232#define MPEG4_ACEP_L4 (0xb4)
233#define MPEG4_ACP_L1 (0xc1)
234#define MPEG4_ACP_L2 (0xc2)
235#define MPEG4_AST_L1 (0xd1)
236#define MPEG4_AST_L2 (0xd2)
237#define MPEG4_AST_L3 (0xd3)
238#define MPEG4_S_STUDIO_P_L1 (0xe1)
239#define MPEG4_S_STUDIO_P_L2 (0xe2)
240#define MPEG4_S_STUDIO_P_L3 (0xe3)
241#define MPEG4_S_STUDIO_P_L4 (0xe4)
242#define MPEG4_C_STUDIO_P_L1 (0xe5)
243#define MPEG4_C_STUDIO_P_L2 (0xe6)
244#define MPEG4_C_STUDIO_P_L3 (0xe7)
245#define MPEG4_C_STUDIO_P_L4 (0xe8)
246#define MPEG4_ASP_L0 (0xF0)
247#define MPEG4_ASP_L1 (0xF1)
248#define MPEG4_ASP_L2 (0xF2)
249#define MPEG4_ASP_L3 (0xF3)
250#define MPEG4_ASP_L4 (0xF4)
251#define MPEG4_ASP_L5 (0xF5)
252#define MPEG4_ASP_L3B (0xF7)
253#define MPEG4_FGSP_L0 (0xf8)
254#define MPEG4_FGSP_L1 (0xf9)
255#define MPEG4_FGSP_L2 (0xfa)
256#define MPEG4_FGSP_L3 (0xfb)
257#define MPEG4_FGSP_L4 (0xfc)
258#define MPEG4_FGSP_L5 (0xfd)
265bool MP4Make3GPCompliant(
266 const char* fileName,
267 char* majorBrand DEFAULT(0),
268 uint32_t minorVersion DEFAULT(0),
269 char** supportedBrands DEFAULT(NULL),
270 uint32_t supportedBrandsCount DEFAULT(0),
271 bool deleteIodsAtom DEFAULT(
true) );
324 MP4Timestamp startTime DEFAULT(0),
325 MP4Duration duration DEFAULT(0),
326 bool dwell DEFAULT(
false) );
371 MP4TrackId trackId );
495 MP4Timestamp startTime );
542 MP4Duration duration );
664 MP4Timestamp* pStartTime DEFAULT(NULL),
665 MP4Duration* pDuration DEFAULT(NULL),
666 MP4Duration* pRenderingOffset DEFAULT(NULL),
667 bool* pIsSyncSample DEFAULT(NULL) );
703 MP4Timestamp* pStartTime DEFAULT(NULL),
704 MP4Duration* pDuration DEFAULT(NULL) );
709#define MP4_SECONDS_TIME_SCALE 1
710#define MP4_MILLISECONDS_TIME_SCALE 1000
711#define MP4_MICROSECONDS_TIME_SCALE 1000000
712#define MP4_NANOSECONDS_TIME_SCALE 1000000000
714#define MP4_SECS_TIME_SCALE MP4_SECONDS_TIME_SCALE
715#define MP4_MSECS_TIME_SCALE MP4_MILLISECONDS_TIME_SCALE
716#define MP4_USECS_TIME_SCALE MP4_MICROSECONDS_TIME_SCALE
717#define MP4_NSECS_TIME_SCALE MP4_NANOSECONDS_TIME_SCALE
738 MP4Duration duration,
739 uint32_t timeScale );
763 MP4Timestamp timeStamp,
764 uint32_t timeScale );
787 uint32_t timeScale );
810 MP4Duration duration,
811 uint32_t timeScale );
833 uint32_t timeScale );
858 const uint8_t* pData,
884 const uint8_t* pData,
914 MP4LogCallback cb_func );
939 MP4LogLevel verbosity );
MP4Timestamp MP4ConvertToTrackTimestamp(MP4FileHandle hFile, MP4TrackId trackId, uint64_t timeStamp, uint32_t timeScale)
Convert a timestamp from a specified time scale to the track time scale.
uint64_t MP4ConvertFromTrackTimestamp(MP4FileHandle hFile, MP4TrackId trackId, MP4Timestamp timeStamp, uint32_t timeScale)
Convert a timestamp from the track time scale to a specified time scale.
bool MP4SetTrackEditDwell(MP4FileHandle hFile, MP4TrackId trackId, MP4EditId editId, bool dwell)
Set the dwell value of a track edit segment.
void MP4LogSetLevel(MP4LogLevel verbosity)
Set the maximum log level.
uint64_t MP4ConvertFromTrackDuration(MP4FileHandle hFile, MP4TrackId trackId, MP4Duration duration, uint32_t timeScale)
Convert duration from track time scale to an arbitrary time scale.
MP4EditId MP4AddTrackEdit(MP4FileHandle hFile, MP4TrackId trackId, MP4EditId editId=((MP4EditId) 0), MP4Timestamp startTime=0, MP4Duration duration=0, bool dwell=false)
Add an edit segment to a track.
MP4SampleId MP4GetSampleIdFromEditTime(MP4FileHandle hFile, MP4TrackId trackId, MP4Timestamp when, MP4Timestamp *pStartTime=NULL, MP4Duration *pDuration=NULL)
Get the sample id of a specified time in the edit list timeline.
MP4Timestamp MP4GetTrackEditStart(MP4FileHandle hFile, MP4TrackId trackId, MP4EditId editId)
Get the start time of a track edit segment.
int8_t MP4GetTrackEditDwell(MP4FileHandle hFile, MP4TrackId trackId, MP4EditId editId)
Get the dwell value of a track edit segment.
uint64_t MP4ConvertFromMovieDuration(MP4FileHandle hFile, MP4Duration duration, uint32_t timeScale)
Convert a duration from the movie (file) time scale to a specified time scale.
bool MP4ReadSampleFromEditTime(MP4FileHandle hFile, MP4TrackId trackId, MP4Timestamp when, uint8_t **ppBytes, uint32_t *pNumBytes, MP4Timestamp *pStartTime=NULL, MP4Duration *pDuration=NULL, MP4Duration *pRenderingOffset=NULL, bool *pIsSyncSample=NULL)
Read a track sample based on a specified edit list time.
bool MP4SetTrackEditDuration(MP4FileHandle hFile, MP4TrackId trackId, MP4EditId editId, MP4Duration duration)
Set the duration of a track edit segment.
bool MP4DeleteTrackEdit(MP4FileHandle hFile, MP4TrackId trackId, MP4EditId editId)
Delete a track edit segment.
uint32_t MP4GetTrackNumberOfEdits(MP4FileHandle hFile, MP4TrackId trackId)
Get the number of edit segments for a track.
MP4Timestamp MP4GetTrackEditMediaStart(MP4FileHandle hFile, MP4TrackId trackId, MP4EditId editId)
Get the media start time of a track edit segment.
void MP4SetLogCallback(MP4LogCallback cb_func)
Set the current log handler function.
MP4Duration MP4GetTrackEditDuration(MP4FileHandle hFile, MP4TrackId trackId, MP4EditId editId)
Get the duration of a track edit segment.
#define MP4_INVALID_EDIT_ID
Constant: invalid MP4EditId.
Definition: general.h:53
char * MP4BinaryToBase16(const uint8_t *pData, uint32_t dataSize)
Convert binary data to a base 16 string.
MP4LogLevel MP4LogGetLevel(void)
Get the current maximum log level.
bool MP4SetTrackEditMediaStart(MP4FileHandle hFile, MP4TrackId trackId, MP4EditId editId, MP4Timestamp startTime)
Set the media start time of a track edit segment.
MP4Duration MP4GetTrackEditTotalDuration(MP4FileHandle hFile, MP4TrackId trackId, MP4EditId editId=((MP4EditId) 0))
Get the total duration of a sequence of track edit segments.
char * MP4BinaryToBase64(const uint8_t *pData, uint32_t dataSize)
Convert binary data to a base 64 string.
void MP4Free(void *p)
Free memory allocated by other library functions.
MP4Duration MP4ConvertToTrackDuration(MP4FileHandle hFile, MP4TrackId trackId, uint64_t duration, uint32_t timeScale)
Convert duration from arbitrary time scale to track time scale.
uint32_t(* encryptFunc_t)(uint32_t, uint32_t, uint8_t *, uint32_t *, uint8_t **)
Encryption function pointer.
Definition: general.h:44