├── Mp4Recorder.cpp ├── Mp4Recorder.h ├── example.cc ├── fdkaac ├── inc │ ├── FDK_audio.h │ ├── aacdecoder_lib.h │ ├── aacenc_lib.h │ ├── audio.h │ ├── cmdl_parser.h │ ├── conv_string.h │ ├── genericStds.h │ ├── machine_type.h │ └── wav_file.h ├── libfdk-aac-1.dll ├── libfdk-aac-1.dll.def ├── libfdk-aac.a ├── libfdk-aac.def ├── libfdk-aac.dll.a ├── libfdk-aac.la └── libfdk-aac.lai ├── libfdk-aacenc.c ├── libfdk-aacenc.h ├── mp4v2 ├── inc │ ├── chapter.h │ ├── file.h │ ├── file_prop.h │ ├── general.h │ ├── isma.h │ ├── itmf_generic.h │ ├── itmf_tags.h │ ├── mp4v2.h │ ├── platform.h │ ├── project.h │ ├── project.h.in │ ├── sample.h │ ├── streaming.h │ ├── track.h │ └── track_prop.h ├── libmp4v2.dll └── libmp4v2.lib └── readme.md /Mp4Recorder.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by itisyang. 3 | // 4 | 5 | #include "Mp4Recorder.h" 6 | #include 7 | #include "util.h" 8 | 9 | int Mp4Recorder::initAACEncoder() { 10 | if (aac_encode_init(&aacEncCtx, 1, 8000, 320) != 0) { 11 | LOGE("初始化AAC编码器失败"); 12 | return -1; 13 | } 14 | return 0; 15 | } 16 | 17 | int Mp4Recorder::startRecord(const char* fileName, int width,int height,int frame_rate,unsigned char *sps_pps) { 18 | m_vWidth = width; 19 | m_vHeight = height; 20 | m_vFrateR = frame_rate; 21 | m_vTimeScale = 90000; 22 | m_vFrameDur = 3000; 23 | mp4FileHandle= (MP4FileHandle)MP4Create(fileName,0); 24 | if(mp4FileHandle==MP4_INVALID_FILE_HANDLE){ 25 | LOGE("创建MP4文件失败!"); 26 | return -1; 27 | } 28 | MP4SetTimeScale(mp4FileHandle,m_vTimeScale); 29 | mp4VideoTrackID=MP4AddH264VideoTrack(mp4FileHandle,m_vTimeScale,m_vTimeScale/m_vFrateR,width,height 30 | ,sps_pps[5],sps_pps[6],sps_pps[7],3); 31 | if(mp4VideoTrackID == MP4_INVALID_TRACK_ID) 32 | { 33 | LOGE("创建视频Track失败!"); 34 | MP4Close(mp4FileHandle); 35 | mp4FileHandle=NULL; 36 | return -1; 37 | } 38 | mp4AudioTrackID=MP4AddAudioTrack(mp4FileHandle,8000,1024, MP4_MPEG4_AUDIO_TYPE); 39 | if(mp4AudioTrackID == MP4_INVALID_TRACK_ID) 40 | { 41 | LOGE("创建音频Track失败!"); 42 | MP4Close(mp4FileHandle); 43 | mp4FileHandle=NULL; 44 | return -1; 45 | } 46 | //bit->00010, 1011, 0001, 000 = 0x1588 47 | // LOW 采样率编号 单声道 48 | u_int8_t pConfig[] = {0x15,0x88}; 49 | MP4SetTrackESConfiguration(mp4FileHandle, mp4AudioTrackID, pConfig, 2); 50 | if (initAACEncoder() < 0) { 51 | LOGE("初始化AAC编码器失败"); 52 | return -1; 53 | } 54 | isAvailable= false; 55 | MP4SetVideoProfileLevel(mp4FileHandle, 0x01); 56 | LOGE("开始录制文件%s",fileName); 57 | return 1; 58 | } 59 | 60 | void Mp4Recorder::stopRecord(){ 61 | isAvailable = false; 62 | FoundNF = false; 63 | MP4Close(mp4FileHandle); 64 | aac_free_context(&aacEncCtx); 65 | LOGE("结束录制文件"); 66 | } 67 | 68 | void Mp4Recorder::writeAudioData(uint8_t*buffer, int size,int duration) { 69 | //进行录像输出 70 | if(!isAvailable&&!FoundNF){ 71 | return; 72 | } 73 | if (aac_encode_frame(aacEncCtx, buffer) != 0) { 74 | return; 75 | } 76 | MP4WriteSample( 77 | mp4FileHandle, 78 | mp4AudioTrackID, 79 | aac_get_out_buffer(aacEncCtx), 80 | aac_get_out_size(aacEncCtx), 81 | MP4_INVALID_DURATION, 82 | 0, 83 | true); 84 | m_vFrameDur += 1024; 85 | } 86 | 87 | void Mp4Recorder::writeVideoData(char * buffer,int size,int duration) { 88 | //进行录像输出 89 | //进行录像输出 90 | char * pBuffer=buffer; 91 | int off=0; 92 | int findMaxPos = size >> 1; //size / 2 查找到最大的位置 93 | bool isFoundSPS = FALSE; //!< 是否找到SPS帧 94 | bool isFoundPPS = FALSE; //!< 是否找到PPS帧 95 | bool isFoundIEX = FALSE; //!< 是否找到I帧加强帧 96 | bool isFoundNF = FALSE; //!< 是否找到普通帧 97 | int spsLoc,ppsLoc,iexLoc; //!< 帧信息开始的位置 98 | int spsLen,ppsLen,iexLen; //!< 帧信息的长度 99 | spsLoc = ppsLoc = iexLoc = spsLen = ppsLen = iexLen = 0; 100 | for (off = 0; off < findMaxPos; off++) { 101 | if (pBuffer[off]==0x00 && pBuffer[off + 1]==0x00 && pBuffer[off + 2]==0x00 && pBuffer[off + 3]==0x01 && pBuffer[off + 4]==0x67 && !isFoundSPS) { 102 | isFoundSPS = TRUE; 103 | off += 4; 104 | spsLoc = off;//SPS帧的开始位置 105 | continue; 106 | } else if (!isFoundPPS && !isFoundIEX && isFoundSPS) { 107 | spsLen++; 108 | } 109 | if(pBuffer[off+0]==0x00 && pBuffer[off+1]==0x00 && pBuffer[off+2]==0x00 && pBuffer[off+3]==0x01 && pBuffer[off+4]==0x68 && !isFoundPPS) { 110 | isFoundPPS = TRUE; 111 | off += 4; 112 | ppsLoc = off;//PSP的开始位置 113 | continue; 114 | } else if (!isFoundIEX && isFoundPPS) { 115 | ppsLen++; 116 | } 117 | if(pBuffer[off+0]==0x00 && pBuffer[off+1]==0x00 && pBuffer[off+2]==0x00 && pBuffer[off+3]==0x01 && pBuffer[off+4]==0x06 && !isFoundIEX) { 118 | isFoundIEX = TRUE; 119 | off += 4; 120 | iexLoc = off;//I帧加强的开始位置 121 | continue; 122 | } else if (isFoundIEX) { 123 | iexLen++; 124 | } 125 | if(pBuffer[off+0]==0x00 && pBuffer[off+1]==0x00 && pBuffer[off+2]==0x00 && pBuffer[off+3]==0x01 && 126 | pBuffer[off+4]!=0x67 && pBuffer[off+4]!=0x68 && pBuffer[off+4]!=0x06 //非SPS,PPS,I帧加强则认为是普通帧 127 | ){ 128 | isFoundNF = TRUE; 129 | break; 130 | } 131 | 132 | } 133 | if(isFoundSPS){ 134 | //SPS 135 | //必须找到第一个I帧才正式开始录像 136 | isAvailable = TRUE; 137 | //LOGE("录制一帧!SPS %d, %d", spsLoc, spsLen); 138 | MP4SetVideoProfileLevel(mp4FileHandle, 0x01); 139 | //MP4AddH264SequenceParameterSet(mp4FileHandle,mp4VideoTrackID,(uint8_t*)&buffer[spsLoc],12); 140 | MP4AddH264SequenceParameterSet(mp4FileHandle,mp4VideoTrackID,(uint8_t*)&buffer[spsLoc],spsLen); 141 | } 142 | 143 | if (!isAvailable) { 144 | return; 145 | } 146 | 147 | if(isFoundPPS){ 148 | //PPS 149 | //LOGE("录制一帧!PPS %d, %d", ppsLoc, ppsLen); 150 | MP4AddH264PictureParameterSet(mp4FileHandle,mp4VideoTrackID,(uint8_t*)&buffer[ppsLoc],ppsLen); 151 | } 152 | if(isFoundIEX){ 153 | //I帧加强信息 154 | // LOGE("录制一帧!I帧加强信息 %d, %d", iexLoc, iexLen); 155 | } 156 | if(isFoundNF){ 157 | uint32_t* p = (uint32_t*)&buffer[off]; 158 | *p = htonl(size-off-4);//大端,去掉头部四个字节 159 | MP4WriteSample(mp4FileHandle,mp4VideoTrackID,(uint8_t*)(&buffer[off]),size-off,m_vFrameDur/8000*90000,0,true); 160 | FoundNF = true; 161 | //LOGE("录制一帧!"); 162 | m_vFrameDur = 0; 163 | return; 164 | } else { 165 | LOGE("录制一帧!ERR"); 166 | } 167 | } -------------------------------------------------------------------------------- /Mp4Recorder.h: -------------------------------------------------------------------------------- 1 | // 2 | // MP4录像类,用于H264+pcm流进行mp4输出 3 | // Created by itisyang. 4 | // 5 | 6 | #ifndef PPSTRONGVIDEO_MP4RECORDER_H 7 | #define PPSTRONGVIDEO_MP4RECORDER_H 8 | extern "C" 9 | { 10 | #include "mp4v2/mp4v2.h" 11 | #include "mp4v2/general.h" 12 | #include "mp4v2/file.h" 13 | #include "mp4v2/file_prop.h" 14 | #include "mp4v2/track.h" 15 | #include "libfdk-aacenc.h" 16 | } 17 | 18 | class Mp4Recorder { 19 | private: 20 | MP4FileHandle mp4FileHandle; 21 | MP4TrackId mp4VideoTrackID; 22 | MP4TrackId mp4AudioTrackID; 23 | AACEncodeContext *aacEncCtx; 24 | /** 25 | * 初始化FDK-AAC编码器 26 | */ 27 | int initAACEncoder(); 28 | public: 29 | bool isAvailable; 30 | bool FoundNF; 31 | int m_vWidth,m_vHeight,m_vFrateR,m_vTimeScale; 32 | double m_vFrameDur; 33 | /** 34 | * 开始录像 35 | */ 36 | int startRecord(const char* fileName, int width,int height,int frame_rate,unsigned char *sps_pps); 37 | /** 38 | * 停止录像 39 | */ 40 | void stopRecord(); 41 | /** 42 | * 写入视频数据 43 | */ 44 | void writeVideoData(char * buffer,int size,int duration); 45 | /** 46 | * 写入音频数据 47 | */ 48 | void writeAudioData(uint8_t* buffer,int size,int duration); 49 | }; 50 | 51 | 52 | #endif //PPSTRONGVIDEO_MP4RECORDER_H 53 | -------------------------------------------------------------------------------- /example.cc: -------------------------------------------------------------------------------- 1 | // 2 | //usage of Mp4Recorder while receive stream 3 | // Created by itisyang. 4 | // 5 | 6 | #include "Mp4Recorder.h" 7 | 8 | class STREAM_THREAD : public QThread 9 | { 10 | Q_OBJECT 11 | public: 12 | Mp4Recorder *mp4Recoder; 13 | //SPS PPS 14 | unsigned char sps_pps[128]; 15 | int videoWidth; //视频宽 16 | int videoHeight; //视频高 17 | int frameRatio; //视频帧率 18 | const QString VIDEO_PATH = "/temp/video/"; 19 | 20 | //TODO......define other para/fun for receive stream etc.. 21 | } 22 | 23 | void STREAM_THREAD::startRecord() 24 | { 25 | if(!this->isRunning()) 26 | return ; 27 | qDebug() << "开始录像"; 28 | QString fileName; 29 | fileName.append(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); 30 | 31 | fileName.append(VIDEO_PATH); 32 | 33 | fileName.append(QDateTime::currentDateTime().toString("yyyyMMdd-hhmmss").append(".mp4")); 34 | 35 | Mp4Recorder *recorder=new Mp4Recorder(); 36 | int ret=recorder->startRecord(fileName.toStdString().c_str(), 37 | this->videoWidth, 38 | this->videoHeight, 39 | this->frameRatio, 40 | sps_pps); 41 | if(ret>=0){ 42 | this->mp4Recoder=recorder; 43 | } 44 | } 45 | 46 | void STREAM_THREAD::stopRecord() 47 | { 48 | qDebug() << "停止录像"; 49 | if(this->mp4Recoder == NULL){ 50 | return ; 51 | } 52 | Mp4Recorder * recorder=this->mp4Recoder; 53 | this->mp4Recoder=NULL; 54 | //bool isAvailable=recorder->isAvailable; 55 | recorder->stopRecord(); 56 | delete recorder; 57 | //return isAvailable; 58 | } 59 | 60 | void STREAM_THREAD::run() 61 | { 62 | while (***) { 63 | //TODO....get stream 64 | if (packet.av_type == STREAM_DATA_VIDEO) { 65 | //TODO...other operation ,such as decode... 66 | //如果当前处于录像时间,那么录制视频数据 67 | if(this->mp4Recoder!=NULL){ 68 | gettimeofday(&tv,NULL); 69 | this->mp4Recoder->writeVideoData(packet.data, packet.size,(tv.tv_sec * 1000 + tv.tv_usec / 1000-oldVideoTimeStamp)); 70 | } 71 | oldVideoTimeStamp = tv.tv_sec * 1000 + tv.tv_usec / 1000; 72 | free(buffer); 73 | } else if (packet.av_type == STREAM_DATA_AUDIO) { 74 | //TODO...other operation ,such as decode... 75 | //如果当前处于录像时间,那么录制音频数据 76 | if(this->mp4Recoder!=NULL){ 77 | //获取当前的时间 78 | gettimeofday(&tv,NULL); 79 | //录制的时候,将时间差记录 80 | this->mp4Recoder->writeAudioData(packet.data, packet.size, tv.tv_sec * 1000 + tv.tv_usec / 1000-oldAudioTimeStamp); 81 | //保存当前的时间 82 | oldAudioTimeStamp = tv.tv_sec * 1000 + tv.tv_usec / 1000; 83 | } 84 | } 85 | } 86 | 87 | //TODO...free resource 88 | } 89 | 90 | STREAM_THREAD::STREAM_THREAD() 91 | { 92 | mp4Recoder = NULL; 93 | } -------------------------------------------------------------------------------- /fdkaac/inc/FDK_audio.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itisyang/mp4-recorder/0de7642becda0374b4dbb644c053fcc0f9d8f2bc/fdkaac/inc/FDK_audio.h -------------------------------------------------------------------------------- /fdkaac/inc/aacdecoder_lib.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itisyang/mp4-recorder/0de7642becda0374b4dbb644c053fcc0f9d8f2bc/fdkaac/inc/aacdecoder_lib.h -------------------------------------------------------------------------------- /fdkaac/inc/aacenc_lib.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itisyang/mp4-recorder/0de7642becda0374b4dbb644c053fcc0f9d8f2bc/fdkaac/inc/aacenc_lib.h -------------------------------------------------------------------------------- /fdkaac/inc/audio.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itisyang/mp4-recorder/0de7642becda0374b4dbb644c053fcc0f9d8f2bc/fdkaac/inc/audio.h -------------------------------------------------------------------------------- /fdkaac/inc/cmdl_parser.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itisyang/mp4-recorder/0de7642becda0374b4dbb644c053fcc0f9d8f2bc/fdkaac/inc/cmdl_parser.h -------------------------------------------------------------------------------- /fdkaac/inc/conv_string.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itisyang/mp4-recorder/0de7642becda0374b4dbb644c053fcc0f9d8f2bc/fdkaac/inc/conv_string.h -------------------------------------------------------------------------------- /fdkaac/inc/genericStds.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itisyang/mp4-recorder/0de7642becda0374b4dbb644c053fcc0f9d8f2bc/fdkaac/inc/genericStds.h -------------------------------------------------------------------------------- /fdkaac/inc/machine_type.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itisyang/mp4-recorder/0de7642becda0374b4dbb644c053fcc0f9d8f2bc/fdkaac/inc/machine_type.h -------------------------------------------------------------------------------- /fdkaac/inc/wav_file.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itisyang/mp4-recorder/0de7642becda0374b4dbb644c053fcc0f9d8f2bc/fdkaac/inc/wav_file.h -------------------------------------------------------------------------------- /fdkaac/libfdk-aac-1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itisyang/mp4-recorder/0de7642becda0374b4dbb644c053fcc0f9d8f2bc/fdkaac/libfdk-aac-1.dll -------------------------------------------------------------------------------- /fdkaac/libfdk-aac-1.dll.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | aacDecoder_AncDataGet 3 | aacDecoder_AncDataInit 4 | aacDecoder_Close 5 | aacDecoder_ConfigRaw 6 | aacDecoder_DecodeFrame 7 | aacDecoder_Fill 8 | aacDecoder_GetFreeBytes 9 | aacDecoder_GetLibInfo 10 | aacDecoder_GetStreamInfo 11 | aacDecoder_Open 12 | aacDecoder_SetParam 13 | aacEncClose 14 | aacEncEncode 15 | aacEncGetLibInfo 16 | aacEncInfo 17 | aacEncOpen 18 | aacEncoder_GetParam 19 | aacEncoder_SetParam 20 | -------------------------------------------------------------------------------- /fdkaac/libfdk-aac.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itisyang/mp4-recorder/0de7642becda0374b4dbb644c053fcc0f9d8f2bc/fdkaac/libfdk-aac.a -------------------------------------------------------------------------------- /fdkaac/libfdk-aac.def: -------------------------------------------------------------------------------- 1 | aacDecoder_AncDataGet 2 | aacDecoder_AncDataInit 3 | aacDecoder_Close 4 | aacDecoder_ConfigRaw 5 | aacDecoder_DecodeFrame 6 | aacDecoder_Fill 7 | aacDecoder_GetFreeBytes 8 | aacDecoder_GetLibInfo 9 | aacDecoder_GetStreamInfo 10 | aacDecoder_Open 11 | aacDecoder_SetParam 12 | aacEncClose 13 | aacEncEncode 14 | aacEncGetLibInfo 15 | aacEncInfo 16 | aacEncOpen 17 | aacEncoder_GetParam 18 | aacEncoder_SetParam 19 | -------------------------------------------------------------------------------- /fdkaac/libfdk-aac.dll.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itisyang/mp4-recorder/0de7642becda0374b4dbb644c053fcc0f9d8f2bc/fdkaac/libfdk-aac.dll.a -------------------------------------------------------------------------------- /fdkaac/libfdk-aac.la: -------------------------------------------------------------------------------- 1 | # libfdk-aac.la - a libtool library file 2 | # Generated by libtool (GNU libtool) 2.4 3 | # 4 | # Please DO NOT delete this file! 5 | # It is necessary for linking the library. 6 | 7 | # The name that we can dlopen(3). 8 | dlname='libfdk-aac-1.dll' 9 | 10 | # Names of this library. 11 | library_names='libfdk-aac.dll.a' 12 | 13 | # The name of the static archive. 14 | old_library='libfdk-aac.a' 15 | 16 | # Linker flags that can not go in dependency_libs. 17 | inherited_linker_flags='' 18 | 19 | # Libraries that this one depends upon. 20 | dependency_libs='' 21 | 22 | # Names of additional weak libraries provided by this library 23 | weak_library_names='' 24 | 25 | # Version information for libfdk-aac. 26 | current=1 27 | age=0 28 | revision=0 29 | 30 | # Is this an already installed library? 31 | installed=no 32 | 33 | # Should we warn about portability when linking against -modules? 34 | shouldnotlink=no 35 | 36 | # Files to dlopen/dlpreopen 37 | dlopen='' 38 | dlpreopen='' 39 | 40 | # Directory that this library needs to be installed in: 41 | libdir='/usr/local/lib' 42 | -------------------------------------------------------------------------------- /fdkaac/libfdk-aac.lai: -------------------------------------------------------------------------------- 1 | # libfdk-aac.la - a libtool library file 2 | # Generated by libtool (GNU libtool) 2.4 3 | # 4 | # Please DO NOT delete this file! 5 | # It is necessary for linking the library. 6 | 7 | # The name that we can dlopen(3). 8 | dlname='../bin/libfdk-aac-1.dll' 9 | 10 | # Names of this library. 11 | library_names='libfdk-aac.dll.a' 12 | 13 | # The name of the static archive. 14 | old_library='libfdk-aac.a' 15 | 16 | # Linker flags that can not go in dependency_libs. 17 | inherited_linker_flags='' 18 | 19 | # Libraries that this one depends upon. 20 | dependency_libs='' 21 | 22 | # Names of additional weak libraries provided by this library 23 | weak_library_names='' 24 | 25 | # Version information for libfdk-aac. 26 | current=1 27 | age=0 28 | revision=0 29 | 30 | # Is this an already installed library? 31 | installed=yes 32 | 33 | # Should we warn about portability when linking against -modules? 34 | shouldnotlink=no 35 | 36 | # Files to dlopen/dlpreopen 37 | dlopen='' 38 | dlpreopen='' 39 | 40 | # Directory that this library needs to be installed in: 41 | libdir='/usr/local/lib' 42 | -------------------------------------------------------------------------------- /libfdk-aacenc.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by itisyang. 3 | // 4 | 5 | #include "libfdk-aacenc.h" 6 | #include "fdk-aac/aacenc_lib.h" 7 | #include "fdk-aac/FDK_audio.h" 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #define DLog(...) __android_log_print(ANDROID_LOG_INFO, "debug-fdk_aac", __VA_ARGS__) 16 | 17 | typedef struct AACEncodeContext { 18 | HANDLE_AACENCODER *encoder; 19 | int channels; 20 | int nb_samples; 21 | int frame_size; 22 | int initial_padding; 23 | uint8_t outData[8192]; 24 | int outSize; 25 | } AACEncodeContext; 26 | 27 | int aac_encode_init(AACEncodeContext ** ectx, int channels, int samplerate, int nb_samples) { 28 | HANDLE_AACENCODER *encoder = (HANDLE_AACENCODER*)calloc(sizeof(HANDLE_AACENCODER), 1); 29 | AACENC_InfoStruct info = {0}; 30 | CHANNEL_MODE mode; 31 | AACENC_ERROR err; 32 | int sce = 0, cpe = 0; 33 | if ((err = aacEncOpen(encoder, 0, channels)) != AACENC_OK) { 34 | DLog("打开fdk-aac的编码器失败!"); 35 | goto error; 36 | } 37 | if ((err = aacEncoder_SetParam(*encoder, AACENC_AOT, AOT_AAC_LC)) != AACENC_OK) { 38 | DLog("不能设置AOT"); 39 | goto error; 40 | } 41 | if ((err = aacEncoder_SetParam(*encoder, AACENC_SAMPLERATE, samplerate)) != AACENC_OK) { 42 | DLog("不能设置采样率:%d", samplerate); 43 | goto error; 44 | } 45 | switch (channels) { 46 | case 1:mode = MODE_1; sce = 1; cpe = 0; break; 47 | case 2:mode = MODE_2; sce = 0; cpe = 1; break; 48 | case 3:mode = MODE_1_2; sce = 1; cpe = 1; break; 49 | case 4:mode = MODE_1_2_1; sce = 2; cpe = 1; break; 50 | case 5:mode = MODE_1_2_2; sce = 1; cpe = 2; break; 51 | case 6:mode = MODE_1_2_2_1; sce = 2; cpe = 2; break; 52 | default: 53 | DLog("无法设置声道模式"); 54 | return -1; 55 | } 56 | if ((err = aacEncoder_SetParam(*encoder, AACENC_CHANNELMODE, mode)) != AACENC_OK) { 57 | DLog("设置声道模式失败"); 58 | goto error; 59 | } 60 | 61 | if ((err = aacEncoder_SetParam(*encoder, AACENC_CHANNELORDER, 1)) != AACENC_OK) { 62 | DLog("不能设置wav声道排列 %d", mode); 63 | goto error; 64 | } 65 | 66 | int bitrate = (96 * sce + 128 * cpe) * samplerate / 44; 67 | if ((err = aacEncoder_SetParam(*encoder, AACENC_BITRATE, bitrate)) != AACENC_OK) { 68 | DLog("不能设置码率 %d", bitrate); 69 | goto error; 70 | } 71 | 72 | if ((err = aacEncoder_SetParam(*encoder, AACENC_TRANSMUX, 0)) != AACENC_OK) { 73 | DLog("不能够设置transmux format"); 74 | goto error; 75 | } 76 | 77 | if ((err = aacEncEncode(*encoder, NULL, NULL, NULL, NULL)) != AACENC_OK) { 78 | DLog("初始化编码器失败!"); 79 | goto error; 80 | } 81 | 82 | if ((err = aacEncInfo(*encoder, &info)) != AACENC_OK) { 83 | DLog("获取编码器信息失败!"); 84 | goto error; 85 | } 86 | 87 | AACEncodeContext *_ectx = (AACEncodeContext*)calloc(sizeof(AACEncodeContext), 1); 88 | _ectx->encoder = encoder; 89 | _ectx->frame_size = info.frameLength; 90 | _ectx->initial_padding = info.encoderDelay; 91 | _ectx->channels = channels; 92 | _ectx->nb_samples = nb_samples; 93 | (*ectx) = _ectx; 94 | 95 | return 0; 96 | 97 | error: 98 | aacEncClose((HANDLE_AACENCODER *)(*encoder)); 99 | if (encoder)free(encoder); 100 | return err; 101 | } 102 | 103 | int aac_encode_frame(AACEncodeContext *ctx, u_int8_t *inData) { 104 | if (!ctx || !inData) { 105 | DLog("传入的上下文或者帧数据为空"); 106 | return -1; 107 | } 108 | AACENC_BufDesc in_buf = {0}, out_buf = {0}; 109 | AACENC_InArgs in_args = {0}; 110 | AACENC_OutArgs out_args = {0}; 111 | int in_buffer_identifier = IN_AUDIO_DATA; 112 | int in_buffer_size, in_buffer_element_size; 113 | int out_buffer_identifier = OUT_BITSTREAM_DATA; 114 | int out_buffer_size, out_buffer_element_size; 115 | 116 | void *in_ptr, *out_ptr; 117 | AACENC_ERROR err; 118 | in_ptr = inData; 119 | in_buffer_size = 2 * ctx->channels * ctx->nb_samples; 120 | in_buffer_element_size = 2; 121 | 122 | in_args.numInSamples = ctx->channels * ctx->nb_samples; 123 | in_buf.numBufs = 1; 124 | in_buf.bufs = &in_ptr; 125 | in_buf.bufferIdentifiers = &in_buffer_identifier; 126 | in_buf.bufSizes = &in_buffer_size; 127 | in_buf.bufElSizes = &in_buffer_element_size; 128 | 129 | ctx->outSize = 8192>(768 * ctx->channels)?8192:(768 * ctx->channels); 130 | 131 | out_ptr = ctx->outData; 132 | out_buffer_size = ctx->outSize; 133 | out_buffer_element_size = 1; 134 | out_buf.numBufs = 1; 135 | out_buf.bufs = &out_ptr; 136 | out_buf.bufferIdentifiers = &out_buffer_identifier; 137 | out_buf.bufSizes = &out_buffer_size; 138 | out_buf.bufElSizes = &out_buffer_element_size; 139 | 140 | if (!ctx)DLog("ctx NULL"); 141 | if (!(ctx->encoder))DLog("encoder NULL"); 142 | if (!inData)DLog("inData NULL"); 143 | 144 | if ((err = aacEncEncode(*ctx->encoder, &in_buf, &out_buf, &in_args, &out_args)) != AACENC_OK) { 145 | DLog("不能编码帧!"); 146 | return err; 147 | } 148 | if (!out_args.numOutBytes) { //可能编码帧失败,或者编码出来的帧为空 149 | return -1; 150 | } 151 | 152 | ctx->outSize = out_args.numOutBytes; 153 | return 0; 154 | } 155 | 156 | int aac_get_out_size(AACEncodeContext *ctx) { 157 | if (!ctx)return 0; 158 | return ctx->outSize; 159 | } 160 | 161 | u_int8_t *aac_get_out_buffer(AACEncodeContext *ctx) { 162 | if (!ctx)return NULL; 163 | return ctx->outData; 164 | } 165 | 166 | void aac_free_context(AACEncodeContext **ctx) { 167 | if (!(*ctx)) { 168 | return; 169 | } 170 | AACEncodeContext *ctx_ = *ctx; 171 | if (ctx_->encoder) { 172 | aacEncClose(ctx_->encoder); 173 | free(ctx_->encoder); 174 | } 175 | free(ctx_); 176 | (*ctx) = NULL; 177 | } -------------------------------------------------------------------------------- /libfdk-aacenc.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by itisyang. 3 | // 4 | 5 | #ifndef PPSTRONGVIDEO_LIBFDK_AACENC_H 6 | #define PPSTRONGVIDEO_LIBFDK_AACENC_H 7 | 8 | #include 9 | 10 | typedef struct AACEncodeContext AACEncodeContext; 11 | 12 | /** 13 | * 初始化aac编码器 14 | * @param ectx 上下文的指针 15 | * @param channels 声道数 16 | * @param samplerate 采样率 17 | * @param nb_samples 每一个音频帧的长度 18 | * 19 | * @return 返回0为成功,其它失败 20 | * 21 | * 22 | */ 23 | int aac_encode_init(AACEncodeContext ** ectx, int channels, int samplerate, int nb_samples); 24 | 25 | /** 26 | * 编码帧 27 | * @param ctx AAC编码的上下文 28 | * @param inData 需要编码的音频帧数据 29 | * @return 返回0成功,其它失败 30 | */ 31 | int aac_encode_frame(AACEncodeContext *ctx, u_int8_t *inData); 32 | 33 | /** 34 | * 获取当前编码之后的帧数据大小 35 | * @param ctx AAC编码的上下文 36 | * @return 编码之后的帧大小 37 | */ 38 | int aac_get_out_size(AACEncodeContext *ctx); 39 | 40 | /** 41 | * 获取编码之后的数据帧的指针 42 | * @param ctx AAC编码的上下文 43 | * @return 数据指针 44 | */ 45 | u_int8_t *aac_get_out_buffer(AACEncodeContext *ctx); 46 | 47 | /** 48 | * 释放AAC编码上下文 49 | * 释放完成以后会对ctx置空 50 | */ 51 | void aac_free_context(AACEncodeContext **ctx); 52 | 53 | #endif //PPSTRONGVIDEO_LIBFDK_AACENC_H 54 | -------------------------------------------------------------------------------- /mp4v2/inc/chapter.h: -------------------------------------------------------------------------------- 1 | #ifndef MP4V2_CHAPTER_H 2 | #define MP4V2_CHAPTER_H 3 | 4 | /**************************************************************************//** 5 | * 6 | * @defgroup mp4_chapter MP4v2 Chapter 7 | * @{ 8 | * 9 | *****************************************************************************/ 10 | 11 | /** The maximum length of a QuickTime chapter title (in 8-bit chars) 12 | */ 13 | #define MP4V2_CHAPTER_TITLE_MAX 1023 14 | 15 | /** Chapter item. 16 | * This item defines various attributes for a chapter. 17 | * @ingroup mp4_chapter 18 | */ 19 | typedef struct MP4Chapter_s { 20 | MP4Duration duration; /**< duration of chapter in milliseconds */ 21 | char title[MP4V2_CHAPTER_TITLE_MAX+1]; /**< title of chapter */ 22 | } MP4Chapter_t; 23 | 24 | /** Known chapter types. 25 | * @ingroup mp4_chapter 26 | */ 27 | typedef enum { 28 | MP4ChapterTypeNone = 0, /**< no chapters found return value */ 29 | MP4ChapterTypeAny = 1, /**< any or all known chapter types */ 30 | MP4ChapterTypeQt = 2, /**< QuickTime chapter type */ 31 | MP4ChapterTypeNero = 4 /**< Nero chapter type */ 32 | } MP4ChapterType; 33 | 34 | /** Add a QuickTime chapter. 35 | * 36 | * This function adds a QuickTime chapter to file hFile. 37 | * 38 | * @param hFile handle of file to add chapter. 39 | * @param chapterTrackId ID of chapter track or #MP4_INVALID_TRACK_ID 40 | * if unknown. 41 | * @param chapterDuration duration (in the timescale of the chapter track). 42 | * @param chapterTitle title text for the chapter or NULL to use default 43 | * title format ("Chapter %03d", n) where n is the chapter number. 44 | */ 45 | MP4V2_EXPORT 46 | void MP4AddChapter( 47 | MP4FileHandle hFile, 48 | MP4TrackId chapterTrackId, 49 | MP4Duration chapterDuration, 50 | const char* chapterTitle DEFAULT(0)); 51 | 52 | /** Add a QuickTime chapter track. 53 | * 54 | * This function adds a chapter (text) track to file hFile. 55 | * The optional parameter timescale may be supplied to give the new 56 | * chapter a specific timescale. Otherwise the chapter track will have 57 | * the same timescale as the reference track defined in parameter refTrackId. 58 | * 59 | * @param hFile handle of file to add chapter track. 60 | * @param refTrackId ID of the track that will reference the chapter track. 61 | * @param timescale the timescale of the chapter track or 0 to use the 62 | * timescale of track specified by refTrackId. 63 | * 64 | * @return ID of the created chapter track. 65 | */ 66 | MP4V2_EXPORT 67 | MP4TrackId MP4AddChapterTextTrack( 68 | MP4FileHandle hFile, 69 | MP4TrackId refTrackId, 70 | uint32_t timescale DEFAULT(0) ); 71 | 72 | /** Add a Nero chapter. 73 | * 74 | * This function adds a Nero chapter to file hFile. 75 | * 76 | * @param hFile handle of file to add chapter. 77 | * @param chapterStart the start time of the chapter in 100 nanosecond units 78 | * @param chapterTitle title text for the chapter or NULL to use default 79 | * title format ("Chapter %03d", n) where n is the chapter number. 80 | */ 81 | MP4V2_EXPORT 82 | void MP4AddNeroChapter( 83 | MP4FileHandle hFile, 84 | MP4Timestamp chapterStart, 85 | const char* chapterTitle DEFAULT(0)); 86 | 87 | /** Convert chapters to another type. 88 | * 89 | * This function converts existing chapters in file hFile 90 | * from one type to another type. 91 | * Conversion from Nero to QuickTime or QuickTime to Nero is supported. 92 | * 93 | * @param hFile handle of file to convert. 94 | * @param toChapterType the chapter type to convert to: 95 | * @li #MP4ChapterTypeQt (convert from Nero to Qt) 96 | * @li #MP4ChapterTypeNero (convert from Qt to Nero) 97 | * 98 | * @return the chapter type before conversion or #MP4ChapterTypeNone 99 | * if the source chapters do not exist 100 | * or invalid toChapterType was specified. 101 | */ 102 | MP4V2_EXPORT 103 | MP4ChapterType MP4ConvertChapters( 104 | MP4FileHandle hFile, 105 | MP4ChapterType toChapterType DEFAULT(MP4ChapterTypeQt)); 106 | 107 | /** Delete chapters. 108 | * 109 | * This function deletes existing chapters in file hFile. 110 | * 111 | * @param hFile handle of file to delete chapters. 112 | * @param chapterType the type of chapters to delete: 113 | * @li #MP4ChapterTypeAny (delete all known chapter types) 114 | * @li #MP4ChapterTypeQt 115 | * @li #MP4ChapterTypeNero 116 | * @param chapterTrackId ID of the chapter track if known, 117 | * or #MP4_INVALID_TRACK_ID. 118 | * Only applies when chapterType=#MP4ChapterTypeQt. 119 | * 120 | * @return the type of deleted chapters 121 | */ 122 | MP4V2_EXPORT 123 | MP4ChapterType MP4DeleteChapters( 124 | MP4FileHandle hFile, 125 | MP4ChapterType chapterType DEFAULT(MP4ChapterTypeQt), 126 | MP4TrackId chapterTrackId DEFAULT(MP4_INVALID_TRACK_ID) ); 127 | 128 | /** Get list of chapters. 129 | * 130 | * This function gets a chpter list from file hFile. 131 | * 132 | * @param hFile handle of file to read. 133 | * @param chapterList address receiving array of chapter items. 134 | * If a non-NULL is received the caller is responsible for freeing the 135 | * memory with MP4Free(). 136 | * @param chapterCount address receiving count of items in array. 137 | * @param chapterType the type of chapters to read: 138 | * @li #MP4ChapterTypeAny (any chapters, searched in order of Qt, Nero) 139 | * @li #MP4ChapterTypeQt 140 | * @li #MP4ChapterTypeNero 141 | * 142 | * @result the first type of chapters found. 143 | */ 144 | MP4V2_EXPORT 145 | MP4ChapterType MP4GetChapters( 146 | MP4FileHandle hFile, 147 | MP4Chapter_t** chapterList, 148 | uint32_t* chapterCount, 149 | MP4ChapterType chapterType DEFAULT(MP4ChapterTypeQt)); 150 | 151 | /** Set list of chapters OKOK. 152 | * 153 | * This functions sets the complete chapter list in file hFile. 154 | * If any chapters of the same type already exist they will first 155 | * be deleted. 156 | * 157 | * @param hFile handle of file to modify. 158 | * @param chapterList array of chapters items. 159 | * @param chapterCount count of items in array. 160 | * @param chapterType type of chapters to write: 161 | * @li #MP4ChapterTypeAny (chapters of all types are written) 162 | * @li #MP4ChapterTypeQt 163 | * @li #MP4ChapterTypeNero 164 | * 165 | * @return the type of chapters written. 166 | */ 167 | MP4V2_EXPORT 168 | MP4ChapterType MP4SetChapters( 169 | MP4FileHandle hFile, 170 | MP4Chapter_t* chapterList, 171 | uint32_t chapterCount, 172 | MP4ChapterType chapterType DEFAULT(MP4ChapterTypeQt)); 173 | 174 | /** @} ***********************************************************************/ 175 | 176 | #endif /* MP4V2_CHAPTER_H */ 177 | -------------------------------------------------------------------------------- /mp4v2/inc/file.h: -------------------------------------------------------------------------------- 1 | #ifndef MP4V2_FILE_H 2 | #define MP4V2_FILE_H 3 | 4 | /**************************************************************************//** 5 | * 6 | * @defgroup mp4_file MP4v2 File I/O 7 | * @{ 8 | * 9 | *****************************************************************************/ 10 | 11 | /** Bit: enable 64-bit data-atoms. */ 12 | #define MP4_CREATE_64BIT_DATA 0x01 13 | /** Bit: enable 64-bit time-atoms. @note Incompatible with QuickTime. */ 14 | #define MP4_CREATE_64BIT_TIME 0x02 15 | /** Bit: do not recompute avg/max bitrates on file close. @note See http://code.google.com/p/mp4v2/issues/detail?id=66 */ 16 | #define MP4_CLOSE_DO_NOT_COMPUTE_BITRATE 0x01 17 | 18 | /** Enumeration of file modes for custom file provider. */ 19 | typedef enum MP4FileMode_e 20 | { 21 | FILEMODE_UNDEFINED, /**< undefined */ 22 | FILEMODE_READ, /**< file may be read */ 23 | FILEMODE_MODIFY, /**< file may be read/written */ 24 | FILEMODE_CREATE /**< file will be created/truncated for read/write */ 25 | } MP4FileMode; 26 | 27 | /** Structure of functions implementing custom file provider. 28 | * 29 | * Except for open, all the functions must return a true value 30 | * to indicate failure or false on success. The open function must return 31 | * a pointer or handle which represents the open file, otherwise NULL. 32 | * 33 | * maxChunkSize is a hint suggesting what the max size of data should be read 34 | * as in underlying read/write operations. A value of 0 indicates there is no hint. 35 | */ 36 | typedef struct MP4FileProvider_s 37 | { 38 | void* ( *open )( const char* name, MP4FileMode mode ); 39 | int ( *seek )( void* handle, int64_t pos ); 40 | int ( *read )( void* handle, void* buffer, int64_t size, int64_t* nin, int64_t maxChunkSize ); 41 | int ( *write )( void* handle, const void* buffer, int64_t size, int64_t* nout, int64_t maxChunkSize ); 42 | int ( *close )( void* handle ); 43 | } MP4FileProvider; 44 | 45 | /** Close an mp4 file. 46 | * MP4Close closes a previously opened mp4 file. If the file was opened 47 | * writable with MP4Create() or MP4Modify(), then MP4Close() will write 48 | * out all pending information to disk. 49 | * 50 | * @param hFile handle of file to close. 51 | * @param flags bitmask that allows the user to set extra options for the 52 | * close commands. Valid options include: 53 | * @li #MP4_CLOSE_DO_NOT_COMPUTE_BITRATE 54 | */ 55 | MP4V2_EXPORT 56 | void MP4Close( 57 | MP4FileHandle hFile, 58 | uint32_t flags DEFAULT(0) ); 59 | 60 | /** Create a new mp4 file. 61 | * 62 | * MP4Create is the first call that should be used when you want to create 63 | * a new, empty mp4 file. It is equivalent to opening a file for writing, 64 | * but also involved with creation of necessary mp4 framework structures. 65 | * ie. invoking MP4Create() followed by MP4Close() will result in a file 66 | * with a non-zero size. 67 | * 68 | * @param fileName pathname of the file to be created. 69 | * On Windows, this should be a UTF-8 encoded string. 70 | * On other platforms, it should be an 8-bit encoding that is 71 | * appropriate for the platform, locale, file system, etc. 72 | * (prefer to use UTF-8 when possible). 73 | * @param flags bitmask that allows the user to set 64-bit values for 74 | * data or time atoms. Valid bits may be any combination of: 75 | * @li #MP4_CREATE_64BIT_DATA 76 | * @li #MP4_CREATE_64BIT_TIME 77 | * 78 | * @return On success a handle of the newly created file for use in 79 | * subsequent calls to the library. 80 | * On error, #MP4_INVALID_FILE_HANDLE. 81 | */ 82 | MP4V2_EXPORT 83 | MP4FileHandle MP4Create( 84 | const char* fileName, 85 | uint32_t flags DEFAULT(0) ); 86 | 87 | /** Create a new mp4 file with extended options. 88 | * 89 | * MP4CreateEx is an extended version of MP4Create(). 90 | * 91 | * @param fileName pathname of the file to be created. 92 | * On Windows, this should be a UTF-8 encoded string. 93 | * On other platforms, it should be an 8-bit encoding that is 94 | * appropriate for the platform, locale, file system, etc. 95 | * (prefer to use UTF-8 when possible). 96 | * @param flags bitmask that allows the user to set 64-bit values for 97 | * data or time atoms. Valid bits may be any combination of: 98 | * @li #MP4_CREATE_64BIT_DATA 99 | * @li #MP4_CREATE_64BIT_TIME 100 | * @param add_ftyp if true an ftyp atom is automatically created. 101 | * @param add_iods if true an iods atom is automatically created. 102 | * @param majorBrand ftyp brand identifier. 103 | * @param minorVersion ftyp informative integer for the minor version 104 | * of the major brand. 105 | * @param compatibleBrands ftyp list of compatible brands. 106 | * @param compatibleBrandsCount is the count of items specified in 107 | * compatibleBrands. 108 | * 109 | * @return On success a handle of the newly created file for use in 110 | * subsequent calls to the library. 111 | * On error, #MP4_INVALID_FILE_HANDLE. 112 | */ 113 | MP4V2_EXPORT 114 | MP4FileHandle MP4CreateEx( 115 | const char* fileName, 116 | uint32_t flags DEFAULT(0), 117 | int add_ftyp DEFAULT(1), 118 | int add_iods DEFAULT(1), 119 | char* majorBrand DEFAULT(0), 120 | uint32_t minorVersion DEFAULT(0), 121 | char** compatibleBrands DEFAULT(0), 122 | uint32_t compatibleBrandsCount DEFAULT(0) ); 123 | 124 | /** Dump mp4 file contents as ASCII either to stdout or the 125 | * log callback (@p see MP4SetLogCallback) 126 | * 127 | * Dump is an invaluable debugging tool in that in can reveal all the details 128 | * of the mp4 control structures. However, the output will not make much sense 129 | * until you familiarize yourself with the mp4 specification (or the Quicktime 130 | * File Format specification). 131 | * 132 | 133 | * Note that MP4Dump() will not print the individual values of control tables, 134 | * such as the size of each sample, unless the current log level is at least 135 | * #MP4_LOG_VERBOSE2. @p see MP4LogSetLevel() for how to set this. 136 | * 137 | * @param hFile handle of file to dump. 138 | * @param dumpImplicits prints properties which would not actually be 139 | * written to the mp4 file, but still exist in mp4 control structures. 140 | * ie. they are implicit given the current values of other controlling 141 | * properties. 142 | * 143 | * @return true on success, false on failure. 144 | */ 145 | MP4V2_EXPORT 146 | bool MP4Dump( 147 | MP4FileHandle hFile, 148 | bool dumpImplicits DEFAULT(0) ); 149 | 150 | /** Return a textual summary of an mp4 file. 151 | * 152 | * MP4FileInfo provides a string that contains a textual summary of the 153 | * contents of an mp4 file. This includes the track id's, the track type, 154 | * and track specific information. For example, for a video track, media 155 | * encoding, image size, frame rate, and bitrate are summarized. 156 | * 157 | * Note that the returned string is malloc'ed, so it is the caller's 158 | * responsibility to free() the string. Also note that the returned string 159 | * contains newlines and tabs which may or may not be desirable. 160 | * 161 | * The following is an example of the output of MP4Info(): 162 | @verbatim 163 | Track Type Info 164 | 1 video MPEG-4 Simple @ L3, 119.625 secs, 1008 kbps, 352x288 @ 24.00 fps 165 | 2 audio MPEG-4, 119.327 secs, 128 kbps, 44100 Hz 166 | 3 hint Payload MP4V-ES for track 1 167 | 4 hint Payload mpeg4-generic for track 2 168 | 5 od Object Descriptors 169 | 6 scene BIFS 170 | @endverbatim 171 | * 172 | * @param fileName pathname to mp4 file to summarize. 173 | * On Windows, this should be a UTF-8 encoded string. 174 | * On other platforms, it should be an 8-bit encoding that is 175 | * appropriate for the platform, locale, file system, etc. 176 | * (prefer to use UTF-8 when possible). 177 | * @param trackId specifies track to summarize. If the value is 178 | * #MP4_INVALID_TRACK_ID, the summary info is created for all 179 | * tracks in the file. 180 | * 181 | * @return On success a malloc'd string containing summary information. 182 | * On failure, NULL. 183 | * 184 | * @see MP4Info(). 185 | */ 186 | MP4V2_EXPORT 187 | char* MP4FileInfo( 188 | const char* fileName, 189 | MP4TrackId trackId DEFAULT(MP4_INVALID_TRACK_ID) ); 190 | 191 | /** Accessor for the filename associated with a file handle 192 | * 193 | * @param hFile a file handle 194 | * 195 | * @return the NUL-terminated, UTF-8 encoded filename 196 | * associated with @p hFile 197 | */ 198 | MP4V2_EXPORT 199 | const char* MP4GetFilename( 200 | MP4FileHandle hFile ); 201 | 202 | /** Return a textual summary of an mp4 file. 203 | * 204 | * MP4FileInfo provides a string that contains a textual summary of the 205 | * contents of an mp4 file. This includes the track id's, the track type, 206 | * and track specific information. For example, for a video track, media 207 | * encoding, image size, frame rate, and bitrate are summarized. 208 | * 209 | * Note that the returned string is malloc'ed, so it is the caller's 210 | * responsibility to free() the string. Also note that the returned string 211 | * contains newlines and tabs which may or may not be desirable. 212 | * 213 | * The following is an example of the output of MP4Info(): 214 | @verbatim 215 | Track Type Info 216 | 1 video MPEG-4 Simple @ L3, 119.625 secs, 1008 kbps, 352x288 @ 24.00 fps 217 | 2 audio MPEG-4, 119.327 secs, 128 kbps, 44100 Hz 218 | 3 hint Payload MP4V-ES for track 1 219 | 4 hint Payload mpeg4-generic for track 2 220 | 5 od Object Descriptors 221 | 6 scene BIFS 222 | @endverbatim 223 | * 224 | * @param hFile handle of file to summarize. 225 | * @param trackId specifies track to summarize. If the value is 226 | * #MP4_INVALID_TRACK_ID, the summary info is created for all 227 | * tracks in the file. 228 | * 229 | * @return On success a malloc'd string containing summary information. 230 | * On failure, NULL. 231 | * 232 | * @see MP4FileInfo(). 233 | */ 234 | MP4V2_EXPORT 235 | char* MP4Info( 236 | MP4FileHandle hFile, 237 | MP4TrackId trackId DEFAULT(MP4_INVALID_TRACK_ID) ); 238 | 239 | /** Modify an existing mp4 file. 240 | * 241 | * MP4Modify is the first call that should be used when you want to modify 242 | * an existing mp4 file. It is roughly equivalent to opening a file in 243 | * read/write mode. 244 | * 245 | * Since modifications to an existing mp4 file can result in a sub-optimal 246 | * file layout, you may want to use MP4Optimize() after you have modified 247 | * and closed the mp4 file. 248 | * 249 | * @param fileName pathname of the file to be modified. 250 | * On Windows, this should be a UTF-8 encoded string. 251 | * On other platforms, it should be an 8-bit encoding that is 252 | * appropriate for the platform, locale, file system, etc. 253 | * (prefer to use UTF-8 when possible). 254 | * @param flags currently ignored. 255 | * 256 | * @return On success a handle of the target file for use in subsequent calls 257 | * to the library. 258 | * On error, #MP4_INVALID_FILE_HANDLE. 259 | */ 260 | MP4V2_EXPORT 261 | MP4FileHandle MP4Modify( 262 | const char* fileName, 263 | uint32_t flags DEFAULT(0) ); 264 | 265 | /** Optimize the layout of an mp4 file. 266 | * 267 | * MP4Optimize reads an existing mp4 file and writes a new version of the 268 | * file with the two important changes: 269 | * 270 | * First, the mp4 control information is moved to the beginning of the file. 271 | * (Frequenty it is at the end of the file due to it being constantly 272 | * modified as track samples are added to an mp4 file). This optimization 273 | * is useful in that in allows the mp4 file to be HTTP streamed. 274 | * 275 | * Second, the track samples are interleaved so that the samples for a 276 | * particular instant in time are colocated within the file. This 277 | * eliminates disk seeks during playback of the file which results in 278 | * better performance. 279 | * 280 | * There are also two important side effects of MP4Optimize(): 281 | * 282 | * First, any free blocks within the mp4 file are eliminated. 283 | * 284 | * Second, as a side effect of the sample interleaving process any media 285 | * data chunks that are not actually referenced by the mp4 control 286 | * structures are deleted. This is useful if you have called MP4DeleteTrack() 287 | * which only deletes the control information for a track, and not the 288 | * actual media data. 289 | * 290 | * @param fileName pathname of (existing) file to be optimized. 291 | * On Windows, this should be a UTF-8 encoded string. 292 | * On other platforms, it should be an 8-bit encoding that is 293 | * appropriate for the platform, locale, file system, etc. 294 | * (prefer to use UTF-8 when possible). 295 | * @param newFileName pathname of the new optimized file. 296 | * On Windows, this should be a UTF-8 encoded string. 297 | * On other platforms, it should be an 8-bit encoding that is 298 | * appropriate for the platform, locale, file system, etc. 299 | * (prefer to use UTF-8 when possible). 300 | * If NULL a temporary file in the same directory as the 301 | * fileName will be used and fileName 302 | * will be over-written upon successful completion. 303 | * 304 | * @return true on success, false on failure. 305 | */ 306 | MP4V2_EXPORT 307 | bool MP4Optimize( 308 | const char* fileName, 309 | const char* newFileName DEFAULT(NULL) ); 310 | 311 | 312 | /** Read an existing mp4 file. 313 | * 314 | * MP4Read is the first call that should be used when you want to just 315 | * read an existing mp4 file. It is equivalent to opening a file for 316 | * reading, but in addition the mp4 file is parsed and the control 317 | * information is loaded into memory. Note that actual track samples are not 318 | * read into memory until MP4ReadSample() is called. 319 | * 320 | * @param fileName pathname of the file to be read. 321 | * On Windows, this should be a UTF-8 encoded string. 322 | * On other platforms, it should be an 8-bit encoding that is 323 | * appropriate for the platform, locale, file system, etc. 324 | * (prefer to use UTF-8 when possible). 325 | ( 326 | * @return On success a handle of the file for use in subsequent calls to 327 | * the library. 328 | * On error, #MP4_INVALID_FILE_HANDLE. 329 | */ 330 | MP4V2_EXPORT 331 | MP4FileHandle MP4Read( 332 | const char* fileName ); 333 | 334 | /** Read an existing mp4 file. 335 | * 336 | * MP4ReadProvider is the first call that should be used when you want to just 337 | * read an existing mp4 file. It is equivalent to opening a file for 338 | * reading, but in addition the mp4 file is parsed and the control 339 | * information is loaded into memory. Note that actual track samples are not 340 | * read into memory until MP4ReadSample() is called. 341 | * 342 | * @param fileName pathname of the file to be read. 343 | * On Windows, this should be a UTF-8 encoded string. 344 | * On other platforms, it should be an 8-bit encoding that is 345 | * appropriate for the platform, locale, file system, etc. 346 | * (prefer to use UTF-8 when possible). 347 | * @param fileProvider custom implementation of file I/O operations. 348 | * All functions in structure must be implemented. 349 | * The structure is immediately copied internally. 350 | * 351 | * @return On success a handle of the file for use in subsequent calls to 352 | * the library. 353 | * On error, #MP4_INVALID_FILE_HANDLE. 354 | */ 355 | MP4V2_EXPORT 356 | MP4FileHandle MP4ReadProvider( 357 | const char* fileName, 358 | const MP4FileProvider* fileProvider DEFAULT(NULL) ); 359 | 360 | /** @} ***********************************************************************/ 361 | 362 | #endif /* MP4V2_FILE_H */ 363 | -------------------------------------------------------------------------------- /mp4v2/inc/file_prop.h: -------------------------------------------------------------------------------- 1 | #ifndef MP4V2_FILE_PROP_H 2 | #define MP4V2_FILE_PROP_H 3 | 4 | /**************************************************************************//** 5 | * 6 | * @defgroup mp4_file_prop MP4v2 File Property 7 | * @{ 8 | * 9 | *****************************************************************************/ 10 | 11 | /* generic props */ 12 | 13 | MP4V2_EXPORT 14 | bool MP4HaveAtom( 15 | MP4FileHandle hFile, 16 | const char* atomName ); 17 | 18 | MP4V2_EXPORT 19 | bool MP4GetIntegerProperty( 20 | MP4FileHandle hFile, 21 | const char* propName, 22 | uint64_t* retval ); 23 | 24 | MP4V2_EXPORT 25 | bool MP4GetFloatProperty( 26 | MP4FileHandle hFile, 27 | const char* propName, 28 | float* retvalue ); 29 | 30 | MP4V2_EXPORT 31 | bool MP4GetStringProperty( 32 | MP4FileHandle hFile, 33 | const char* propName, 34 | const char** retvalue ); 35 | 36 | MP4V2_EXPORT 37 | bool MP4GetBytesProperty( 38 | MP4FileHandle hFile, 39 | const char* propName, 40 | uint8_t** ppValue, 41 | uint32_t* pValueSize ); 42 | 43 | MP4V2_EXPORT 44 | bool MP4SetIntegerProperty( 45 | MP4FileHandle hFile, 46 | const char* propName, 47 | int64_t value ); 48 | 49 | MP4V2_EXPORT 50 | bool MP4SetFloatProperty( 51 | MP4FileHandle hFile, 52 | const char* propName, 53 | float value ); 54 | 55 | MP4V2_EXPORT 56 | bool MP4SetStringProperty( 57 | MP4FileHandle hFile, 58 | const char* propName, 59 | const char* value ); 60 | 61 | MP4V2_EXPORT 62 | bool MP4SetBytesProperty( 63 | MP4FileHandle hFile, 64 | const char* propName, 65 | const uint8_t* pValue, 66 | uint32_t valueSize ); 67 | 68 | /* specific props */ 69 | 70 | MP4V2_EXPORT 71 | MP4Duration MP4GetDuration( MP4FileHandle hFile ); 72 | 73 | /** Get the time scale of the movie (file). 74 | * 75 | * MP4GetTimeScale returns the time scale in units of ticks per second for 76 | * the mp4 file. Caveat: tracks may use the same time scale as the movie 77 | * or may use their own time scale. 78 | * 79 | * @param hFile handle of file for operation. 80 | * 81 | * @return timescale (ticks per second) of the mp4 file. 82 | */ 83 | MP4V2_EXPORT 84 | uint32_t MP4GetTimeScale( MP4FileHandle hFile ); 85 | 86 | /** Set the time scale of the movie (file). 87 | * 88 | * MP4SetTimeScale sets the time scale of the mp4 file. The time scale is 89 | * in the number of clock ticks per second. Caveat: tracks may use the 90 | * same time scale as the movie or may use their own time scale. 91 | * 92 | * @param hFile handle of file for operation. 93 | * @param value desired timescale for the movie. 94 | * 95 | * @return On success, true. On failure, false. 96 | */ 97 | MP4V2_EXPORT 98 | bool MP4SetTimeScale( MP4FileHandle hFile, uint32_t value ); 99 | 100 | /** Change the general timescale of file hFile. 101 | * 102 | * This function changes the general timescale of the file hFile 103 | * to the new timescale value by recalculating all values that depend 104 | * on the timescale in "moov.mvhd". 105 | * 106 | * If the timescale is already equal to value nothing is done. 107 | * 108 | * @param hFile handle of file to change. 109 | * @param value the new timescale. 110 | */ 111 | MP4V2_EXPORT 112 | void MP4ChangeMovieTimeScale( MP4FileHandle hFile, uint32_t value ); 113 | 114 | MP4V2_EXPORT 115 | uint8_t MP4GetODProfileLevel( MP4FileHandle hFile ); 116 | 117 | MP4V2_EXPORT 118 | bool MP4SetODProfileLevel( MP4FileHandle hFile, uint8_t value ); 119 | 120 | MP4V2_EXPORT 121 | uint8_t MP4GetSceneProfileLevel( MP4FileHandle hFile ); 122 | 123 | MP4V2_EXPORT 124 | bool MP4SetSceneProfileLevel( MP4FileHandle hFile, uint8_t value ); 125 | 126 | MP4V2_EXPORT 127 | uint8_t MP4GetVideoProfileLevel( 128 | MP4FileHandle hFile, 129 | MP4TrackId trackId DEFAULT(MP4_INVALID_TRACK_ID) ); 130 | 131 | MP4V2_EXPORT 132 | void MP4SetVideoProfileLevel( MP4FileHandle hFile, uint8_t value ); 133 | 134 | MP4V2_EXPORT 135 | uint8_t MP4GetAudioProfileLevel( MP4FileHandle hFile ); 136 | 137 | MP4V2_EXPORT 138 | void MP4SetAudioProfileLevel( MP4FileHandle hFile, uint8_t value ); 139 | 140 | MP4V2_EXPORT 141 | uint8_t MP4GetGraphicsProfileLevel( MP4FileHandle hFile ); 142 | 143 | MP4V2_EXPORT 144 | bool MP4SetGraphicsProfileLevel( MP4FileHandle hFile, uint8_t value ); 145 | 146 | /** @} ***********************************************************************/ 147 | 148 | #endif /* MP4V2_FILE_PROP_H */ 149 | -------------------------------------------------------------------------------- /mp4v2/inc/general.h: -------------------------------------------------------------------------------- 1 | #ifndef MP4V2_GENERAL_H 2 | #define MP4V2_GENERAL_H 3 | 4 | /**************************************************************************//** 5 | * 6 | * @defgroup mp4_general MP4v2 General 7 | * @{ 8 | * 9 | *****************************************************************************/ 10 | 11 | /* MP4 API types */ 12 | typedef void* MP4FileHandle; 13 | typedef uint32_t MP4TrackId; 14 | typedef uint32_t MP4SampleId; 15 | typedef uint64_t MP4Timestamp; 16 | typedef uint64_t MP4Duration; 17 | typedef uint32_t MP4EditId; 18 | 19 | typedef enum { 20 | MP4_LOG_NONE = 0, 21 | MP4_LOG_ERROR = 1, 22 | MP4_LOG_WARNING = 2, 23 | MP4_LOG_INFO = 3, 24 | MP4_LOG_VERBOSE1 = 4, 25 | MP4_LOG_VERBOSE2 = 5, 26 | MP4_LOG_VERBOSE3 = 6, 27 | MP4_LOG_VERBOSE4 = 7 28 | } MP4LogLevel; 29 | 30 | /*****************************************************************************/ 31 | 32 | typedef void (*MP4LogCallback)( 33 | MP4LogLevel loglevel, 34 | const char* fmt, 35 | va_list ap ); 36 | 37 | /*****************************************************************************/ 38 | 39 | /** Encryption function pointer. 40 | * 41 | * @see MP4EncAndCopySample(). 42 | * @see MP4EncAndCopyTrack(). 43 | */ 44 | typedef uint32_t (*encryptFunc_t)( uint32_t, uint32_t, uint8_t*, uint32_t*, uint8_t** ); 45 | 46 | /*****************************************************************************/ 47 | 48 | #define MP4_INVALID_FILE_HANDLE ((MP4FileHandle)NULL) /**< Constant: invalid MP4FileHandle. */ 49 | #define MP4_INVALID_TRACK_ID ((MP4TrackId)0) /**< Constant: invalid MP4TrackId. */ 50 | #define MP4_INVALID_SAMPLE_ID ((MP4SampleId)0) /**< Constant: invalid MP4SampleId. */ 51 | #define MP4_INVALID_TIMESTAMP ((MP4Timestamp)-1) /**< Constant: invalid MP4Timestamp. */ 52 | #define MP4_INVALID_DURATION ((MP4Duration)-1) /**< Constant: invalid MP4Duration. */ 53 | #define MP4_INVALID_EDIT_ID ((MP4EditId)0) /**< Constant: invalid MP4EditId. */ 54 | 55 | /* Macros to test for API type validity */ 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) 62 | 63 | /* 64 | * MP4 Known track type names - e.g. MP4GetNumberOfTracks(type) 65 | * 66 | * Note this first group of track types should be created 67 | * via the MP4AddTrack() functions, and not MP4AddTrack(type) 68 | */ 69 | #define MP4_OD_TRACK_TYPE "odsm" /**< Constant: OD track. */ 70 | #define MP4_SCENE_TRACK_TYPE "sdsm" /**< Constant: scene track. */ 71 | #define MP4_AUDIO_TRACK_TYPE "soun" /**< Constant: audio track. */ 72 | #define MP4_VIDEO_TRACK_TYPE "vide" /**< Constant: video track. */ 73 | #define MP4_HINT_TRACK_TYPE "hint" /**< Constant: hint track. */ 74 | #define MP4_CNTL_TRACK_TYPE "cntl" /**< Constant: control track. */ 75 | #define MP4_TEXT_TRACK_TYPE "text" /**< Constant: text track. */ 76 | #define MP4_SUBTITLE_TRACK_TYPE "sbtl" /**< Constant: subtitle track. */ 77 | #define MP4_SUBPIC_TRACK_TYPE "subp" /**< Constant: subpic track. */ 78 | /* 79 | * This second set of track types should be created 80 | * via MP4AddSystemsTrack(type) 81 | */ 82 | #define MP4_CLOCK_TRACK_TYPE "crsm" /**< Constant: clock track. */ 83 | #define MP4_MPEG7_TRACK_TYPE "m7sm" /**< Constant: mpeg7 track. */ 84 | #define MP4_OCI_TRACK_TYPE "ocsm" /**< Constant: OCI track. */ 85 | #define MP4_IPMP_TRACK_TYPE "ipsm" /**< Constant: IPMP track. */ 86 | #define MP4_MPEGJ_TRACK_TYPE "mjsm" /**< Constant: MPEGJ track. */ 87 | 88 | #define MP4_IS_VIDEO_TRACK_TYPE(type) \ 89 | (!strcasecmp(type, MP4_VIDEO_TRACK_TYPE)) 90 | 91 | #define MP4_IS_AUDIO_TRACK_TYPE(type) \ 92 | (!strcasecmp(type, MP4_AUDIO_TRACK_TYPE)) 93 | 94 | #define MP4_IS_CNTL_TRACK_TYPE(type) \ 95 | (!strcasecmp(type, MP4_CNTL_TRACK_TYPE)) 96 | 97 | #define MP4_IS_OD_TRACK_TYPE(type) \ 98 | (!strcasecmp(type, MP4_OD_TRACK_TYPE)) 99 | 100 | #define MP4_IS_SCENE_TRACK_TYPE(type) \ 101 | (!strcasecmp(type, MP4_SCENE_TRACK_TYPE)) 102 | 103 | #define MP4_IS_HINT_TRACK_TYPE(type) \ 104 | (!strcasecmp(type, MP4_HINT_TRACK_TYPE)) 105 | 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)) 112 | 113 | /* MP4 Audio track types - see MP4AddAudioTrack()*/ 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 /* a private definition */ 125 | #define MP4_VORBIS_AUDIO_TYPE 0xE1 /* a private definition */ 126 | #define MP4_AC3_AUDIO_TYPE 0xE2 /* a private definition */ 127 | #define MP4_ALAW_AUDIO_TYPE 0xE3 /* a private definition */ 128 | #define MP4_ULAW_AUDIO_TYPE 0xE4 /* a private definition */ 129 | #define MP4_G723_AUDIO_TYPE 0xE5 /* a private definition */ 130 | #define MP4_PCM16_BIG_ENDIAN_AUDIO_TYPE 0xE6 /* a private definition */ 131 | 132 | /* MP4 MPEG-4 Audio types from 14496-3 Table 1.5.1 */ 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 152 | 153 | /* MP4 Audio type utilities following common usage */ 154 | #define MP4_IS_MP3_AUDIO_TYPE(type) \ 155 | ((type) == MP4_MPEG1_AUDIO_TYPE || (type) == MP4_MPEG2_AUDIO_TYPE) 156 | 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)) 160 | 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) 166 | 167 | #define MP4_IS_AAC_AUDIO_TYPE(type) \ 168 | (MP4_IS_MPEG2_AAC_AUDIO_TYPE(type) \ 169 | || (type) == MP4_MPEG4_AUDIO_TYPE) 170 | 171 | /* MP4 Video track types - see MP4AddVideoTrack() */ 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 /* a private definition */ 185 | #define MP4_H263_VIDEO_TYPE 0xF2 /* a private definition */ 186 | #define MP4_H261_VIDEO_TYPE 0xF3 /* a private definition */ 187 | 188 | /* MP4 Video type utilities */ 189 | #define MP4_IS_MPEG1_VIDEO_TYPE(type) \ 190 | ((type) == MP4_MPEG1_VIDEO_TYPE) 191 | 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)) 196 | 197 | #define MP4_IS_MPEG4_VIDEO_TYPE(type) \ 198 | ((type) == MP4_MPEG4_VIDEO_TYPE) 199 | 200 | /* Mpeg4 Visual Profile Defines - ISO/IEC 14496-2:2001/Amd.2:2002(E) */ 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) 259 | 260 | /*****************************************************************************/ 261 | 262 | /* 3GP specific utilities */ 263 | 264 | MP4V2_EXPORT 265 | bool 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) ); 272 | 273 | /* NOTE this section of functionality has not yet been fully tested */ 274 | 275 | MP4V2_EXPORT 276 | MP4EditId MP4AddTrackEdit( 277 | MP4FileHandle hFile, 278 | MP4TrackId trackId, 279 | MP4EditId editId DEFAULT(MP4_INVALID_EDIT_ID), 280 | MP4Timestamp startTime DEFAULT(0), 281 | MP4Duration duration DEFAULT(0), 282 | bool dwell DEFAULT(false) ); 283 | 284 | MP4V2_EXPORT 285 | bool MP4DeleteTrackEdit( 286 | MP4FileHandle hFile, 287 | MP4TrackId trackId, 288 | MP4EditId editId ); 289 | 290 | MP4V2_EXPORT 291 | uint32_t MP4GetTrackNumberOfEdits( 292 | MP4FileHandle hFile, 293 | MP4TrackId trackId ); 294 | 295 | MP4V2_EXPORT 296 | MP4Timestamp MP4GetTrackEditStart( 297 | MP4FileHandle hFile, 298 | MP4TrackId trackId, 299 | MP4EditId editId ); 300 | 301 | MP4V2_EXPORT 302 | MP4Duration MP4GetTrackEditTotalDuration( 303 | MP4FileHandle hFile, 304 | MP4TrackId trackId, 305 | MP4EditId editId DEFAULT(MP4_INVALID_EDIT_ID) ); 306 | 307 | MP4V2_EXPORT 308 | MP4Timestamp MP4GetTrackEditMediaStart( 309 | MP4FileHandle hFile, 310 | MP4TrackId trackId, 311 | MP4EditId editId ); 312 | 313 | MP4V2_EXPORT 314 | bool MP4SetTrackEditMediaStart( 315 | MP4FileHandle hFile, 316 | MP4TrackId trackId, 317 | MP4EditId editId, 318 | MP4Timestamp startTime ); 319 | 320 | MP4V2_EXPORT 321 | MP4Duration MP4GetTrackEditDuration( 322 | MP4FileHandle hFile, 323 | MP4TrackId trackId, 324 | MP4EditId editId ); 325 | 326 | MP4V2_EXPORT 327 | bool MP4SetTrackEditDuration( 328 | MP4FileHandle hFile, 329 | MP4TrackId trackId, 330 | MP4EditId editId, 331 | MP4Duration duration ); 332 | 333 | MP4V2_EXPORT 334 | int8_t MP4GetTrackEditDwell( 335 | MP4FileHandle hFile, 336 | MP4TrackId trackId, 337 | MP4EditId editId ); 338 | 339 | MP4V2_EXPORT 340 | bool MP4SetTrackEditDwell( 341 | MP4FileHandle hFile, 342 | MP4TrackId trackId, 343 | MP4EditId editId, 344 | bool dwell ); 345 | 346 | MP4V2_EXPORT 347 | bool MP4ReadSampleFromEditTime( 348 | /* input parameters */ 349 | MP4FileHandle hFile, 350 | MP4TrackId trackId, 351 | MP4Timestamp when, 352 | /* input/output parameters */ 353 | uint8_t** ppBytes, 354 | uint32_t* pNumBytes, 355 | /* output parameters */ 356 | MP4Timestamp* pStartTime DEFAULT(NULL), 357 | MP4Duration* pDuration DEFAULT(NULL), 358 | MP4Duration* pRenderingOffset DEFAULT(NULL), 359 | bool* pIsSyncSample DEFAULT(NULL) ); 360 | 361 | MP4V2_EXPORT 362 | MP4SampleId MP4GetSampleIdFromEditTime( 363 | MP4FileHandle hFile, 364 | MP4TrackId trackId, 365 | MP4Timestamp when, 366 | MP4Timestamp* pStartTime DEFAULT(NULL), 367 | MP4Duration* pDuration DEFAULT(NULL) ); 368 | 369 | /* time conversion utilties */ 370 | 371 | /* predefined values for timeScale parameter below */ 372 | #define MP4_SECONDS_TIME_SCALE 1 373 | #define MP4_MILLISECONDS_TIME_SCALE 1000 374 | #define MP4_MICROSECONDS_TIME_SCALE 1000000 375 | #define MP4_NANOSECONDS_TIME_SCALE 1000000000 376 | 377 | #define MP4_SECS_TIME_SCALE MP4_SECONDS_TIME_SCALE 378 | #define MP4_MSECS_TIME_SCALE MP4_MILLISECONDS_TIME_SCALE 379 | #define MP4_USECS_TIME_SCALE MP4_MICROSECONDS_TIME_SCALE 380 | #define MP4_NSECS_TIME_SCALE MP4_NANOSECONDS_TIME_SCALE 381 | 382 | MP4V2_EXPORT 383 | uint64_t MP4ConvertFromMovieDuration( 384 | MP4FileHandle hFile, 385 | MP4Duration duration, 386 | uint32_t timeScale ); 387 | 388 | MP4V2_EXPORT 389 | uint64_t MP4ConvertFromTrackTimestamp( 390 | MP4FileHandle hFile, 391 | MP4TrackId trackId, 392 | MP4Timestamp timeStamp, 393 | uint32_t timeScale ); 394 | 395 | MP4V2_EXPORT 396 | MP4Timestamp MP4ConvertToTrackTimestamp( 397 | MP4FileHandle hFile, 398 | MP4TrackId trackId, 399 | uint64_t timeStamp, 400 | uint32_t timeScale ); 401 | 402 | /** Convert duration from track time scale to an arbitrary time scale. 403 | * 404 | * MP4ConvertFromTrackDuration converts a duration such as a sample duration 405 | * from the track time scale to another time scale. This can be used by a 406 | * player application to map all track samples to a common time scale. 407 | * 408 | * @param hFile handle of file for operation. 409 | * @param trackId id of track for operation. 410 | * @param duration value to be converted. 411 | * @param timeScale time scale in ticks per second. 412 | * 413 | * @return On success, the duration in arbitrary time scale units. 414 | * On error, 0. 415 | * 416 | * @see MP4GetSampleDuration(). 417 | * @see MP4ConvertToTrackDuration(). 418 | */ 419 | MP4V2_EXPORT 420 | uint64_t MP4ConvertFromTrackDuration( 421 | MP4FileHandle hFile, 422 | MP4TrackId trackId, 423 | MP4Duration duration, 424 | uint32_t timeScale ); 425 | 426 | /** Convert duration from arbitrary time scale to track time scale. 427 | * 428 | * MP4ConvertToTrackDuration converts a duration such as a sample duration 429 | * from the specified time scale to the track time scale. 430 | * 431 | * @param hFile handle of file for operation. 432 | * @param trackId id of track for operation. 433 | * @param duration value to be converted. 434 | * @param timeScale time scale in ticks per second. 435 | * 436 | * @return On success, the duration in track time scale units. 437 | * On error, #MP4_INVALID_DURATION. 438 | * 439 | * @see MP4ConvertFromTrackDuration(). 440 | */ 441 | MP4V2_EXPORT 442 | MP4Duration MP4ConvertToTrackDuration( 443 | MP4FileHandle hFile, 444 | MP4TrackId trackId, 445 | uint64_t duration, 446 | uint32_t timeScale ); 447 | 448 | MP4V2_EXPORT 449 | char* MP4BinaryToBase16( 450 | const uint8_t* pData, 451 | uint32_t dataSize ); 452 | 453 | MP4V2_EXPORT 454 | char* MP4BinaryToBase64( 455 | const uint8_t* pData, 456 | uint32_t dataSize ); 457 | 458 | MP4V2_EXPORT 459 | uint8_t* Base64ToBinary( 460 | const char* pData, 461 | uint32_t decodeSize, 462 | uint32_t* pDataSize ); 463 | 464 | MP4V2_EXPORT 465 | void MP4Free( 466 | void* p ); 467 | 468 | /** Set the function to call in place of default logging behavior 469 | * 470 | * @param cb_func the function to call 471 | */ 472 | MP4V2_EXPORT 473 | void MP4SetLogCallback( 474 | MP4LogCallback cb_func ); 475 | /** @} ***********************************************************************/ 476 | 477 | /** 478 | * Accessor for the maximum level for diagnostic information 479 | * 480 | * @return the maximum level for diagnostic information 481 | * 482 | * @see MP4LogSetLevel() for further details. 483 | */ 484 | MP4V2_EXPORT 485 | MP4LogLevel MP4LogGetLevel( void ); 486 | 487 | /** 488 | * Set the maximum level for diagnostic information 489 | * 490 | * @param verbosity the level to set 491 | */ 492 | MP4V2_EXPORT 493 | void MP4LogSetLevel( MP4LogLevel verbosity ); 494 | 495 | #endif /* MP4V2_GENERAL_H */ 496 | -------------------------------------------------------------------------------- /mp4v2/inc/isma.h: -------------------------------------------------------------------------------- 1 | #ifndef MP4V2_ISMA_H 2 | #define MP4V2_ISMA_H 3 | 4 | /**************************************************************************//** 5 | * 6 | * @defgroup mp4_isma MP4v2 ISMA (Internet Streaming Media Alliance) 7 | * @{ 8 | * 9 | *****************************************************************************/ 10 | 11 | /** something */ 12 | typedef struct mp4v2_ismacryp_session_params { 13 | uint32_t scheme_type; 14 | uint16_t scheme_version; 15 | uint8_t key_ind_len; 16 | uint8_t iv_len; 17 | uint8_t selective_enc; 18 | const char* kms_uri; 19 | } mp4v2_ismacrypParams; 20 | 21 | /* 22 | * API to initialize ismacryp properties to sensible defaults 23 | * if input param is null then mallocs a params struct 24 | */ 25 | 26 | MP4V2_EXPORT 27 | mp4v2_ismacrypParams* MP4DefaultISMACrypParams( mp4v2_ismacrypParams* ptr ); 28 | 29 | MP4V2_EXPORT 30 | MP4TrackId MP4AddEncAudioTrack( 31 | MP4FileHandle hFile, 32 | uint32_t timeScale, 33 | MP4Duration sampleDuration, 34 | mp4v2_ismacrypParams* icPp, 35 | uint8_t audioType DEFAULT(MP4_MPEG4_AUDIO_TYPE) ); 36 | 37 | MP4V2_EXPORT 38 | MP4TrackId MP4AddEncVideoTrack( 39 | MP4FileHandle hFile, 40 | uint32_t timeScale, 41 | MP4Duration sampleDuration, 42 | uint16_t width, 43 | uint16_t height, 44 | mp4v2_ismacrypParams* icPp, 45 | uint8_t videoType DEFAULT(MP4_MPEG4_VIDEO_TYPE), 46 | const char* oFormat DEFAULT(NULL) ); 47 | 48 | MP4V2_EXPORT 49 | MP4TrackId MP4AddEncH264VideoTrack( 50 | MP4FileHandle dstFile, 51 | uint32_t timeScale, 52 | MP4Duration sampleDuration, 53 | uint16_t width, 54 | uint16_t height, 55 | MP4FileHandle srcFile, 56 | MP4TrackId srcTrackId, 57 | mp4v2_ismacrypParams* icPp ); 58 | 59 | MP4V2_EXPORT 60 | MP4TrackId MP4EncAndCloneTrack( 61 | MP4FileHandle srcFile, 62 | MP4TrackId srcTrackId, 63 | mp4v2_ismacrypParams* icPp, 64 | MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE), 65 | MP4TrackId dstHintTrackReferenceTrack DEFAULT(MP4_INVALID_TRACK_ID) ); 66 | 67 | MP4V2_EXPORT 68 | MP4TrackId MP4EncAndCopyTrack( 69 | MP4FileHandle srcFile, 70 | MP4TrackId srcTrackId, 71 | mp4v2_ismacrypParams* icPp, 72 | encryptFunc_t encfcnp, 73 | uint32_t encfcnparam1, 74 | MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE), 75 | bool applyEdits DEFAULT(false), 76 | MP4TrackId dstHintTrackReferenceTrack DEFAULT(MP4_INVALID_TRACK_ID) ); 77 | 78 | MP4V2_EXPORT 79 | bool MP4MakeIsmaCompliant( 80 | const char* fileName, 81 | bool addIsmaComplianceSdp DEFAULT(true) ); 82 | 83 | MP4V2_EXPORT 84 | char* MP4MakeIsmaSdpIod( 85 | uint8_t videoProfile, 86 | uint32_t videoBitrate, 87 | uint8_t* videoConfig, 88 | uint32_t videoConfigLength, 89 | uint8_t audioProfile, 90 | uint32_t audioBitrate, 91 | uint8_t* audioConfig, 92 | uint32_t audioConfigLength ); 93 | 94 | /** @} ***********************************************************************/ 95 | 96 | #endif /* MP4V2_ISMA_H */ 97 | -------------------------------------------------------------------------------- /mp4v2/inc/itmf_generic.h: -------------------------------------------------------------------------------- 1 | #ifndef MP4V2_ITMF_GENERIC_H 2 | #define MP4V2_ITMF_GENERIC_H 3 | 4 | /**************************************************************************//** 5 | * 6 | * @defgroup mp4_itmf_generic MP4v2 iTMF (iTunes Metadata Format) Generic 7 | * @{ 8 | * 9 | * This is a low-level API used to manage iTMF metadata. 10 | * 11 | * It provides support for virtually any kind of iTMF metadata item, 12 | * including meaning atoms, sometimes referred to as reverse-DNS meanings. 13 | * Structures are directly modified; ie: there are no fuctions which 14 | * modify values for you. There is little type-safety, logic checks, or 15 | * specifications compliance checks. For these reasons it is recommended 16 | * to use iTMF Tags API when possible. 17 | * 18 | * At the heart of this API is an #MP4ItmfItem which corresponds to an 19 | * iTMF metadata item atom. The item, and any recursive data structures 20 | * contained within require manual memory management. The general 21 | * rule to follow is that you must always check/free a ptr if you intend 22 | * to resize data. In cases where you know the existing data size is 23 | * exactly what is needed, you may overwrite the buffer contents. 24 | * 25 | * Each item always has at least 1 data elements which corresponds to 26 | * a data atom. Additionally, each item has optional mean and 27 | * name values which correspond to mean and name atoms. 28 | * 29 | * Each #MP4ItmfItem has a list of #MP4ItmfData. Similarily, care must 30 | * be taken to manage memory with one key difference; these structures 31 | * also have a valueSize field. If value is NULL then set valueSize=0. 32 | * Otherwise, set valueSize to the size (in bytes) of value buffer. 33 | * 34 | * In rare cases where the number of data elements in a single item 35 | * is > 1, the user must manually free/alloc/copy the elements 36 | * buffer and update size accordingly. 37 | * 38 | * The mp4 file structure is modified only when MP4AddItem(), 39 | * MP4SetItem() and MP4RemoveItem() are used. Simply free'ing 40 | * the item list does not modify the mp4 file. 41 | * 42 | * iTMF Generic read workflow: 43 | * 44 | * @li MP4ItmfGetItems() 45 | * @li inspect each item... 46 | * @li MP4ItmfItemListFree() 47 | * 48 | * iTMF Generic read/modify/remove workflow: 49 | * 50 | * @li MP4ItmfGetItems() 51 | * @li inspect/modify item... 52 | * @li MP4ItmfSetItem() each modified item... 53 | * @li MP4ItmfRemoveItem()... 54 | * @li MP4ItmfItemListFree() 55 | * 56 | * iTMF Generic add workflow: 57 | * 58 | * @li MP4ItmfItemAlloc() 59 | * @li MP4ItmfAddItem() 60 | * @li MP4ItmfItemFree() 61 | * 62 | * @par Warning: 63 | * Care must be taken when using multiple mechanisms to modify an open mp4 64 | * file as it is not thread-safe, nor does it permit overlapping different 65 | * API workflows which have a begin/end to their workflow. That is to say 66 | * do not interleave an iTMF Generic workflow with an iTMF Tags workflow. 67 | * 68 | *****************************************************************************/ 69 | 70 | /** Basic types of value data as enumerated in spec. */ 71 | typedef enum MP4ItmfBasicType_e 72 | { 73 | MP4_ITMF_BT_IMPLICIT = 0, /**< for use with tags for which no type needs to be indicated */ 74 | MP4_ITMF_BT_UTF8 = 1, /**< without any count or null terminator */ 75 | MP4_ITMF_BT_UTF16 = 2, /**< also known as UTF-16BE */ 76 | MP4_ITMF_BT_SJIS = 3, /**< deprecated unless it is needed for special Japanese characters */ 77 | MP4_ITMF_BT_HTML = 6, /**< the HTML file header specifies which HTML version */ 78 | MP4_ITMF_BT_XML = 7, /**< the XML header must identify the DTD or schemas */ 79 | MP4_ITMF_BT_UUID = 8, /**< also known as GUID; stored as 16 bytes in binary (valid as an ID) */ 80 | MP4_ITMF_BT_ISRC = 9, /**< stored as UTF-8 text (valid as an ID) */ 81 | MP4_ITMF_BT_MI3P = 10, /**< stored as UTF-8 text (valid as an ID) */ 82 | MP4_ITMF_BT_GIF = 12, /**< (deprecated) a GIF image */ 83 | MP4_ITMF_BT_JPEG = 13, /**< a JPEG image */ 84 | MP4_ITMF_BT_PNG = 14, /**< a PNG image */ 85 | MP4_ITMF_BT_URL = 15, /**< absolute, in UTF-8 characters */ 86 | MP4_ITMF_BT_DURATION = 16, /**< in milliseconds, 32-bit integer */ 87 | MP4_ITMF_BT_DATETIME = 17, /**< in UTC, counting seconds since midnight, January 1, 1904; 32 or 64-bits */ 88 | MP4_ITMF_BT_GENRES = 18, /**< a list of enumerated values */ 89 | MP4_ITMF_BT_INTEGER = 21, /**< a signed big-endian integer with length one of { 1,2,3,4,8 } bytes */ 90 | MP4_ITMF_BT_RIAA_PA = 24, /**< RIAA parental advisory; { -1=no, 1=yes, 0=unspecified }, 8-bit ingteger */ 91 | MP4_ITMF_BT_UPC = 25, /**< Universal Product Code, in text UTF-8 format (valid as an ID) */ 92 | MP4_ITMF_BT_BMP = 27, /**< Windows bitmap image */ 93 | 94 | MP4_ITMF_BT_UNDEFINED = 255 /**< undefined */ 95 | } MP4ItmfBasicType; 96 | 97 | /** Data structure. 98 | * Models an iTMF data atom contained in an iTMF metadata item atom. 99 | */ 100 | typedef struct MP4ItmfData_s 101 | { 102 | uint8_t typeSetIdentifier; /**< always zero. */ 103 | MP4ItmfBasicType typeCode; /**< iTMF basic type. */ 104 | uint32_t locale; /**< always zero. */ 105 | uint8_t* value; /**< may be NULL. */ 106 | uint32_t valueSize; /**< value size in bytes. */ 107 | } MP4ItmfData; 108 | 109 | /** List of data. */ 110 | typedef struct MP4ItmfDataList_s 111 | { 112 | MP4ItmfData* elements; /**< flat array. NULL when size is zero. */ 113 | uint32_t size; /**< number of elements. */ 114 | } MP4ItmfDataList; 115 | 116 | /** Item structure. 117 | * Models an iTMF metadata item atom contained in an ilst atom. 118 | */ 119 | typedef struct MP4ItmfItem_s 120 | { 121 | void* __handle; /**< internal use only. */ 122 | 123 | char* code; /**< four-char code identifing atom type. NULL-terminated. */ 124 | char* mean; /**< may be NULL. UTF-8 meaning. NULL-terminated. */ 125 | char* name; /**< may be NULL. UTF-8 name. NULL-terminated. */ 126 | MP4ItmfDataList dataList; /**< list of data. can be zero length. */ 127 | } MP4ItmfItem; 128 | 129 | /** List of items. */ 130 | typedef struct MP4ItmfItemList_s 131 | { 132 | MP4ItmfItem* elements; /**< flat array. NULL when size is zero. */ 133 | uint32_t size; /**< number of elements. */ 134 | } MP4ItmfItemList; 135 | 136 | /** Allocate an item on the heap. 137 | * @param code four-char code identifying atom type. NULL-terminated. 138 | * @param numData number of data elements to allocate. Must be >= 1. 139 | * @return newly allocated item. 140 | */ 141 | MP4V2_EXPORT MP4ItmfItem* 142 | MP4ItmfItemAlloc( const char* code, uint32_t numData ); 143 | 144 | /** Free an item (deep free). 145 | * @param item to be free'd. 146 | */ 147 | MP4V2_EXPORT void 148 | MP4ItmfItemFree( MP4ItmfItem* item ); 149 | 150 | /** Free an item list (deep free). 151 | * @param itemList to be free'd. 152 | */ 153 | MP4V2_EXPORT void 154 | MP4ItmfItemListFree( MP4ItmfItemList* itemList ); 155 | 156 | /** Get list of all items from file. 157 | * @param hFile handle of file to operate on. 158 | * @return On succes, list of items, which must be free'd. On failure, NULL. 159 | */ 160 | MP4V2_EXPORT MP4ItmfItemList* 161 | MP4ItmfGetItems( MP4FileHandle hFile ); 162 | 163 | /** Get list of items by code from file. 164 | * @param hFile handle of file to operate on. 165 | * @param code four-char code identifying atom type. NULL-terminated. 166 | * @return On succes, list of items, which must be free'd. On failure, NULL. 167 | */ 168 | MP4V2_EXPORT MP4ItmfItemList* 169 | MP4ItmfGetItemsByCode( MP4FileHandle hFile, const char* code ); 170 | 171 | /** Get list of items by meaning from file. 172 | * Implicitly only returns atoms of code @b{----}. 173 | * @param hFile handle of file to operate on. 174 | * @param meaning UTF-8 meaning. NULL-terminated. 175 | * @param name may be NULL. UTF-8 name. NULL-terminated. 176 | * @return On succes, list of items, which must be free'd. On failure, NULL. 177 | */ 178 | MP4V2_EXPORT MP4ItmfItemList* 179 | MP4ItmfGetItemsByMeaning( MP4FileHandle hFile, const char* meaning, const char* name ); 180 | 181 | /** Add an item to file. 182 | * @param hFile handle of file to operate on. 183 | * @param item object to add. 184 | * @return true on success, false on failure. 185 | */ 186 | MP4V2_EXPORT bool 187 | MP4ItmfAddItem( MP4FileHandle hFile, const MP4ItmfItem* item ); 188 | 189 | /** Overwrite an existing item in file. 190 | * @param hFile handle of file to operate on. 191 | * @param item object to overwrite. Must have a valid index obtained from prior get. 192 | * @return true on success, false on failure. 193 | */ 194 | MP4V2_EXPORT bool 195 | MP4ItmfSetItem( MP4FileHandle hFile, const MP4ItmfItem* item ); 196 | 197 | /** Remove an existing item from file. 198 | * @param hFile handle of file to operate on. 199 | * @param item object to remove. Must have a valid index obtained from prior get. 200 | * @return true on success, false on failure. 201 | */ 202 | MP4V2_EXPORT bool 203 | MP4ItmfRemoveItem( MP4FileHandle hFile, const MP4ItmfItem* item ); 204 | 205 | /** @} ***********************************************************************/ 206 | 207 | #endif /* MP4V2_ITMF_GENERIC_H */ 208 | -------------------------------------------------------------------------------- /mp4v2/inc/itmf_tags.h: -------------------------------------------------------------------------------- 1 | #ifndef MP4V2_ITMF_TAGS_H 2 | #define MP4V2_ITMF_TAGS_H 3 | 4 | /**************************************************************************//** 5 | * 6 | * @defgroup mp4_itmf_tags MP4v2 iTMF (iTunes Metadata Format) Tags 7 | * @{ 8 | * 9 | * This is a high-level API used to manage iTMF metadata. 10 | * 11 | * It provides more type-safety and simplified memory management as compared 12 | * to iTMF Generic API. 13 | * 14 | * At the heart of this API is a read-only structure that holds all known 15 | * items and their current values. The value is always a pointer which if 16 | * NULL indicates its corresponding atom does not exist. Thus, one must 17 | * always check if the pointer is non-NULL before attempting to extract 18 | * its value. 19 | * 20 | * The structure may not be directly modified. Instead, set functions 21 | * corresponding to each item are used to modify the backing-store of 22 | * the read-only structure. Setting the value ptr to NULL will effectively 23 | * remove it. Setting the value ptr to real data will immediately make a 24 | * copy of the value in the backing-store and the read-only structure 25 | * will correctly reflect the change. 26 | * 27 | * The hidden data cache memory is automatically managed. Thus the user need 28 | * only guarantee the data is available during the lifetime of the set-function 29 | * call. 30 | * 31 | * iTMF Tags read workflow: 32 | * 33 | * @li MP4TagsAlloc() 34 | * @li MP4TagsFetch() 35 | * @li inspect each tag of interest... 36 | * @li MP4TagsStore() (if modified) 37 | * @li MP4TagsFree() 38 | * 39 | * iTMF Tags read/modify/add/remove workflow: 40 | * 41 | * @li MP4TagsAlloc() 42 | * @li MP4TagsFetch() 43 | * @li inspect each tag of interest... 44 | * @li MP4TagsSetName(), MP4TagsSetArtist()... 45 | * @li MP4TagsStore() 46 | * @li MP4TagsFree() 47 | * 48 | * @par Warning: 49 | * Care must be taken when using multiple mechanisms to modify an open mp4 50 | * file as it is not thread-safe, nor does it permit overlapping different 51 | * API workflows which have a begin/end to their workflow. That is to say 52 | * do not interleave an iTMF Generic workflow with an iTMF Tags workflow. 53 | * 54 | *****************************************************************************/ 55 | 56 | /** Enumeration of possible MP4TagArtwork::type values. */ 57 | typedef enum MP4TagArtworkType_e 58 | { 59 | MP4_ART_UNDEFINED = 0, 60 | MP4_ART_BMP = 1, 61 | MP4_ART_GIF = 2, 62 | MP4_ART_JPEG = 3, 63 | MP4_ART_PNG = 4 64 | } MP4TagArtworkType; 65 | 66 | /** Data object representing a single piece of artwork. */ 67 | typedef struct MP4TagArtwork_s 68 | { 69 | void* data; /**< raw picture data */ 70 | uint32_t size; /**< data size in bytes */ 71 | MP4TagArtworkType type; /**< data type */ 72 | } MP4TagArtwork; 73 | 74 | typedef struct MP4TagTrack_s 75 | { 76 | uint16_t index; 77 | uint16_t total; 78 | } MP4TagTrack; 79 | 80 | typedef struct MP4TagDisk_s 81 | { 82 | uint16_t index; 83 | uint16_t total; 84 | } MP4TagDisk; 85 | 86 | /** Tags convenience structure. 87 | * 88 | * This structure is used in the tags convenience API which allows for 89 | * simplified retrieval and modification of the majority of known tags. 90 | * 91 | * This is a read-only structure and each tag is present if and only if the 92 | * pointer is a non-NULL value. The actual data is backed by a hidden 93 | * data cache which is only updated when the appropriate metadata set 94 | * function is used, or if MP4TagsFetch() is invoked. Thus, if other API 95 | * is used to manipulate relevent atom structure of the MP4 file, the user 96 | * is responsible for re-fetching the data in this structure. 97 | */ 98 | typedef struct MP4Tags_s 99 | { 100 | void* __handle; /* internal use only */ 101 | 102 | const char* name; 103 | const char* artist; 104 | const char* albumArtist; 105 | const char* album; 106 | const char* grouping; 107 | const char* composer; 108 | const char* comments; 109 | const char* genre; 110 | const uint16_t* genreType; 111 | const char* releaseDate; 112 | const MP4TagTrack* track; 113 | const MP4TagDisk* disk; 114 | const uint16_t* tempo; 115 | const uint8_t* compilation; 116 | 117 | const char* tvShow; 118 | const char* tvNetwork; 119 | const char* tvEpisodeID; 120 | const uint32_t* tvSeason; 121 | const uint32_t* tvEpisode; 122 | 123 | const char* description; 124 | const char* longDescription; 125 | const char* lyrics; 126 | 127 | const char* sortName; 128 | const char* sortArtist; 129 | const char* sortAlbumArtist; 130 | const char* sortAlbum; 131 | const char* sortComposer; 132 | const char* sortTVShow; 133 | 134 | const MP4TagArtwork* artwork; 135 | uint32_t artworkCount; 136 | 137 | const char* copyright; 138 | const char* encodingTool; 139 | const char* encodedBy; 140 | const char* purchaseDate; 141 | 142 | const uint8_t* podcast; 143 | const char* keywords; /* TODO: Needs testing */ 144 | const char* category; 145 | 146 | const uint8_t* hdVideo; 147 | const uint8_t* mediaType; 148 | const uint8_t* contentRating; 149 | const uint8_t* gapless; 150 | 151 | const char* iTunesAccount; 152 | const uint8_t* iTunesAccountType; 153 | const uint32_t* iTunesCountry; 154 | const uint32_t* contentID; 155 | const uint32_t* artistID; 156 | const uint64_t* playlistID; 157 | const uint32_t* genreID; 158 | const uint32_t* composerID; 159 | const char* xid; 160 | } MP4Tags; 161 | 162 | /** Allocate tags convenience structure for reading and settings tags. 163 | * 164 | * This function allocates a new structure which represents a snapshot 165 | * of all the tags therein, tracking if the tag is missing, 166 | * or present and with value. It is the caller's responsibility to free 167 | * the structure with MP4TagsFree(). 168 | * 169 | * @return structure with all tags missing. 170 | */ 171 | MP4V2_EXPORT 172 | const MP4Tags* MP4TagsAlloc( void ); 173 | 174 | /** Fetch data from mp4 file and populate structure. 175 | * 176 | * The tags structure and its hidden data-cache is updated to 177 | * reflect the actual tags values found in the hFile. 178 | * 179 | * @param tags structure to fetch (write) into. 180 | * @param hFile handle of file to fetch data from. 181 | * 182 | * @return true on success, false on failure. 183 | */ 184 | MP4V2_EXPORT 185 | bool MP4TagsFetch( const MP4Tags* tags, MP4FileHandle hFile ); 186 | 187 | /** Store data to mp4 file from structure. 188 | * 189 | * The tags structure is pushed out to the mp4 file, 190 | * adding tags if needed, removing tags if needed, and updating 191 | * the values to modified tags. 192 | * 193 | * @param tags structure to store (read) from. 194 | * @param hFile handle of file to store data to. 195 | * 196 | * @return true on success, false on failure. 197 | */ 198 | MP4V2_EXPORT 199 | bool MP4TagsStore( const MP4Tags* tags, MP4FileHandle hFile ); 200 | 201 | /** Free tags convenience structure. 202 | * 203 | * This function frees memory associated with the structure. 204 | * 205 | * @param tags structure to destroy. 206 | */ 207 | MP4V2_EXPORT 208 | void MP4TagsFree( const MP4Tags* tags ); 209 | 210 | /** Accessor that indicates whether a tags structure 211 | * contains any metadata 212 | * 213 | * @param tags the structure to inspect 214 | * 215 | * @param hasMetadata populated with false if @p tags 216 | * contains no metadata, true if @p tags contains metadata 217 | * 218 | * @retval false error determining if @p tags contains 219 | * metadata 220 | * 221 | * @retval true successfully determined if @p tags contains 222 | * metadata 223 | */ 224 | MP4V2_EXPORT 225 | bool MP4TagsHasMetadata ( const MP4Tags* tags, bool *hasMetadata ); 226 | 227 | MP4V2_EXPORT bool MP4TagsSetName ( const MP4Tags*, const char* ); 228 | MP4V2_EXPORT bool MP4TagsSetArtist ( const MP4Tags*, const char* ); 229 | MP4V2_EXPORT bool MP4TagsSetAlbumArtist ( const MP4Tags*, const char* ); 230 | MP4V2_EXPORT bool MP4TagsSetAlbum ( const MP4Tags*, const char* ); 231 | MP4V2_EXPORT bool MP4TagsSetGrouping ( const MP4Tags*, const char* ); 232 | MP4V2_EXPORT bool MP4TagsSetComposer ( const MP4Tags*, const char* ); 233 | MP4V2_EXPORT bool MP4TagsSetComments ( const MP4Tags*, const char* ); 234 | MP4V2_EXPORT bool MP4TagsSetGenre ( const MP4Tags*, const char* ); 235 | MP4V2_EXPORT bool MP4TagsSetGenreType ( const MP4Tags*, const uint16_t* ); 236 | MP4V2_EXPORT bool MP4TagsSetReleaseDate ( const MP4Tags*, const char* ); 237 | MP4V2_EXPORT bool MP4TagsSetTrack ( const MP4Tags*, const MP4TagTrack* ); 238 | MP4V2_EXPORT bool MP4TagsSetDisk ( const MP4Tags*, const MP4TagDisk* ); 239 | MP4V2_EXPORT bool MP4TagsSetTempo ( const MP4Tags*, const uint16_t* ); 240 | MP4V2_EXPORT bool MP4TagsSetCompilation ( const MP4Tags*, const uint8_t* ); 241 | 242 | MP4V2_EXPORT bool MP4TagsSetTVShow ( const MP4Tags*, const char* ); 243 | MP4V2_EXPORT bool MP4TagsSetTVNetwork ( const MP4Tags*, const char* ); 244 | MP4V2_EXPORT bool MP4TagsSetTVEpisodeID ( const MP4Tags*, const char* ); 245 | MP4V2_EXPORT bool MP4TagsSetTVSeason ( const MP4Tags*, const uint32_t* ); 246 | MP4V2_EXPORT bool MP4TagsSetTVEpisode ( const MP4Tags*, const uint32_t* ); 247 | 248 | MP4V2_EXPORT bool MP4TagsSetDescription ( const MP4Tags*, const char* ); 249 | MP4V2_EXPORT bool MP4TagsSetLongDescription ( const MP4Tags*, const char* ); 250 | MP4V2_EXPORT bool MP4TagsSetLyrics ( const MP4Tags*, const char* ); 251 | 252 | MP4V2_EXPORT bool MP4TagsSetSortName ( const MP4Tags*, const char* ); 253 | MP4V2_EXPORT bool MP4TagsSetSortArtist ( const MP4Tags*, const char* ); 254 | MP4V2_EXPORT bool MP4TagsSetSortAlbumArtist ( const MP4Tags*, const char* ); 255 | MP4V2_EXPORT bool MP4TagsSetSortAlbum ( const MP4Tags*, const char* ); 256 | MP4V2_EXPORT bool MP4TagsSetSortComposer ( const MP4Tags*, const char* ); 257 | MP4V2_EXPORT bool MP4TagsSetSortTVShow ( const MP4Tags*, const char* ); 258 | 259 | MP4V2_EXPORT bool MP4TagsAddArtwork ( const MP4Tags*, MP4TagArtwork* ); 260 | MP4V2_EXPORT bool MP4TagsSetArtwork ( const MP4Tags*, uint32_t, MP4TagArtwork* ); 261 | MP4V2_EXPORT bool MP4TagsRemoveArtwork ( const MP4Tags*, uint32_t ); 262 | 263 | MP4V2_EXPORT bool MP4TagsSetCopyright ( const MP4Tags*, const char* ); 264 | MP4V2_EXPORT bool MP4TagsSetEncodingTool ( const MP4Tags*, const char* ); 265 | MP4V2_EXPORT bool MP4TagsSetEncodedBy ( const MP4Tags*, const char* ); 266 | MP4V2_EXPORT bool MP4TagsSetPurchaseDate ( const MP4Tags*, const char* ); 267 | 268 | MP4V2_EXPORT bool MP4TagsSetPodcast ( const MP4Tags*, const uint8_t* ); 269 | MP4V2_EXPORT bool MP4TagsSetKeywords ( const MP4Tags*, const char* ); 270 | MP4V2_EXPORT bool MP4TagsSetCategory ( const MP4Tags*, const char* ); 271 | 272 | MP4V2_EXPORT bool MP4TagsSetHDVideo ( const MP4Tags*, const uint8_t* ); 273 | MP4V2_EXPORT bool MP4TagsSetMediaType ( const MP4Tags*, const uint8_t* ); 274 | MP4V2_EXPORT bool MP4TagsSetContentRating ( const MP4Tags*, const uint8_t* ); 275 | MP4V2_EXPORT bool MP4TagsSetGapless ( const MP4Tags*, const uint8_t* ); 276 | 277 | MP4V2_EXPORT bool MP4TagsSetITunesAccount ( const MP4Tags*, const char* ); 278 | MP4V2_EXPORT bool MP4TagsSetITunesAccountType ( const MP4Tags*, const uint8_t* ); 279 | MP4V2_EXPORT bool MP4TagsSetITunesCountry ( const MP4Tags*, const uint32_t* ); 280 | MP4V2_EXPORT bool MP4TagsSetContentID ( const MP4Tags*, const uint32_t* ); 281 | MP4V2_EXPORT bool MP4TagsSetArtistID ( const MP4Tags*, const uint32_t* ); 282 | MP4V2_EXPORT bool MP4TagsSetPlaylistID ( const MP4Tags*, const uint64_t* ); 283 | MP4V2_EXPORT bool MP4TagsSetGenreID ( const MP4Tags*, const uint32_t* ); 284 | MP4V2_EXPORT bool MP4TagsSetComposerID ( const MP4Tags*, const uint32_t* ); 285 | MP4V2_EXPORT bool MP4TagsSetXID ( const MP4Tags*, const char* ); 286 | 287 | /** @} ***********************************************************************/ 288 | 289 | #endif /* MP4V2_ITMF_TAGS_H */ 290 | -------------------------------------------------------------------------------- /mp4v2/inc/mp4v2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * The contents of this file are subject to the Mozilla Public 3 | * License Version 1.1 (the "License"); you may not use this file 4 | * except in compliance with the License. You may obtain a copy of 5 | * the License at http://www.mozilla.org/MPL/ 6 | * 7 | * Software distributed under the License is distributed on an "AS 8 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 9 | * implied. See the License for the specific language governing 10 | * rights and limitations under the License. 11 | * 12 | * The Original Code is MPEG4IP. 13 | * 14 | * The Initial Developer of the Original Code is Cisco Systems Inc. 15 | * Portions created by Cisco Systems Inc. are 16 | * Copyright (C) Cisco Systems Inc. 2001 - 2005. All Rights Reserved. 17 | * 18 | * 3GPP features implementation is based on 3GPP's TS26.234-v5.60, 19 | * and was contributed by Ximpo Group Ltd. 20 | * 21 | * Portions created by Ximpo Group Ltd. are 22 | * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved. 23 | * 24 | * Contributor(s): 25 | * Dave Mackie dmackie@cisco.com 26 | * Alix Marchandise-Franquet alix@cisco.com 27 | * Ximpo Group Ltd. mp4v2@ximpo.com 28 | * Bill May wmay@cisco.com 29 | */ 30 | #ifndef MP4V2_MP4V2_H 31 | #define MP4V2_MP4V2_H 32 | 33 | /*****************************************************************************/ 34 | 35 | #include "platform.h" 36 | #include "project.h" 37 | 38 | /*****************************************************************************/ 39 | 40 | /* exploit C++ ability of default values for function parameters */ 41 | #if defined( DEFAULT ) 42 | # define __MP4V2_SAVE_DEFAULT DEFAULT 43 | #endif 44 | #undef DEFAULT 45 | #if defined( __cplusplus ) 46 | # define DEFAULT(x) =x 47 | #else 48 | # define DEFAULT(x) 49 | #endif 50 | 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif 54 | 55 | /*****************************************************************************/ 56 | 57 | #include 58 | #include 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | 69 | /*****************************************************************************/ 70 | 71 | /* restore macro DEFAULT to state prior to mp4v2 headers */ 72 | #undef DEFAULT 73 | #if defined( __MP4V2_SAVE_DEFAULT ) 74 | # define DEFAULT __MP4V2_SAVE_DEFAULT 75 | #endif 76 | 77 | #ifdef __cplusplus 78 | } // extern "C" 79 | #endif 80 | 81 | /*****************************************************************************/ 82 | 83 | #endif /* MP4V2_MP4V2_H */ 84 | -------------------------------------------------------------------------------- /mp4v2/inc/platform.h: -------------------------------------------------------------------------------- 1 | #ifndef MP4V2_PLATFORM_H 2 | #define MP4V2_PLATFORM_H 3 | 4 | /*****************************************************************************/ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | // Thanks, MSFT, for making C99 a total PITA. Declare this not to define any stdint stuff; this is useful 11 | // if you're going to be using mp4v2 on windows with some other library that defines its own stdint. 12 | // TODO msft has finally re-included stdint in vs2010, so maybe at some point in the future this won't be needed. 13 | #ifndef MP4V2_NO_STDINT_DEFS 14 | #if defined( _WIN32 ) && !defined( __MINGW32__ ) 15 | typedef char int8_t; 16 | typedef short int16_t; 17 | typedef int int32_t; 18 | typedef long long int64_t; 19 | 20 | typedef unsigned char uint8_t; 21 | typedef unsigned short uint16_t; 22 | typedef unsigned int uint32_t; 23 | typedef unsigned long long uint64_t; 24 | #else 25 | #include 26 | #endif 27 | #endif 28 | 29 | #if defined( _WIN32 ) || defined( __MINGW32__ ) 30 | # if defined( MP4V2_EXPORTS ) 31 | # define MP4V2_EXPORT __declspec(dllexport) 32 | # elif defined( MP4V2_USE_DLL_IMPORT ) || !defined( MP4V2_USE_STATIC_LIB ) 33 | # define MP4V2_EXPORT __declspec(dllimport) 34 | # else 35 | # define MP4V2_EXPORT 36 | # endif 37 | #else 38 | # define MP4V2_EXPORT __attribute__((visibility("default"))) 39 | #endif 40 | 41 | #if defined( __GNUC__ ) 42 | # define MP4V2_DEPRECATED __attribute__((deprecated)) 43 | #else 44 | # define MP4V2_DEPRECATED 45 | #endif 46 | 47 | /****************************************************************************** 48 | * 49 | * TODO-KB: cleanup -- absolutely no need for a C-API to fuss with reserved 50 | * C++ keywords. This will involve changing the public interface and current 51 | * plan of action: 52 | * 53 | * typdef enum { 54 | * mp4_false, 55 | * mp4_true, 56 | * } mp4_bool_t; 57 | * 58 | * followed by updating all public signatures and implementation. 59 | */ 60 | 61 | #ifndef FALSE 62 | #define FALSE 0 63 | #endif 64 | 65 | #ifndef TRUE 66 | #define TRUE 1 67 | #endif 68 | 69 | #if !defined( __cplusplus ) 70 | #ifndef bool 71 | #if SIZEOF_BOOL == 8 72 | typedef uint64_t bool; 73 | #else 74 | #if SIZEOF_BOOL == 4 75 | typedef uint32_t bool; 76 | #else 77 | #if SIZEOF_BOOL == 2 78 | typedef uint16_t bool; 79 | #else 80 | typedef unsigned char bool; 81 | #endif 82 | #endif 83 | #endif 84 | #ifndef false 85 | #define false FALSE 86 | #endif 87 | #ifndef true 88 | #define true TRUE 89 | #endif 90 | #endif 91 | #endif 92 | 93 | /*****************************************************************************/ 94 | 95 | #endif /* MP4V2_PLATFORM_H */ 96 | -------------------------------------------------------------------------------- /mp4v2/inc/project.h: -------------------------------------------------------------------------------- 1 | #ifndef MP4V2_PROJECT_H 2 | #define MP4V2_PROJECT_H 3 | 4 | /*****************************************************************************/ 5 | 6 | #define MP4V2_PROJECT_name "MP4v2" 7 | #define MP4V2_PROJECT_name_lower "mp4v2" 8 | #define MP4V2_PROJECT_name_upper "MP4V2" 9 | #define MP4V2_PROJECT_name_formal "MP4v2 2.0.0" 10 | #define MP4V2_PROJECT_url_website "http://code.google.com/p/mp4v2" 11 | #define MP4V2_PROJECT_url_downloads "http://code.google.com/p/mp4v2/downloads/list" 12 | #define MP4V2_PROJECT_url_discussion "http://groups.google.com/group/mp4v2" 13 | #define MP4V2_PROJECT_irc "irc://irc.freenode.net/handbrake" 14 | #define MP4V2_PROJECT_bugreport "" 15 | #define MP4V2_PROJECT_version "2.0.0" 16 | #define MP4V2_PROJECT_version_hex 0x00020000 17 | #define MP4V2_PROJECT_version_major 2 18 | #define MP4V2_PROJECT_version_minor 0 19 | #define MP4V2_PROJECT_version_point 0 20 | #define MP4V2_PROJECT_repo_url "https://mp4v2.googlecode.com/svn/releases/2.0.0" 21 | #define MP4V2_PROJECT_repo_branch "2.0.0" 22 | #define MP4V2_PROJECT_repo_root "https://mp4v2.googlecode.com/svn" 23 | #define MP4V2_PROJECT_repo_uuid "6e6572fa-98a6-11dd-ad9f-f77439c74b79" 24 | #define MP4V2_PROJECT_repo_rev 493 25 | #define MP4V2_PROJECT_repo_date "2012-05-20 15:16:54 -0700 (Sun, 20 May 2012)" 26 | #define MP4V2_PROJECT_repo_type "stable" 27 | #define MP4V2_PROJECT_build "Sun May 20 15:18:53 PDT 2012" 28 | 29 | /*****************************************************************************/ 30 | 31 | #endif /* MP4V2_PROJECT_H */ 32 | -------------------------------------------------------------------------------- /mp4v2/inc/project.h.in: -------------------------------------------------------------------------------- 1 | #ifndef MP4V2_PROJECT_H 2 | #define MP4V2_PROJECT_H 3 | 4 | /*****************************************************************************/ 5 | 6 | #define MP4V2_PROJECT_name "@PROJECT_name@" 7 | #define MP4V2_PROJECT_name_lower "@PROJECT_name_lower@" 8 | #define MP4V2_PROJECT_name_upper "@PROJECT_name_upper@" 9 | #define MP4V2_PROJECT_name_formal "@PROJECT_name_formal@" 10 | #define MP4V2_PROJECT_url_website "@PROJECT_url_website@" 11 | #define MP4V2_PROJECT_url_downloads "@PROJECT_url_downloads@" 12 | #define MP4V2_PROJECT_url_discussion "@PROJECT_url_discussion@" 13 | #define MP4V2_PROJECT_irc "@PROJECT_irc@" 14 | #define MP4V2_PROJECT_bugreport "@PROJECT_bugreport@" 15 | #define MP4V2_PROJECT_version "@PROJECT_version@" 16 | #define MP4V2_PROJECT_version_hex @PROJECT_version_hex@ 17 | #define MP4V2_PROJECT_version_major @PROJECT_version_major@ 18 | #define MP4V2_PROJECT_version_minor @PROJECT_version_minor@ 19 | #define MP4V2_PROJECT_version_point @PROJECT_version_point@ 20 | #define MP4V2_PROJECT_repo_url "@PROJECT_repo_url@" 21 | #define MP4V2_PROJECT_repo_branch "@PROJECT_repo_branch@" 22 | #define MP4V2_PROJECT_repo_root "@PROJECT_repo_root@" 23 | #define MP4V2_PROJECT_repo_uuid "@PROJECT_repo_uuid@" 24 | #define MP4V2_PROJECT_repo_rev @PROJECT_repo_rev@ 25 | #define MP4V2_PROJECT_repo_date "@PROJECT_repo_date@" 26 | #define MP4V2_PROJECT_repo_type "@PROJECT_repo_type@" 27 | #define MP4V2_PROJECT_build "@PROJECT_build@" 28 | 29 | /*****************************************************************************/ 30 | 31 | #endif /* MP4V2_PROJECT_H */ 32 | -------------------------------------------------------------------------------- /mp4v2/inc/sample.h: -------------------------------------------------------------------------------- 1 | #ifndef MP4V2_SAMPLE_H 2 | #define MP4V2_SAMPLE_H 3 | 4 | /**************************************************************************//** 5 | * 6 | * @defgroup mp4_sample MP4v2 Sample 7 | * @{ 8 | * 9 | *****************************************************************************/ 10 | 11 | /** Sample dependency types. 12 | * 13 | * Bit combinations 0x03, 0x30, 0xc0 are reserved. 14 | */ 15 | typedef enum MP4SampleDependencyType_e { 16 | MP4_SDT_UNKNOWN = 0x00, /**< unknown */ 17 | MP4_SDT_HAS_REDUNDANT_CODING = 0x01, /**< contains redundant coding */ 18 | MP4_SDT_HAS_NO_REDUNDANT_CODING = 0x02, /**< does not contain redundant coding */ 19 | MP4_SDT_HAS_DEPENDENTS = 0x04, /**< referenced by other samples */ 20 | MP4_SDT_HAS_NO_DEPENDENTS = 0x08, /**< not referenced by other samples */ 21 | MP4_SDT_IS_DEPENDENT = 0x10, /**< references other samples */ 22 | MP4_SDT_IS_INDEPENDENT = 0x20, /**< does not reference other samples */ 23 | MP4_SDT_EARLIER_DISPLAY_TIMES_ALLOWED = 0x40, /**< subequent samples in GOP may display earlier */ 24 | _MP4_SDT_RESERVED = 0x80 /**< reserved */ 25 | } MP4SampleDependencyType; 26 | 27 | /** Read a track sample. 28 | * 29 | * MP4ReadSample reads the specified sample from the specified track. 30 | * Typically this sample is then decoded in a codec dependent fashion and 31 | * rendered in an appropriate fashion. 32 | * 33 | * The argument ppBytes allows for two possible approaches for 34 | * buffering: 35 | * 36 | * If the calling application wishes to handle its own buffering it can set 37 | * *ppBytes to the buffer it wishes to use. The calling application is 38 | * responsible for ensuring that the buffer is large enough to hold the 39 | * sample. This can be done by using either MP4GetSampleSize() or 40 | * MP4GetTrackMaxSampleSize() to determine before-hand how large the 41 | * receiving buffer must be. 42 | * 43 | * If the value of *ppBytes is NULL, then an appropriately sized buffer is 44 | * automatically malloc'ed for the sample data and *ppBytes set to this 45 | * pointer. The calling application is responsible for free'ing this 46 | * memory. 47 | * 48 | * The last four arguments are pointers to variables that can receive 49 | * optional sample information. 50 | * 51 | * Typically for audio none of these are needed. MPEG audio such as MP3 or 52 | * AAC has a fixed sample duration and every sample can be accessed at 53 | * random. 54 | * 55 | * For video, all of these optional values could be needed. MPEG video can 56 | * be encoded at a variable frame rate, with only occasional random access 57 | * points, and with "B frames" which cause the rendering (display) order 58 | * of the video frames to differ from the storage/decoding order. 59 | * 60 | * Other media types fall between these two extremes. 61 | * 62 | * @param hFile handle of file for operation. 63 | * @param trackId id of track for operation. 64 | * @param sampleId specifies which sample is to be read. 65 | * Caveat: the first sample has id 1 not 0. 66 | * @param ppBytes pointer to the pointer to the sample data. 67 | * @param pNumBytes pointer to variable that will be hold the size in bytes 68 | * of the sample. 69 | * @param pStartTime if non-NULL, pointer to variable that will receive the 70 | * starting timestamp for this sample. Caveat: The timestamp is in 71 | * trackId's timescale. 72 | * @param pDuration if non-NULL, pointer to variable that will receive the 73 | * duration for this sample. Caveat: The duration is in 74 | * trackId's timescale. 75 | * @param pRenderingOffset if non-NULL, pointer to variable that will 76 | * receive the rendering offset for this sample. Currently the only 77 | * media type that needs this feature is MPEG video. Caveat: The offset 78 | * is in trackId's timescale. 79 | * @param pIsSyncSample if non-NULL, pointer to variable that will receive 80 | * the state of the sync/random access flag for this sample. 81 | * 82 | * @return true on success, false on failure. 83 | * 84 | * @see MP4GetSampleSize(). 85 | * @see MP4GetTrackMaxSampleSize(). 86 | */ 87 | MP4V2_EXPORT 88 | bool MP4ReadSample( 89 | /* input parameters */ 90 | MP4FileHandle hFile, 91 | MP4TrackId trackId, 92 | MP4SampleId sampleId, 93 | /* input/output parameters */ 94 | uint8_t** ppBytes, 95 | uint32_t* pNumBytes, 96 | /* output parameters */ 97 | MP4Timestamp* pStartTime DEFAULT(NULL), 98 | MP4Duration* pDuration DEFAULT(NULL), 99 | MP4Duration* pRenderingOffset DEFAULT(NULL), 100 | bool* pIsSyncSample DEFAULT(NULL) ); 101 | 102 | /** Read a track sample based on a specified time. 103 | * 104 | * MP4ReadSampleFromTime is similar to MP4ReadSample() except the sample 105 | * is specified by using a timestamp instead of sampleId. 106 | * Typically this sample is then decoded in a codec dependent fashion and 107 | * rendered in an appropriate fashion. 108 | * 109 | * The argument ppBytes allows for two possible approaches for 110 | * buffering: 111 | * 112 | * If the calling application wishes to handle its own buffering it can set 113 | * *ppBytes to the buffer it wishes to use. The calling application is 114 | * responsible for ensuring that the buffer is large enough to hold the 115 | * sample. This can be done by using either MP4GetSampleSize() or 116 | * MP4GetTrackMaxSampleSize() to determine before-hand how large the 117 | * receiving buffer must be. 118 | * 119 | * If the value of *ppBytes is NULL, then an appropriately sized buffer is 120 | * automatically malloc'ed for the sample data and *ppBytes set to this 121 | * pointer. The calling application is responsible for free'ing this 122 | * memory. 123 | * 124 | * The last four arguments are pointers to variables that can receive 125 | * optional sample information. 126 | * 127 | * Typically for audio none of these are needed. MPEG audio such as MP3 or 128 | * AAC has a fixed sample duration and every sample can be accessed at 129 | * random. 130 | * 131 | * For video, all of these optional values could be needed. MPEG video can 132 | * be encoded at a variable frame rate, with only occasional random access 133 | * points, and with "B frames" which cause the rendering (display) order 134 | * of the video frames to differ from the storage/decoding order. 135 | * 136 | * Other media types fall between these two extremes. 137 | * 138 | * @param hFile handle of file for operation. 139 | * @param trackId id of track for operation. 140 | * @param when specifies which sample is to be read based on a time in the 141 | * track timeline. See MP4GetSampleIdFromTime() for details. 142 | * @param ppBytes pointer to the pointer to the sample data. 143 | * @param pNumBytes pointer to variable that will be hold the size in bytes 144 | * of the sample. 145 | * @param pStartTime if non-NULL, pointer to variable that will receive the 146 | * starting timestamp for this sample. Caveat: The timestamp is in 147 | * trackId's timescale. 148 | * @param pDuration if non-NULL, pointer to variable that will receive the 149 | * duration for this sample. Caveat: The duration is in 150 | * trackId's timescale. 151 | * @param pRenderingOffset if non-NULL, pointer to variable that will 152 | * receive the rendering offset for this sample. Currently the only 153 | * media type that needs this feature is MPEG video. Caveat: The offset 154 | * is in trackId's timescale. 155 | * @param pIsSyncSample if non-NULL, pointer to variable that will receive 156 | * the state of the sync/random access flag for this sample. 157 | * 158 | * @return true on success, false on failure. 159 | * 160 | * @see MP4ReadSample(). 161 | * @see MP4GetSampleIdFromTime(). 162 | * @see MP4GetSampleSize(). 163 | * @see MP4GetTrackMaxSampleSize(). 164 | */ 165 | MP4V2_EXPORT 166 | bool MP4ReadSampleFromTime( 167 | /* input parameters */ 168 | MP4FileHandle hFile, 169 | MP4TrackId trackId, 170 | MP4Timestamp when, 171 | /* input/output parameters */ 172 | uint8_t** ppBytes, 173 | uint32_t* pNumBytes, 174 | /* output parameters */ 175 | MP4Timestamp* pStartTime DEFAULT(NULL), 176 | MP4Duration* pDuration DEFAULT(NULL), 177 | MP4Duration* pRenderingOffset DEFAULT(NULL), 178 | bool* pIsSyncSample DEFAULT(NULL) ); 179 | 180 | /** Write a track sample. 181 | * 182 | * MP4WriteSample writes the given sample at the end of the specified track. 183 | * Currently the library does not support random insertion of samples into 184 | * the track timeline. Note that with mp4 there cannot be any holes or 185 | * overlapping samples in the track timeline. The last three arguments give 186 | * optional sample information. 187 | * 188 | * The value of duration can be given as #MP4_INVALID_DURATION if all samples 189 | * in the track have the same duration. This can be specified with 190 | * MP4AddTrack() and related functions. 191 | * 192 | * Typically for audio none of the optional arguments are needed. MPEG audio 193 | * such as MP3 or AAC has a fixed sample duration and every sample can be 194 | * accessed at random. 195 | * 196 | * For video, all of the optional arguments could be needed. MPEG video 197 | * can be encoded at a variable frame rate, with only occasional random 198 | * access points, and with "B frames" which cause the rendering (display) 199 | * order of the video frames to differ from the storage/decoding order. 200 | * 201 | * Other media types fall between these two extremes. 202 | * 203 | * @param hFile handle of file for operation. 204 | * @param trackId id of track for operation. 205 | * @param pBytes pointer to sample data. 206 | * @param numBytes length of sample data in bytes. 207 | * @param duration sample duration. Caveat: should be in track timescale. 208 | * @param renderingOffset the rendering offset for this sample. 209 | * Currently the only media type that needs this feature is MPEG 210 | * video. Caveat: The offset should be in the track timescale. 211 | * @param isSyncSample the sync/random access flag for this sample. 212 | * 213 | * @return true on success, false on failure. 214 | * 215 | * @see MP4AddTrack(). 216 | */ 217 | MP4V2_EXPORT 218 | bool MP4WriteSample( 219 | MP4FileHandle hFile, 220 | MP4TrackId trackId, 221 | const uint8_t* pBytes, 222 | uint32_t numBytes, 223 | MP4Duration duration DEFAULT(MP4_INVALID_DURATION), 224 | MP4Duration renderingOffset DEFAULT(0), 225 | bool isSyncSample DEFAULT(true) ); 226 | 227 | /** Write a track sample and supply dependency information. 228 | * 229 | * MP4WriteSampleDependency writes the given sample at the end of the specified track. 230 | * Currently the library does not support random insertion of samples into 231 | * the track timeline. Note that with mp4 there cannot be any holes or 232 | * overlapping samples in the track timeline. The last three arguments give 233 | * optional sample information. 234 | * 235 | * The value of duration can be given as #MP4_INVALID_DURATION if all samples 236 | * in the track have the same duration. This can be specified with 237 | * MP4AddTrack() and related functions. 238 | * 239 | * When this method is used instead of MP4WriteSample() it enables sdtp 240 | * atom to be written out. This atom may be used by advanced players to 241 | * optimize trick-operations such as fast-fwd, reverse or scrubbing. 242 | * 243 | * An sdtp atom will always be written out if this method is used. 244 | * To avoid writing the atom, use MP4WriteSample() instead. 245 | * 246 | * Intermixing use of MP4WriteSampleDependency() and MP4WriteSample() on the 247 | * same track is not permitted. 248 | * 249 | * @param hFile handle of file for operation. 250 | * @param trackId id of track for operation. 251 | * @param pBytes pointer to sample data. 252 | * @param numBytes length of sample data in bytes. 253 | * @param duration sample duration. Caveat: should be in track timescale. 254 | * @param renderingOffset the rendering offset for this sample. 255 | * Currently the only media type that needs this feature is MPEG 256 | * video. Caveat: The offset should be in the track timescale. 257 | * @param isSyncSample the sync/random access flag for this sample. 258 | * @param dependencyFlags bitmask specifying sample dependency characteristics. 259 | * See #MP4SampleDependencyType for bit constants. 260 | * 261 | * @return true on success, false on failure. 262 | * 263 | * @see MP4AddTrack(). 264 | */ 265 | MP4V2_EXPORT 266 | bool MP4WriteSampleDependency( 267 | MP4FileHandle hFile, 268 | MP4TrackId trackId, 269 | const uint8_t* pBytes, 270 | uint32_t numBytes, 271 | MP4Duration duration, 272 | MP4Duration renderingOffset, 273 | bool isSyncSample, 274 | uint32_t dependencyFlags ); 275 | 276 | /** Make a copy of a sample. 277 | * 278 | * MP4CopySample creates a new sample based on an existing sample. Note that 279 | * another copy of the media sample data is created in the file using this 280 | * function. ie. this call is equivalent to MP4ReadSample() followed by 281 | * MP4WriteSample(). 282 | * 283 | * Note that is the responsibility of the caller to ensure that the copied 284 | * media sample makes sense in the destination track. eg. copying a video 285 | * sample to an audio track is unlikely to result in anything good happening, 286 | * even copying a sample from video track to another requires that the tracks 287 | * use the same encoding and that issues such as image size are addressed. 288 | * 289 | * @param srcFile source sample file handle. 290 | * @param srcTrackId source sample track id. 291 | * @param srcSampleId source sample id. 292 | * @param dstFile destination file handle for new (copied) sample. 293 | * If the value is #MP4_INVALID_FILE_HANDLE, the copy is created in 294 | * the same file as srcFile. 295 | * @param dstTrackId destination track id for new sample. 296 | * If the value is #MP4_INVALID_TRACK_ID, the the copy is created in 297 | * the same track as the srcTrackId. 298 | * @param dstSampleDuration duration in track timescale for new sample. 299 | * If the value is #MP4_INVALID_DURATION, then the duration of 300 | * the source sample is used. 301 | * 302 | * @return On success, thew id of the new sample. 303 | * On error, #MP4_INVALID_SAMPLE_ID. 304 | * 305 | * @see MP4ReadSample(). 306 | * @see MP4WriteSample(). 307 | */ 308 | MP4V2_EXPORT 309 | bool MP4CopySample( 310 | MP4FileHandle srcFile, 311 | MP4TrackId srcTrackId, 312 | MP4SampleId srcSampleId, 313 | MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE), 314 | MP4TrackId dstTrackId DEFAULT(MP4_INVALID_TRACK_ID), 315 | MP4Duration dstSampleDuration DEFAULT(MP4_INVALID_DURATION) ); 316 | 317 | /** Make a copy of a sample. 318 | * 319 | * MP4EncAndCopySample is similar to MP4CopySample() except that it 320 | * offers an encryption hook to the caller. 321 | * 322 | * @param srcFile source sample file handle. 323 | * @param srcTrackId source sample track id. 324 | * @param srcSampleId source sample id. 325 | * @param encfcnp undocumented. 326 | * @param encfcnparam1 undocumented. 327 | * @param dstFile destination file handle for new (copied) sample. 328 | * If the value is #MP4_INVALID_FILE_HANDLE, the copy is created in 329 | * the same file as srcFile. 330 | * @param dstTrackId destination track id for new sample. 331 | * If the value is #MP4_INVALID_TRACK_ID, the the copy is created in 332 | * the same track as the srcTrackId. 333 | * @param dstSampleDuration duration in track timescale for new sample. 334 | * If the value is #MP4_INVALID_DURATION, then the duration of 335 | * the source sample is used. 336 | * 337 | * @return On success, thew id of the new sample. 338 | * On error, #MP4_INVALID_SAMPLE_ID. 339 | * 340 | * @see MP4CopySample(). 341 | */ 342 | MP4V2_EXPORT 343 | bool MP4EncAndCopySample( 344 | MP4FileHandle srcFile, 345 | MP4TrackId srcTrackId, 346 | MP4SampleId srcSampleId, 347 | encryptFunc_t encfcnp, 348 | uint32_t encfcnparam1, 349 | MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE), 350 | MP4TrackId dstTrackId DEFAULT(MP4_INVALID_TRACK_ID), 351 | MP4Duration dstSampleDuration DEFAULT(MP4_INVALID_DURATION) ); 352 | 353 | /** Not implemented. 354 | */ 355 | MP4V2_EXPORT 356 | bool MP4ReferenceSample( 357 | MP4FileHandle srcFile, 358 | MP4TrackId srcTrackId, 359 | MP4SampleId srcSampleId, 360 | MP4FileHandle dstFile, 361 | MP4TrackId dstTrackId, 362 | MP4Duration dstSampleDuration DEFAULT(MP4_INVALID_DURATION) ); 363 | 364 | /** Get size of a track sample. 365 | * 366 | * MP4GetSampleSize returns the size in bytes of the specified sample from the 367 | * the specified track. 368 | * 369 | * @param hFile handle of file for operation. 370 | * @param trackId id of track for operation. 371 | * @param sampleId id of sample for operation. Caveat: the first sample has 372 | * id 1, not 0. 373 | * 374 | * @return On success the sample size in bytes. On error, 0. 375 | */ 376 | MP4V2_EXPORT 377 | uint32_t MP4GetSampleSize( 378 | MP4FileHandle hFile, 379 | MP4TrackId trackId, 380 | MP4SampleId sampleId); 381 | 382 | /** Get the maximum sample size of a track. 383 | * 384 | * MP4GetTrackMaxSampleSize returns the maximum size in bytes of all the 385 | * samples in the specified track. 386 | * 387 | * @param hFile handle of file for operation. 388 | * @param trackId id of track for operation. 389 | * 390 | * @return On success, the maximum sample size in bytes. On error, 0. 391 | * 392 | * @see MP4GetSampleSize(). 393 | */ 394 | MP4V2_EXPORT 395 | uint32_t MP4GetTrackMaxSampleSize( 396 | MP4FileHandle hFile, 397 | MP4TrackId trackId ); 398 | 399 | /** Get sample id of a specified time. 400 | * 401 | * MP4GetSampleIdFromTime returns the sample id of the track sample in which 402 | * the specified time occurs. 403 | * 404 | * The specified time should be in the track timescale. 405 | * 406 | * It is wise to use MP4GetSampleTime() with the returned sample id so one 407 | * can adjust for any difference between the specified time and the actual 408 | * start time of the sample. 409 | * 410 | * If the calling application needs a sample that can be accessed randomly 411 | * then the wantSyncSample argument should be set to true. This could 412 | * be the case for a player that is implementing a positioning function and 413 | * needs to be able to start decoding a track from the returned sample id. 414 | * 415 | * @param hFile handle of file for operation. 416 | * @param trackId id of track for operation. 417 | * @param when time in track timescale. 418 | * @param wantSyncSample specifies if the result sample id must correspond 419 | * to a sample whose sync/random access flag is true. 420 | * 421 | * @return On success, the sample id that occurs at the specified time. 422 | * On error, #MP4_INVALID_SAMPLE_ID. 423 | * 424 | * @see MP4ConvertToTrackTimestamp() for how to map a time value to this 425 | * timescale. 426 | */ 427 | MP4V2_EXPORT 428 | MP4SampleId MP4GetSampleIdFromTime( 429 | MP4FileHandle hFile, 430 | MP4TrackId trackId, 431 | MP4Timestamp when, 432 | bool wantSyncSample DEFAULT(false) ); 433 | 434 | /** Get start time of track sample. 435 | * 436 | * MP4GetSampleTime returns the start time of the specified sample from 437 | * the specified track in the track timescale units. 438 | * 439 | * @param hFile handle of file for operation. 440 | * @param trackId id of track for operation. 441 | * @param sampleId id of sample for operation. Caveat: the first sample has 442 | * id 1, not 0. 443 | * 444 | * @return On success, sample start time in track timescale units. 445 | * On error, #MP4_INVALID_TIMESTAMP. 446 | * 447 | * @see MP4ConvertFromTrackTimestamp() for how to map this value to another 448 | * timescale. 449 | */ 450 | MP4V2_EXPORT 451 | MP4Timestamp MP4GetSampleTime( 452 | MP4FileHandle hFile, 453 | MP4TrackId trackId, 454 | MP4SampleId sampleId ); 455 | 456 | /** Get the duration of a track sample. 457 | * 458 | * MP4GetSampleDuration returns the duration of the specified sample from 459 | * the specified track in the track timescale units. 460 | * 461 | * @param hFile handle of file for operation. 462 | * @param trackId id of track for operation. 463 | * @param sampleId id of sample for operation. Caveat: the first sample has 464 | * id 1, not 0. 465 | * 466 | * @return On success, the sample duration in track timescale units. 467 | * On error, #MP4_INVALID_DURATION. 468 | * 469 | * @see MP4ConvertFromTrackDuration() for how to map this value to another 470 | * timescale. 471 | */ 472 | MP4V2_EXPORT 473 | MP4Duration MP4GetSampleDuration( 474 | MP4FileHandle hFile, 475 | MP4TrackId trackId, 476 | MP4SampleId sampleId ); 477 | 478 | /** Get the rendering offset of a track sample. 479 | * 480 | * MP4GetSampleRenderingOffset returns the rendering offset of the specified 481 | * sample from the specified track in the track timescale units. 482 | * 483 | * The sample rendering offset is typically zero for all media types other 484 | * than video. For video, encodings such as those defined by MPEG have 485 | * three types of frames: I, P, and B. To increase coding efficiency B 486 | * frames can depend on I or P frames that should be rendered after the B 487 | * frame. However to decode the B frame the I or P frame must already have 488 | * been decoded. This situation is addressed by placing the frames in 489 | * decoding order in the video track, and then setting the rendering offset 490 | * property to indicate when the video frame should actually be rendered to 491 | * the screen. Hence the start time of a sample indicates when it should be 492 | * decoded, the start time plus the rendering offset indicates when it 493 | * should be rendered. 494 | * 495 | * @param hFile handle of file for operation. 496 | * @param trackId id of track for operation. 497 | * @param sampleId id of sample for operation. Caveat: the first sample has 498 | * id 1, not 0. 499 | * 500 | * @return On success, the rendering offset in track timescale units. 501 | * On error, #MP4_INVALID_DURATION. 502 | * 503 | * @see MP4ConvertFromTrackDuration() for how to map this value to another 504 | * timescale. 505 | */ 506 | MP4V2_EXPORT 507 | MP4Duration MP4GetSampleRenderingOffset( 508 | MP4FileHandle hFile, 509 | MP4TrackId trackId, 510 | MP4SampleId sampleId ); 511 | 512 | /** Set the rendering offset of a track sample. 513 | * 514 | * MP4SetSampleRenderingOffset sets the rendering offset of the specified 515 | * sample from the specified track in the track timescale units. 516 | * 517 | * @param hFile handle of file for operation. 518 | * @param trackId id of track for operation. 519 | * @param sampleId id of sample for operation. Caveat: the first sample has 520 | * id 1, not 0. 521 | * @param renderingOffset new offset value in timescale units. 522 | * 523 | * @return true on success, false on failure. 524 | * 525 | * @see MP4ConvertToTrackDuration() for how to map this value from another 526 | * timescale. 527 | * @see MP4GetSampleRenderingOffset() for a description of this sample 528 | * property. 529 | */ 530 | MP4V2_EXPORT 531 | bool MP4SetSampleRenderingOffset( 532 | MP4FileHandle hFile, 533 | MP4TrackId trackId, 534 | MP4SampleId sampleId, 535 | MP4Duration renderingOffset ); 536 | 537 | /** Get sync/random access state of sample. 538 | * 539 | * MP4GetSampleSync returns the state of the sync/random access flag of 540 | * the specified sample from the specified track. 541 | * 542 | * @param hFile handle of file for operation. 543 | * @param trackId id of track for operation. 544 | * @param sampleId id of sample for operation. Caveat: the first sample has 545 | * id 1, not 0. 546 | * 547 | * @return 1 when true, 0 when false. On error, -1. 548 | */ 549 | MP4V2_EXPORT 550 | int8_t MP4GetSampleSync( 551 | MP4FileHandle hFile, 552 | MP4TrackId trackId, 553 | MP4SampleId sampleId ); 554 | 555 | /* @} ***********************************************************************/ 556 | 557 | #endif /* MP4V2_SAMPLE_H */ 558 | -------------------------------------------------------------------------------- /mp4v2/inc/streaming.h: -------------------------------------------------------------------------------- 1 | #ifndef MP4V2_STREAMING_H 2 | #define MP4V2_STREAMING_H 3 | 4 | /**************************************************************************//** 5 | * 6 | * @defgroup mp4_hint MP4v2 Streaming 7 | * @{ 8 | * 9 | *****************************************************************************/ 10 | 11 | MP4V2_EXPORT 12 | bool MP4GetHintTrackRtpPayload( 13 | MP4FileHandle hFile, 14 | MP4TrackId hintTrackId, 15 | char** ppPayloadName DEFAULT(NULL), 16 | uint8_t* pPayloadNumber DEFAULT(NULL), 17 | uint16_t* pMaxPayloadSize DEFAULT(NULL), 18 | char** ppEncodingParams DEFAULT(NULL) ); 19 | 20 | #define MP4_SET_DYNAMIC_PAYLOAD 0xff 21 | 22 | MP4V2_EXPORT 23 | bool MP4SetHintTrackRtpPayload( 24 | MP4FileHandle hFile, 25 | MP4TrackId hintTrackId, 26 | const char* pPayloadName, 27 | uint8_t* pPayloadNumber, 28 | uint16_t maxPayloadSize DEFAULT(0), 29 | const char * encode_params DEFAULT(NULL), 30 | bool include_rtp_map DEFAULT(true), 31 | bool include_mpeg4_esid DEFAULT(true) ); 32 | 33 | MP4V2_EXPORT 34 | const char* MP4GetSessionSdp( 35 | MP4FileHandle hFile ); 36 | 37 | MP4V2_EXPORT 38 | bool MP4SetSessionSdp( 39 | MP4FileHandle hFile, 40 | const char* sdpString ); 41 | 42 | MP4V2_EXPORT 43 | bool MP4AppendSessionSdp( 44 | MP4FileHandle hFile, 45 | const char* sdpString ); 46 | 47 | MP4V2_EXPORT 48 | const char* MP4GetHintTrackSdp( 49 | MP4FileHandle hFile, 50 | MP4TrackId hintTrackId ); 51 | 52 | MP4V2_EXPORT 53 | bool MP4SetHintTrackSdp( 54 | MP4FileHandle hFile, 55 | MP4TrackId hintTrackId, 56 | const char* sdpString ); 57 | 58 | MP4V2_EXPORT 59 | bool MP4AppendHintTrackSdp( 60 | MP4FileHandle hFile, 61 | MP4TrackId hintTrackId, 62 | const char* sdpString ); 63 | 64 | MP4V2_EXPORT 65 | MP4TrackId MP4GetHintTrackReferenceTrackId( 66 | MP4FileHandle hFile, 67 | MP4TrackId hintTrackId ); 68 | 69 | MP4V2_EXPORT 70 | bool MP4ReadRtpHint( 71 | MP4FileHandle hFile, 72 | MP4TrackId hintTrackId, 73 | MP4SampleId hintSampleId, 74 | uint16_t* pNumPackets DEFAULT(NULL) ); 75 | 76 | MP4V2_EXPORT 77 | uint16_t MP4GetRtpHintNumberOfPackets( 78 | MP4FileHandle hFile, 79 | MP4TrackId hintTrackId ); 80 | 81 | MP4V2_EXPORT 82 | int8_t MP4GetRtpPacketBFrame( 83 | MP4FileHandle hFile, 84 | MP4TrackId hintTrackId, 85 | uint16_t packetIndex ); 86 | 87 | MP4V2_EXPORT 88 | int32_t MP4GetRtpPacketTransmitOffset( 89 | MP4FileHandle hFile, 90 | MP4TrackId hintTrackId, 91 | uint16_t packetIndex ); 92 | 93 | MP4V2_EXPORT 94 | bool MP4ReadRtpPacket( 95 | MP4FileHandle hFile, 96 | MP4TrackId hintTrackId, 97 | uint16_t packetIndex, 98 | uint8_t** ppBytes, 99 | uint32_t* pNumBytes, 100 | uint32_t ssrc DEFAULT(0), 101 | bool includeHeader DEFAULT(true), 102 | bool includePayload DEFAULT(true) ); 103 | 104 | MP4V2_EXPORT 105 | MP4Timestamp MP4GetRtpTimestampStart( 106 | MP4FileHandle hFile, 107 | MP4TrackId hintTrackId ); 108 | 109 | MP4V2_EXPORT 110 | bool MP4SetRtpTimestampStart( 111 | MP4FileHandle hFile, 112 | MP4TrackId hintTrackId, 113 | MP4Timestamp rtpStart ); 114 | 115 | MP4V2_EXPORT 116 | bool MP4AddRtpHint( 117 | MP4FileHandle hFile, 118 | MP4TrackId hintTrackId ); 119 | 120 | MP4V2_EXPORT 121 | bool MP4AddRtpVideoHint( 122 | MP4FileHandle hFile, 123 | MP4TrackId hintTrackId, 124 | bool isBframe DEFAULT(false), 125 | uint32_t timestampOffset DEFAULT(0) ); 126 | 127 | MP4V2_EXPORT 128 | bool MP4AddRtpPacket( 129 | MP4FileHandle hFile, 130 | MP4TrackId hintTrackId, 131 | bool setMbit DEFAULT(false), 132 | int32_t transmitOffset DEFAULT(0) ); 133 | 134 | MP4V2_EXPORT 135 | bool MP4AddRtpImmediateData( 136 | MP4FileHandle hFile, 137 | MP4TrackId hintTrackId, 138 | const uint8_t* pBytes, 139 | uint32_t numBytes ); 140 | 141 | MP4V2_EXPORT 142 | bool MP4AddRtpSampleData( 143 | MP4FileHandle hFile, 144 | MP4TrackId hintTrackId, 145 | MP4SampleId sampleId, 146 | uint32_t dataOffset, 147 | uint32_t dataLength ); 148 | 149 | MP4V2_EXPORT 150 | bool MP4AddRtpESConfigurationPacket( 151 | MP4FileHandle hFile, 152 | MP4TrackId hintTrackId ); 153 | 154 | MP4V2_EXPORT 155 | bool MP4WriteRtpHint( 156 | MP4FileHandle hFile, 157 | MP4TrackId hintTrackId, 158 | MP4Duration duration, 159 | bool isSyncSample DEFAULT(true) ); 160 | 161 | /** @} ***********************************************************************/ 162 | 163 | #endif /* MP4V2_STREAMING_H */ 164 | -------------------------------------------------------------------------------- /mp4v2/inc/track.h: -------------------------------------------------------------------------------- 1 | #ifndef MP4V2_TRACK_H 2 | #define MP4V2_TRACK_H 3 | 4 | /**************************************************************************//** 5 | * 6 | * @defgroup mp4_track MP4v2 Track 7 | * @{ 8 | * 9 | *****************************************************************************/ 10 | 11 | /** Add a user defined track. 12 | * 13 | * MP4AddTrack adds a user defined track to the mp4 file. Care should be 14 | * taken to avoid any of the standardized track type names. A useful 15 | * convention is use only uppercase characters for user defined track types. 16 | * The string should be exactly four characters in length, e.g. "MINE". 17 | * 18 | * Note this should not be used to add any of the known track types defined 19 | * in the MP4 standard (ISO/IEC 14496-1:2001). 20 | * 21 | * @param hFile handle of file for operation. 22 | * @param type specifies the type of track to be added. 23 | * @param timeScale the time scale in ticks per second of the track. Default is 1000. 24 | * 25 | * @return On success, the track-id of new track. 26 | * On failure, #MP4_INVALID_TRACK_ID. 27 | */ 28 | MP4V2_EXPORT 29 | MP4TrackId MP4AddTrack( 30 | MP4FileHandle hFile, 31 | const char* type, 32 | uint32_t timeScale DEFAULT(MP4_MSECS_TIME_SCALE) ); 33 | 34 | /** Add an MPEG-4 systems track. 35 | * 36 | * MP4AddSystemsTrack adds an MPEG-4 Systems track to the mp4 file. Note 37 | * this should not be used to add OD or scene tracks, MP4AddODTrack() and 38 | * MP4AddSceneTrack() should be used for those purposes. Other known 39 | * MPEG-4 System track types are: 40 | * @li #MP4_CLOCK_TRACK_TYPE 41 | * @li #MP4_MPEG7_TRACK_TYPE 42 | * @li #MP4_OCI_TRACK_TYPE 43 | * @li #MP4_IPMP_TRACK_TYPE 44 | * @li #MP4_MPEGJ_TRACK_TYPE 45 | * 46 | * @param hFile handle of file for operation. 47 | * @param type specifies the type of track to be added. 48 | * 49 | * @return On success, the track-id of new track. 50 | * On failure, #MP4_INVALID_TRACK_ID. 51 | */ 52 | MP4V2_EXPORT 53 | MP4TrackId MP4AddSystemsTrack( 54 | MP4FileHandle hFile, 55 | const char* type ); 56 | 57 | /** Add a object descriptor (OD) track. 58 | * 59 | * MP4AddODTrack adds an object descriptor (aka OD) track to the mp4 file. 60 | * MP4WriteSample() can then be used to add the desired OD commands to the 61 | * track. The burden is currently on the calling application to understand 62 | * OD. 63 | * 64 | * Those wishing to have a simple audio/video scene without understanding 65 | * OD may wish to use MP4MakeIsmaCompliant() to create the minimal OD and 66 | * BIFS information. 67 | * 68 | * @param hFile handle of file for operation. 69 | * 70 | * @return On success, the track-id of new track. 71 | * On failure, #MP4_INVALID_TRACK_ID. 72 | */ 73 | MP4V2_EXPORT 74 | MP4TrackId MP4AddODTrack( 75 | MP4FileHandle hFile ); 76 | 77 | /** Add a scene (BIFS) track. 78 | * 79 | * MP4AddSceneTrack adds a scene (aka BIFS) track to the mp4 file. 80 | * MP4WriteSample() can then be used to add the desired BIFS commands to 81 | * the track. The burden is currently on the calling application to 82 | * understand BIFS. 83 | * 84 | * Those wishing to have a simple audio/video scene without understanding 85 | * BIFS may wish to use MP4MakeIsmaCompliant() to create the minimal OD 86 | * and BIFS information. 87 | * 88 | * @param hFile handle of file for operation. 89 | * 90 | * @return On success, the track-id of new track. 91 | * On failure, #MP4_INVALID_TRACK_ID. 92 | */ 93 | MP4V2_EXPORT 94 | MP4TrackId MP4AddSceneTrack( 95 | MP4FileHandle hFile ); 96 | 97 | /** Add audio track to mp4 file. 98 | * 99 | * MP4AddAudioTrack adds an audio track to the mp4 file. MP4WriteSample() 100 | * can then be used to add the desired audio samples. 101 | * 102 | * It is recommended that the time scale be set to the sampling frequency 103 | * (eg. 44100 Hz) of the audio so as to preserve the timing information 104 | * accurately. 105 | * 106 | * If the audio encoding uses a fixed duration for each sample that should 107 | * be specified here. If not then the value #MP4_INVALID_DURATION 108 | * should be given for the sampleDuration argument. 109 | * 110 | * @param hFile handle of file for operation. 111 | * @param timeScale the time scale in ticks per second of the track. 112 | * @param sampleDuration the fixed duration for all track samples. 113 | * Caveat: the value should be in track-timescale units. 114 | * @param audioType the audio encoding type. 115 | * See MP4GetTrackEsdsObjectTypeId() for known values. 116 | * 117 | * @return On success, the track-id of the new track. 118 | * On error, #MP4_INVALID_TRACK_ID. 119 | */ 120 | MP4V2_EXPORT 121 | MP4TrackId MP4AddAudioTrack( 122 | MP4FileHandle hFile, 123 | uint32_t timeScale, 124 | MP4Duration sampleDuration, 125 | uint8_t audioType DEFAULT(MP4_MPEG4_AUDIO_TYPE) ); 126 | 127 | /** Add ulaw track to mp4 file. 128 | * 129 | * MP4AddULawAudioTrack adds a ulaw track to the mp4 file. MP4WriteSample() 130 | * can then be used to add the desired audio samples. 131 | * 132 | * @param hFile handle of file for operation. 133 | * @param timeScale the time scale in ticks per second of the track. 134 | * 135 | * @return On success, the track-id of the new track. 136 | * On error, #MP4_INVALID_TRACK_ID. 137 | */ 138 | MP4V2_EXPORT 139 | MP4TrackId MP4AddULawAudioTrack( 140 | MP4FileHandle hFile, 141 | uint32_t timeScale); 142 | 143 | /** Add alaw track to mp4 file. 144 | * 145 | * MP4AddALawAudioTrack adds a alaw track to the mp4 file. MP4WriteSample() 146 | * can then be used to add the desired audio samples. 147 | * 148 | * @param hFile handle of file for operation. 149 | * @param timeScale the time scale in ticks per second of the track. 150 | * 151 | * @return On success, the track-id of the new track. 152 | * On error, #MP4_INVALID_TRACK_ID. 153 | */ 154 | MP4V2_EXPORT 155 | MP4TrackId MP4AddALawAudioTrack( 156 | MP4FileHandle hFile, 157 | uint32_t timeScale); 158 | 159 | MP4V2_EXPORT 160 | MP4TrackId MP4AddAC3AudioTrack( 161 | MP4FileHandle hFile, 162 | uint32_t samplingRate, 163 | uint8_t fscod, 164 | uint8_t bsid, 165 | uint8_t bsmod, 166 | uint8_t acmod, 167 | uint8_t lfeon, 168 | uint8_t bit_rate_code ); 169 | 170 | MP4V2_EXPORT 171 | MP4TrackId MP4AddAmrAudioTrack( 172 | MP4FileHandle hFile, 173 | uint32_t timeScale, 174 | uint16_t modeSet, 175 | uint8_t modeChangePeriod, 176 | uint8_t framesPerSample, 177 | bool isAmrWB ); 178 | 179 | MP4V2_EXPORT 180 | void MP4SetAmrVendor( 181 | MP4FileHandle hFile, 182 | MP4TrackId trackId, 183 | uint32_t vendor ); 184 | 185 | MP4V2_EXPORT 186 | void MP4SetAmrDecoderVersion( 187 | MP4FileHandle hFile, 188 | MP4TrackId trackId, 189 | uint8_t decoderVersion ); 190 | 191 | MP4V2_EXPORT 192 | void MP4SetAmrModeSet( 193 | MP4FileHandle hFile, 194 | MP4TrackId trakId, 195 | uint16_t modeSet ); 196 | 197 | MP4V2_EXPORT 198 | uint16_t MP4GetAmrModeSet( 199 | MP4FileHandle hFile, 200 | MP4TrackId trackId ); 201 | 202 | MP4V2_EXPORT 203 | MP4TrackId MP4AddHrefTrack( 204 | MP4FileHandle hFile, 205 | uint32_t timeScale, 206 | MP4Duration sampleDuration, 207 | const char* base_url DEFAULT(NULL) ); 208 | 209 | MP4V2_EXPORT 210 | const char* MP4GetHrefTrackBaseUrl( 211 | MP4FileHandle hFile, 212 | MP4TrackId trackId ); 213 | 214 | /** Add a video track. 215 | * 216 | * MP4AddVideoTrack adds a video track to the mp4 file. MP4WriteSample() 217 | * can then be used to add the desired video samples. 218 | * 219 | * It is recommended that the time scale be set to 90000 so as to preserve 220 | * the timing information accurately for the range of video frame rates 221 | * commonly in use. 222 | * 223 | * If the video frame rate is to be fixed then the sampleDuration argument 224 | * should be give the appropriate fixed value. If the video frame rate is 225 | * to be variable then the value #MP4_INVALID_DURATION should be 226 | * given for the sampleDuration argument. 227 | * 228 | * @param hFile handle of file for operation. 229 | * @param timeScale the timescale in ticks per second of the track. 230 | * @param sampleDuration specifies fixed sample duration for all track 231 | * samples. Caveat: the value should be in track timescale units. 232 | * @param width specifies the video frame width in pixels. 233 | * @param height specifies the video frame height in pixels. 234 | * @param videoType specifies the video encoding type. 235 | * See MP4GetTrackVideoType() for known values. 236 | * 237 | * @return On success, the track-id of the new track. 238 | * On error, #MP4_INVALID_TRACK_ID. 239 | */ 240 | MP4V2_EXPORT 241 | MP4TrackId MP4AddVideoTrack( 242 | MP4FileHandle hFile, 243 | uint32_t timeScale, 244 | MP4Duration sampleDuration, 245 | uint16_t width, 246 | uint16_t height, 247 | uint8_t videoType DEFAULT(MP4_MPEG4_VIDEO_TYPE) ); 248 | 249 | MP4V2_EXPORT 250 | MP4TrackId MP4AddH264VideoTrack( 251 | MP4FileHandle hFile, 252 | uint32_t timeScale, 253 | MP4Duration sampleDuration, 254 | uint16_t width, 255 | uint16_t height, 256 | uint8_t AVCProfileIndication, 257 | uint8_t profile_compat, 258 | uint8_t AVCLevelIndication, 259 | uint8_t sampleLenFieldSizeMinusOne ); 260 | 261 | MP4V2_EXPORT 262 | void MP4AddH264SequenceParameterSet( 263 | MP4FileHandle hFile, 264 | MP4TrackId trackId, 265 | const uint8_t* pSequence, 266 | uint16_t sequenceLen ); 267 | 268 | MP4V2_EXPORT 269 | void MP4AddH264PictureParameterSet( 270 | MP4FileHandle hFile, 271 | MP4TrackId trackId, 272 | const uint8_t* pPict, 273 | uint16_t pictLen ); 274 | 275 | MP4V2_EXPORT 276 | void MP4SetH263Vendor( 277 | MP4FileHandle hFile, 278 | MP4TrackId trackId, 279 | uint32_t vendor ); 280 | 281 | MP4V2_EXPORT 282 | void MP4SetH263DecoderVersion( 283 | MP4FileHandle hFile, 284 | MP4TrackId trackId, 285 | uint8_t decoderVersion ); 286 | 287 | MP4V2_EXPORT 288 | void MP4SetH263Bitrates( 289 | MP4FileHandle hFile, 290 | MP4TrackId trackId, 291 | uint32_t avgBitrate, 292 | uint32_t maxBitrate ); 293 | 294 | MP4V2_EXPORT 295 | MP4TrackId MP4AddH263VideoTrack( 296 | MP4FileHandle hFile, 297 | uint32_t timeScale, 298 | MP4Duration sampleDuration, 299 | uint16_t width, 300 | uint16_t height, 301 | uint8_t h263Level, 302 | uint8_t h263Profile, 303 | uint32_t avgBitrate, 304 | uint32_t maxBitrate ); 305 | 306 | /** Add a hint track. 307 | * 308 | * MP4AddHintTrack adds a hint track to the mp4 file. A hint track is used 309 | * to describe how to send the reference media track over a particular 310 | * network transport. In the case of the IETF RTP protocol, the hint track 311 | * describes how the media data should be placed into packets and any 312 | * media specific protocol headers that should be added. 313 | * 314 | * Typically there is a one to one correspondence between reference media 315 | * track samples and hint track samples. The start time, duration, and 316 | * sync flags are typically the same, however provisions are made for 317 | * deviations from this rule. 318 | * 319 | * The MP4 library provides extensive support for RTP hint tracks. This 320 | * includes a easy to use API to create RTP hint tracks, and read out 321 | * fully constructed RTP packets based on the hint track. 322 | * 323 | * @param hFile handle of file for operation. 324 | * @param refTrackId specifies the reference media track for this hint track. 325 | * 326 | * @return On success, the track-id of the new track. 327 | * On error, #MP4_INVALID_TRACK_ID. 328 | */ 329 | MP4V2_EXPORT 330 | MP4TrackId MP4AddHintTrack( 331 | MP4FileHandle hFile, 332 | MP4TrackId refTrackId ); 333 | 334 | MP4V2_EXPORT 335 | MP4TrackId MP4AddTextTrack( 336 | MP4FileHandle hFile, 337 | MP4TrackId refTrackId ); 338 | 339 | MP4V2_EXPORT 340 | MP4TrackId MP4AddSubtitleTrack( 341 | MP4FileHandle hFile, 342 | uint32_t timescale, 343 | uint16_t width, 344 | uint16_t height ); 345 | 346 | MP4V2_EXPORT 347 | MP4TrackId MP4AddSubpicTrack( 348 | MP4FileHandle hFile, 349 | uint32_t timescale, 350 | uint16_t width, 351 | uint16_t height ); 352 | 353 | MP4V2_EXPORT 354 | MP4TrackId MP4AddPixelAspectRatio( 355 | MP4FileHandle hFile, 356 | MP4TrackId refTrackId, 357 | uint32_t hSpacing, 358 | uint32_t vSpacing ); 359 | 360 | MP4V2_EXPORT 361 | MP4TrackId MP4AddColr( 362 | MP4FileHandle hFile, 363 | MP4TrackId refTrackId, 364 | uint16_t primary, 365 | uint16_t transfer, 366 | uint16_t matrix ); 367 | 368 | MP4V2_EXPORT 369 | MP4TrackId MP4CloneTrack( 370 | MP4FileHandle srcFile, 371 | MP4TrackId srcTrackId, 372 | MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE), 373 | MP4TrackId dstHintTrackReferenceTrack DEFAULT(MP4_INVALID_TRACK_ID) ); 374 | 375 | MP4V2_EXPORT 376 | MP4TrackId MP4CopyTrack( 377 | MP4FileHandle srcFile, 378 | MP4TrackId srcTrackId, 379 | MP4FileHandle dstFile DEFAULT(MP4_INVALID_FILE_HANDLE), 380 | bool applyEdits DEFAULT(false), 381 | MP4TrackId dstHintTrackReferenceTrack DEFAULT(MP4_INVALID_TRACK_ID) ); 382 | 383 | MP4V2_EXPORT 384 | bool MP4DeleteTrack( 385 | MP4FileHandle hFile, 386 | MP4TrackId trackId ); 387 | 388 | MP4V2_EXPORT 389 | uint32_t MP4GetNumberOfTracks( 390 | MP4FileHandle hFile, 391 | const char* type DEFAULT(NULL), 392 | uint8_t subType DEFAULT(0) ); 393 | 394 | MP4V2_EXPORT 395 | MP4TrackId MP4FindTrackId( 396 | MP4FileHandle hFile, 397 | uint16_t index, 398 | const char* type DEFAULT(NULL), 399 | uint8_t subType DEFAULT(0) ); 400 | 401 | MP4V2_EXPORT 402 | uint16_t MP4FindTrackIndex( 403 | MP4FileHandle hFile, 404 | MP4TrackId trackId ); 405 | 406 | /** Get maximum duration of chunk. 407 | * 408 | * MP4GetTrackDurationPerChunk gets the maximum duration for each chunk. 409 | * 410 | * @param hFile handle of file for operation. 411 | * @param trackId id of track for operation. 412 | * @param duration out value of duration in track timescale units. 413 | * 414 | * return true on success, false on failure. 415 | */ 416 | MP4V2_EXPORT 417 | bool MP4GetTrackDurationPerChunk( 418 | MP4FileHandle hFile, 419 | MP4TrackId trackId, 420 | MP4Duration* duration ); 421 | 422 | /** Set maximum duration of chunk. 423 | * 424 | * MP4SetTrackDurationPerChunk sets the maximum duration for each chunk. 425 | * 426 | * @param hFile handle of file for operation. 427 | * @param trackId id of track for operation. 428 | * @param duration in timescale units. 429 | * 430 | * @return true on success, false on failure. 431 | */ 432 | MP4V2_EXPORT 433 | bool MP4SetTrackDurationPerChunk( 434 | MP4FileHandle hFile, 435 | MP4TrackId trackId, 436 | MP4Duration duration ); 437 | 438 | /** 439 | * @param hFile handle of file for operation. 440 | * @param trackId id of track for operation. 441 | * 442 | * @return true on success, false on failure. 443 | */ 444 | MP4V2_EXPORT 445 | bool MP4AddIPodUUID( 446 | MP4FileHandle hFile, 447 | MP4TrackId trackId ); 448 | 449 | /** @} ***********************************************************************/ 450 | 451 | #endif /* MP4V2_TRACK_H */ 452 | -------------------------------------------------------------------------------- /mp4v2/inc/track_prop.h: -------------------------------------------------------------------------------- 1 | #ifndef MP4V2_TRACK_PROP_H 2 | #define MP4V2_TRACK_PROP_H 3 | 4 | /**************************************************************************//** 5 | * 6 | * @defgroup mp4_track_prop MP4v2 Track Property 7 | * @{ 8 | * 9 | *****************************************************************************/ 10 | 11 | /* specific track properties */ 12 | 13 | MP4V2_EXPORT 14 | bool MP4HaveTrackAtom( 15 | MP4FileHandle hFile, 16 | MP4TrackId trackId, 17 | const char* atomname ); 18 | 19 | /** Get the track type. 20 | * 21 | * MP4GetTrackType gets the type of the track with the specified track id. 22 | * 23 | * Note: the library does not provide a MP4SetTrackType function, the 24 | * track type needs to be specified when the track is created, e.g. 25 | * MP4AddSystemsTrack(MP4_OCI_TRACK_TYPE). 26 | * 27 | * Known track types are: 28 | * @li #MP4_OD_TRACK_TYPE 29 | * @li #MP4_SCENE_TRACK_TYPE 30 | * @li #MP4_AUDIO_TRACK_TYPE 31 | * @li #MP4_VIDEO_TRACK_TYPE 32 | * @li #MP4_HINT_TRACK_TYPE 33 | * @li #MP4_CNTL_TRACK_TYPE 34 | * @li #MP4_TEXT_TRACK_TYPE 35 | * @li #MP4_CLOCK_TRACK_TYPE 36 | * @li #MP4_MPEG7_TRACK_TYPE 37 | * @li #MP4_OCI_TRACK_TYPE 38 | * @li #MP4_IPMP_TRACK_TYPE 39 | * @li #MP4_MPEGJ_TRACK_TYPE 40 | * 41 | * @param hFile handle of file for operation. 42 | * @param trackId id of track for operation. 43 | * 44 | * @return On success, a string indicating track type. On failure, NULL. 45 | */ 46 | MP4V2_EXPORT 47 | const char* MP4GetTrackType( 48 | MP4FileHandle hFile, 49 | MP4TrackId trackId ); 50 | 51 | MP4V2_EXPORT 52 | const char* MP4GetTrackMediaDataName( 53 | MP4FileHandle hFile, 54 | MP4TrackId trackId ); 55 | 56 | /* 57 | * MP4GetTrackMediaDataOriginalFormat is to be used to get the original 58 | * MediaDataName if a track has been encrypted. 59 | */ 60 | 61 | MP4V2_EXPORT 62 | bool MP4GetTrackMediaDataOriginalFormat( 63 | MP4FileHandle hFile, 64 | MP4TrackId trackId, 65 | char* originalFormat, 66 | uint32_t buflen ); 67 | 68 | MP4V2_EXPORT 69 | MP4Duration MP4GetTrackDuration( 70 | MP4FileHandle hFile, 71 | MP4TrackId trackId ); 72 | 73 | /** Get the time scale of a track. 74 | * 75 | * MP4GetTrackTimeScale returns the time scale of the specified track in 76 | * the mp4 file. The time scale determines the number of clock ticks per 77 | * second for this track. 78 | * 79 | * @param hFile handle of file for operation. 80 | * @param trackId id of track for operation. 81 | * 82 | * @return timescale (ticks per second) of the track in the mp4 file. 83 | */ 84 | MP4V2_EXPORT 85 | uint32_t MP4GetTrackTimeScale( 86 | MP4FileHandle hFile, 87 | MP4TrackId trackId ); 88 | 89 | /** Set the time scale of a track. 90 | * 91 | * MP4SetTrackTimeScale sets the time scale of the specified track in the 92 | * mp4 file. The time scale determines the number of clock ticks per 93 | * second for this track. 94 | * 95 | * Typically this value is set once when the track is created. However 96 | * this call can be used to modify the value if that is desired. Since 97 | * track sample durations are expressed in units of the track time scale, 98 | * any change to the time scale value will effect the real time duration 99 | * of the samples. 100 | * 101 | * @param hFile handle of file for operation. 102 | * @param trackId id of track for operation. 103 | * @param timeScale desired time scale for the track. 104 | * 105 | * @return true on success, false on failure. 106 | */ 107 | MP4V2_EXPORT 108 | bool MP4SetTrackTimeScale( 109 | MP4FileHandle hFile, 110 | MP4TrackId trackId, 111 | uint32_t value ); 112 | 113 | /** Get ISO-639-2/T language code of a track. 114 | * The language code is a 3-char alpha code consisting of lower-case letters. 115 | * 116 | * @param hFile handle of file for operation. 117 | * @param trackId id of track for operation. 118 | * @param code buffer to hold 3-char+null (4-bytes total). 119 | * 120 | * @return true on success, false on failure. 121 | */ 122 | MP4V2_EXPORT 123 | bool MP4GetTrackLanguage( 124 | MP4FileHandle hFile, 125 | MP4TrackId trackId, 126 | char* code ); 127 | 128 | /** Set ISO-639-2/T language code of a track. 129 | * The language code is a 3-char alpha code consisting of lower-case letters. 130 | * 131 | * @param hFile handle of file for operation. 132 | * @param trackId id of track for operation. 133 | * @param code 3-char language code. 134 | * 135 | * @return true on success, false on failure. 136 | */ 137 | MP4V2_EXPORT 138 | bool MP4SetTrackLanguage( 139 | MP4FileHandle hFile, 140 | MP4TrackId trackId, 141 | const char* code ); 142 | 143 | /** Get track name. 144 | * 145 | * MP4GetTrackName gets the name of the track via udta.name property. 146 | * 147 | * @param hFile handle of file for operation. 148 | * @param trackId id of track for operation. 149 | * 150 | * @return true on success, false on failure. 151 | */ 152 | MP4V2_EXPORT 153 | bool MP4GetTrackName( 154 | MP4FileHandle hFile, 155 | MP4TrackId trackId, 156 | char** name ); 157 | 158 | /** Set track name. 159 | * 160 | * MP4SetTrackName sets the name of the track via udta.name property. 161 | * The udta atom is created if needed. 162 | * 163 | * @param hFile handle of file for operation. 164 | * @param trackId id of track for operation. 165 | * 166 | * @return true on success, false on failure. 167 | */ 168 | MP4V2_EXPORT 169 | bool MP4SetTrackName( 170 | MP4FileHandle hFile, 171 | MP4TrackId trackId, 172 | const char* name ); 173 | 174 | MP4V2_EXPORT 175 | uint8_t MP4GetTrackAudioMpeg4Type( 176 | MP4FileHandle hFile, 177 | MP4TrackId trackId ); 178 | 179 | MP4V2_EXPORT 180 | uint8_t MP4GetTrackEsdsObjectTypeId( 181 | MP4FileHandle hFile, 182 | MP4TrackId trackId ); 183 | 184 | /* returns MP4_INVALID_DURATION if track samples do not have a fixed duration */ 185 | MP4V2_EXPORT 186 | MP4Duration MP4GetTrackFixedSampleDuration( 187 | MP4FileHandle hFile, 188 | MP4TrackId trackId ); 189 | 190 | MP4V2_EXPORT 191 | uint32_t MP4GetTrackBitRate( 192 | MP4FileHandle hFile, 193 | MP4TrackId trackId ); 194 | 195 | MP4V2_EXPORT 196 | bool MP4GetTrackVideoMetadata( 197 | MP4FileHandle hFile, 198 | MP4TrackId trackId, 199 | uint8_t** ppConfig, 200 | uint32_t* pConfigSize ); 201 | 202 | MP4V2_EXPORT 203 | bool MP4GetTrackESConfiguration( 204 | MP4FileHandle hFile, 205 | MP4TrackId trackId, 206 | uint8_t** ppConfig, 207 | uint32_t* pConfigSize ); 208 | 209 | MP4V2_EXPORT 210 | bool MP4SetTrackESConfiguration( 211 | MP4FileHandle hFile, 212 | MP4TrackId trackId, 213 | const uint8_t* pConfig, 214 | uint32_t configSize ); 215 | 216 | /* h264 information routines */ 217 | MP4V2_EXPORT 218 | bool MP4GetTrackH264ProfileLevel( 219 | MP4FileHandle hFile, 220 | MP4TrackId trackId, 221 | uint8_t* pProfile, 222 | uint8_t* pLevel ); 223 | 224 | MP4V2_EXPORT 225 | bool MP4GetTrackH264SeqPictHeaders( 226 | MP4FileHandle hFile, 227 | MP4TrackId trackId, 228 | uint8_t*** pSeqHeaders, 229 | uint32_t** pSeqHeaderSize, 230 | uint8_t*** pPictHeader, 231 | uint32_t** pPictHeaderSize ); 232 | 233 | MP4V2_EXPORT 234 | bool MP4GetTrackH264LengthSize( 235 | MP4FileHandle hFile, 236 | MP4TrackId trackId, 237 | uint32_t* pLength ); 238 | 239 | MP4V2_EXPORT 240 | MP4SampleId MP4GetTrackNumberOfSamples( 241 | MP4FileHandle hFile, 242 | MP4TrackId trackId ); 243 | 244 | MP4V2_EXPORT 245 | uint16_t MP4GetTrackVideoWidth( 246 | MP4FileHandle hFile, 247 | MP4TrackId trackId ); 248 | 249 | MP4V2_EXPORT 250 | uint16_t MP4GetTrackVideoHeight( 251 | MP4FileHandle hFile, 252 | MP4TrackId trackId ); 253 | 254 | MP4V2_EXPORT 255 | double MP4GetTrackVideoFrameRate( 256 | MP4FileHandle hFile, 257 | MP4TrackId trackId ); 258 | 259 | MP4V2_EXPORT 260 | int MP4GetTrackAudioChannels( 261 | MP4FileHandle hFile, 262 | MP4TrackId trackId ); 263 | 264 | MP4V2_EXPORT 265 | bool MP4IsIsmaCrypMediaTrack( 266 | MP4FileHandle hFile, 267 | MP4TrackId trackId ); 268 | 269 | /* generic track properties */ 270 | 271 | MP4V2_EXPORT 272 | bool MP4HaveTrackAtom( 273 | MP4FileHandle hFile, 274 | MP4TrackId trackId, 275 | const char* atomName ); 276 | 277 | MP4V2_EXPORT 278 | bool MP4GetTrackIntegerProperty( 279 | MP4FileHandle hFile, 280 | MP4TrackId trackId, 281 | const char* propName, 282 | uint64_t* retvalue ); 283 | 284 | MP4V2_EXPORT 285 | bool MP4GetTrackFloatProperty( 286 | MP4FileHandle hFile, 287 | MP4TrackId trackId, 288 | const char* propName, 289 | float* ret_value ); 290 | 291 | MP4V2_EXPORT 292 | bool MP4GetTrackStringProperty( 293 | MP4FileHandle hFile, 294 | MP4TrackId trackId, 295 | const char* propName, 296 | const char** retvalue ); 297 | 298 | MP4V2_EXPORT 299 | bool MP4GetTrackBytesProperty( 300 | MP4FileHandle hFile, 301 | MP4TrackId trackId, 302 | const char* propName, 303 | uint8_t** ppValue, 304 | uint32_t* pValueSize ); 305 | 306 | MP4V2_EXPORT 307 | bool MP4SetTrackIntegerProperty( 308 | MP4FileHandle hFile, 309 | MP4TrackId trackId, 310 | const char* propName, 311 | int64_t value ); 312 | 313 | MP4V2_EXPORT 314 | bool MP4SetTrackFloatProperty( 315 | MP4FileHandle hFile, 316 | MP4TrackId trackId, 317 | const char* propName, 318 | float value ); 319 | 320 | MP4V2_EXPORT 321 | bool MP4SetTrackStringProperty( 322 | MP4FileHandle hFile, 323 | MP4TrackId trackId, 324 | const char* propName, 325 | const char* value ); 326 | 327 | MP4V2_EXPORT 328 | bool MP4SetTrackBytesProperty( 329 | MP4FileHandle hFile, 330 | MP4TrackId trackId, 331 | const char* propName, 332 | const uint8_t* pValue, 333 | uint32_t valueSize); 334 | 335 | /** @} ***********************************************************************/ 336 | 337 | #endif /* MP4V2_TRACK_PROP_H */ 338 | -------------------------------------------------------------------------------- /mp4v2/libmp4v2.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itisyang/mp4-recorder/0de7642becda0374b4dbb644c053fcc0f9d8f2bc/mp4v2/libmp4v2.dll -------------------------------------------------------------------------------- /mp4v2/libmp4v2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itisyang/mp4-recorder/0de7642becda0374b4dbb644c053fcc0f9d8f2bc/mp4v2/libmp4v2.lib -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # mp4-recorder 2 | > using lib-mp4v2 and lib-fdk-aac to record mp4 file 3 | 4 | ## basic design 5 | > pcm + h264 = mp4 6 | 7 | ## modules 8 | #### Mp4Recorder 9 | > class of mp4 recorder 10 | 11 | #### libmp4v2 12 | > https://code.google.com/archive/p/mp4v2/ 13 | #### libfdk-aac 14 | > https://sourceforge.net/projects/opencore-amr/files/fdk-aac/ 15 | --------------------------------------------------------------------------------