├── README.md ├── app ├── .gitignore ├── CMakeLists.txt ├── build.gradle ├── libs │ ├── armeabi-v7a │ │ └── libmp4v2.so │ └── include │ │ ├── com_seuic_jni_Mp4v2Helper.h │ │ └── mp4v2 │ │ ├── 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 ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── chezi008 │ │ └── mp4v2demo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── cpp │ │ ├── Mp4v2Helper.c │ │ ├── mp4record.c │ │ └── mp4record.h │ ├── java │ │ └── com │ │ │ ├── me │ │ │ └── archko │ │ │ │ └── mp4 │ │ │ │ ├── SLApolloUtils.java │ │ │ │ └── TestMp4Activity.java │ │ │ └── seuic │ │ │ └── jni │ │ │ └── Mp4v2Helper.java │ └── res │ │ ├── drawable-hdpi │ │ └── ic_launcher.png │ │ ├── drawable-mdpi │ │ └── ic_launcher.png │ │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ │ ├── layout │ │ └── main_layout.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── chezi008 │ └── mp4v2demo │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── local.properties ├── mtv.h264 └── settings.gradle /README.md: -------------------------------------------------------------------------------- 1 | # Mp4v2Demo 2 | Android使用Mp4v2用h264流和acc流合成mp4 3 | 使用mp4v2源码在linux系统下生成对应的so包,AndroidStudio用最新的cmake利用mp4v2库生成mp4文件,用h264流生成mp4文件同一个套路,android进行h264的解码,将生成的每一帧喂入mp4b2库。(目前只做了视频写入,没有进行音频写入) 4 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | #CMake版本信息 3 | cmake_minimum_required(VERSION 3.4.1) 4 | 5 | set(distribution_DIR ${CMAKE_SOURCE_DIR}/../../../../libs) 6 | #支持-std=gnu++11 7 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11") 8 | 9 | 10 | add_library( mp4v2 11 | SHARED 12 | IMPORTED ) 13 | set_target_properties( mp4v2 14 | PROPERTIES IMPORTED_LOCATION 15 | ../../../../libs/armeabi-v7a/libmp4v2.so ) 16 | include_directories(libs/include) 17 | 18 | 19 | 20 | add_library(Mp4v2Helper SHARED 21 | src/main/cpp/Mp4v2Helper.c 22 | ) 23 | 24 | 25 | find_library( # Sets the name of the path variable. 26 | log-lib 27 | 28 | # Specifies the name of the NDK library that 29 | # you want CMake to locate. 30 | log ) 31 | 32 | target_link_libraries( Mp4v2Helper mp4v2 ${log-lib} ) 33 | 34 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.1" 6 | defaultConfig { 7 | applicationId "com.chezi008.mp4v2demo" 8 | minSdkVersion 16 9 | targetSdkVersion 22 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | externalNativeBuild { 14 | cmake { 15 | cppFlags "-std=c++11 -fexceptions" 16 | } 17 | } 18 | ndk { 19 | abiFilters "armeabi-v7a" 20 | } 21 | } 22 | buildTypes { 23 | release { 24 | minifyEnabled false 25 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 26 | } 27 | } 28 | externalNativeBuild { 29 | cmake { 30 | path "CMakeLists.txt" 31 | } 32 | } 33 | sourceSets.main { 34 | jni.srcDirs = [] 35 | jniLibs.srcDirs = ['libs'] 36 | } 37 | } 38 | 39 | dependencies { 40 | compile fileTree(dir: 'libs', include: ['*.jar']) 41 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 42 | exclude group: 'com.android.support', module: 'support-annotations' 43 | }) 44 | compile 'com.android.support:appcompat-v7:25.3.1' 45 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 46 | testCompile 'junit:junit:4.12' 47 | } 48 | -------------------------------------------------------------------------------- /app/libs/armeabi-v7a/libmp4v2.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chezi008/Mp4v2Demo/ca2db3839b2e07524a1016a88e50d6e9c1c89438/app/libs/armeabi-v7a/libmp4v2.so -------------------------------------------------------------------------------- /app/libs/include/com_seuic_jni_Mp4v2Helper.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class com_seuic_jni_Mp4v2Helper */ 4 | 5 | #ifndef _Included_com_seuic_jni_Mp4v2Helper 6 | #define _Included_com_seuic_jni_Mp4v2Helper 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | /* 11 | * Class: com_seuic_jni_Mp4v2Helper 12 | * Method: initMp4Encoder 13 | * Signature: (Ljava/lang/String;II)I 14 | */ 15 | JNIEXPORT jint JNICALL Java_com_seuic_jni_Mp4v2Helper_initMp4Encoder 16 | (JNIEnv *, jclass, jstring, jint, jint); 17 | 18 | /* 19 | * Class: com_seuic_jni_Mp4v2Helper 20 | * Method: mp4VEncode 21 | * Signature: ([BI)I 22 | */ 23 | JNIEXPORT jint JNICALL Java_com_seuic_jni_Mp4v2Helper_mp4VEncode 24 | (JNIEnv *, jclass, jbyteArray, jint); 25 | 26 | /* 27 | * Class: com_seuic_jni_Mp4v2Helper 28 | * Method: mp4AEncode 29 | * Signature: ([BI)I 30 | */ 31 | JNIEXPORT jint JNICALL Java_com_seuic_jni_Mp4v2Helper_mp4AEncode 32 | (JNIEnv *, jclass, jbyteArray, jint); 33 | 34 | /* 35 | * Class: com_seuic_jni_Mp4v2Helper 36 | * Method: closeMp4Encoder 37 | * Signature: ()V 38 | */ 39 | JNIEXPORT void JNICALL Java_com_seuic_jni_Mp4v2Helper_closeMp4Encoder 40 | (JNIEnv *, jclass); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | #endif 46 | -------------------------------------------------------------------------------- /app/libs/include/mp4v2/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 | -------------------------------------------------------------------------------- /app/libs/include/mp4v2/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 | -------------------------------------------------------------------------------- /app/libs/include/mp4v2/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 | -------------------------------------------------------------------------------- /app/libs/include/mp4v2/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 | -------------------------------------------------------------------------------- /app/libs/include/mp4v2/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 | -------------------------------------------------------------------------------- /app/libs/include/mp4v2/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 | -------------------------------------------------------------------------------- /app/libs/include/mp4v2/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 | -------------------------------------------------------------------------------- /app/libs/include/mp4v2/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 36 | #include 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 | -------------------------------------------------------------------------------- /app/libs/include/mp4v2/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 | -------------------------------------------------------------------------------- /app/libs/include/mp4v2/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 | -------------------------------------------------------------------------------- /app/libs/include/mp4v2/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 | -------------------------------------------------------------------------------- /app/libs/include/mp4v2/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 | -------------------------------------------------------------------------------- /app/libs/include/mp4v2/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 | -------------------------------------------------------------------------------- /app/libs/include/mp4v2/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 | -------------------------------------------------------------------------------- /app/libs/include/mp4v2/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 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\Android\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/chezi008/mp4v2demo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.chezi008.mp4v2demo; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.chezi008.mp4v2demo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 36 | 37 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /app/src/main/cpp/Mp4v2Helper.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Administrator on 2017/4/12. 3 | // 4 | #include 5 | #include "mp4record.h" 6 | #include "mp4record.c" 7 | #import 8 | 9 | MP4V2_CONTEXT *_mp4Handle; 10 | 11 | /** 12 | * 初始化 13 | * @param env 14 | * @param jclass 15 | * @param path 16 | * @param width 17 | * @param height 18 | * @return 19 | */ 20 | jint JNICALL Java_com_seuic_jni_Mp4v2Helper_initMp4Encoder 21 | (JNIEnv *env, jclass jclass, jstring path, jint width, jint height) { 22 | const char *local_title = (*env)->GetStringUTFChars(env, path, NULL); 23 | int m_width = width; 24 | int m_height = height; 25 | _mp4Handle = initMp4Encoder(local_title, m_width, m_height); 26 | return 0; 27 | } 28 | /** 29 | * 添加视频帧的方法 30 | */ 31 | JNIEXPORT jint JNICALL Java_com_seuic_jni_Mp4v2Helper_mp4VEncode 32 | (JNIEnv *env, jclass clz, jbyteArray data, jint size) { 33 | unsigned char *buf = (unsigned char *) (*env)->GetByteArrayElements(env, data, JNI_FALSE); 34 | int nalsize = size; 35 | int reseult = mp4VEncode(_mp4Handle, buf, nalsize); 36 | return reseult; 37 | } 38 | /** 39 | * 添加音频数据 40 | */ 41 | JNIEXPORT jint JNICALL Java_com_seuic_jni_Mp4v2Helper_mp4AEncode 42 | (JNIEnv *env, jclass clz, jbyteArray data, jint size) { 43 | unsigned char *buf = (unsigned char *) (*env)->GetByteArrayElements(env, data, JNI_FALSE); 44 | int nalsize = size; 45 | int reseult = mp4AEncode(_mp4Handle, buf, nalsize); 46 | return reseult; 47 | } 48 | /** 49 | * 释放 50 | */ 51 | JNIEXPORT void JNICALL Java_com_seuic_jni_Mp4v2Helper_closeMp4Encoder 52 | (JNIEnv *env, jclass clz) { 53 | closeMp4Encoder(_mp4Handle); 54 | } 55 | 56 | 57 | -------------------------------------------------------------------------------- /app/src/main/cpp/mp4record.c: -------------------------------------------------------------------------------- 1 | // 2 | // mp4record.c 3 | // 4 | 5 | #import "mp4record.h" 6 | #import 7 | #import "string.h" 8 | 9 | MP4V2_CONTEXT * initMp4Encoder(const char * filename,int width,int height){ 10 | MP4V2_CONTEXT * recordCtx = (MP4V2_CONTEXT*)malloc(sizeof(struct MP4V2_CONTEXT)); 11 | if (!recordCtx) { 12 | printf("error : malloc context \n"); 13 | return NULL; 14 | } 15 | 16 | recordCtx->m_vWidth = width; 17 | recordCtx->m_vHeight = height; 18 | recordCtx->m_vFrateR = 25; 19 | recordCtx->m_vTimeScale = 90000; 20 | recordCtx->m_vFrameDur = 3000; 21 | recordCtx->m_vTrackId = MP4_INVALID_TRACK_ID; 22 | recordCtx->m_aTrackId = MP4_INVALID_TRACK_ID; 23 | 24 | recordCtx->m_mp4FHandle = MP4Create(filename,0); 25 | if (recordCtx->m_mp4FHandle == MP4_INVALID_FILE_HANDLE) { 26 | printf("error : MP4Create \n"); 27 | return NULL; 28 | } 29 | MP4SetTimeScale(recordCtx->m_mp4FHandle, recordCtx->m_vTimeScale); 30 | //------------------------------------------------------------------------------------- audio track 31 | // recordCtx->m_aTrackId = MP4AddAudioTrack(recordCtx->m_mp4FHandle, 8000, 160, MP4_MPEG4_AUDIO_TYPE); 32 | // if (recordCtx->m_aTrackId == MP4_INVALID_TRACK_ID){ 33 | // printf("error : MP4AddAudioTrack \n"); 34 | // return NULL; 35 | // } 36 | // 37 | // MP4SetAudioProfileLevel(recordCtx->m_mp4FHandle, 2);// 2, 1// uint8_t aacConfig[2] = {18,16}; 38 | //// uint8_t aacConfig[2] = {0x14, 0x10}; 39 | // uint8_t aacConfig[2] = {0x15,0x88}; 40 | // MP4SetTrackESConfiguration(recordCtx->m_mp4FHandle,recordCtx->m_aTrackId,aacConfig,2); 41 | printf("ok : initMp4Encoder file=%s \n",filename); 42 | 43 | return recordCtx; 44 | } 45 | 46 | int mp4VEncode(MP4V2_CONTEXT * recordCtx, uint8_t * _naluData ,int _naluSize){ 47 | 48 | int index = -1; 49 | 50 | if(_naluData[0]==0 && _naluData[1]==0 && _naluData[2]==0 && _naluData[3]==1 && (_naluData[4]&0x1F)==0x07){ 51 | index = _NALU_SPS_; 52 | } 53 | if(index!=_NALU_SPS_ && recordCtx->m_vTrackId == MP4_INVALID_TRACK_ID){ 54 | return index; 55 | } 56 | if(_naluData[0]==0 && _naluData[1]==0 && _naluData[2]==0 && _naluData[3]==1 && (_naluData[4]&0x1F)==0x08){ 57 | index = _NALU_PPS_; 58 | } 59 | if(_naluData[0]==0 && _naluData[1]==0 && _naluData[2]==0 && _naluData[3]==1 && (_naluData[4]&0x1F)==0x05){ 60 | index = _NALU_I_; 61 | } 62 | if(_naluData[0]==0 && _naluData[1]==0 && _naluData[2]==0 && _naluData[3]==1 && (_naluData[4]&0x1F)==0x01){ 63 | index = _NALU_P_; 64 | } 65 | // 66 | switch(index){ 67 | case _NALU_SPS_: 68 | if(recordCtx->m_vTrackId == MP4_INVALID_TRACK_ID){ 69 | recordCtx->m_vTrackId = MP4AddH264VideoTrack 70 | (recordCtx->m_mp4FHandle, 71 | recordCtx->m_vTimeScale, 72 | recordCtx->m_vTimeScale / recordCtx->m_vFrateR, 73 | recordCtx->m_vWidth, // width 74 | recordCtx->m_vHeight, // height 75 | _naluData[5], // sps[1] AVCProfileIndication 76 | _naluData[6], // sps[2] profile_compat 77 | _naluData[7], // sps[3] AVCLevelIndication 78 | 3); // 4 bytes length before each NAL unit 79 | if (recordCtx->m_vTrackId == MP4_INVALID_TRACK_ID) { 80 | return -1; 81 | } 82 | MP4SetVideoProfileLevel(recordCtx->m_mp4FHandle, 0x7F); // Simple Profile @ Level 3 83 | } 84 | MP4AddH264SequenceParameterSet(recordCtx->m_mp4FHandle,recordCtx->m_vTrackId,_naluData+4,_naluSize-4); 85 | printf("sps 我排第一\n"); 86 | // 87 | break; 88 | case _NALU_PPS_: 89 | MP4AddH264PictureParameterSet(recordCtx->m_mp4FHandle,recordCtx->m_vTrackId,_naluData+4,_naluSize-4); 90 | printf("pps 我排第二\n"); 91 | break; 92 | case _NALU_I_: 93 | { 94 | // uint8_t * IFrameData = (uint8_t*)malloc(_naluSize+1); 95 | // // 96 | // IFrameData[0] = (_naluSize-3) >>24; 97 | // IFrameData[1] = (_naluSize-3) >>16; 98 | // IFrameData[2] = (_naluSize-3) >>8; 99 | // IFrameData[3] = (_naluSize-3) &0xff; 100 | // 101 | // memcpy(IFrameData+4,_naluData+3,_naluSize-3); 102 | //// if(!MP4WriteSample(recordCtx->m_mp4FHandle, recordCtx->m_vTrackId, IFrameData, _naluSize+1, recordCtx->m_vFrameDur/44100*90000, 0, 1)){ 103 | //// return -1; 104 | //// } 105 | //// recordCtx->m_vFrameDur = 0; 106 | // if(!MP4WriteSample(recordCtx->m_mp4FHandle, recordCtx->m_vTrackId, IFrameData, _naluSize+1, MP4_INVALID_DURATION, 0, 1)){ 107 | // return -1; 108 | // } 109 | // free(IFrameData); 110 | // printf("Iframe 我排第三\n"); 111 | // // 112 | { 113 | _naluData[0] = (_naluSize-4) >>24; 114 | _naluData[1] = (_naluSize-4) >>16; 115 | _naluData[2] = (_naluSize-4) >>8; 116 | _naluData[3] = (_naluSize-4) &0xff; 117 | 118 | // if(!MP4WriteSample(recordCtx->m_mp4FHandle, recordCtx->m_vTrackId, _naluData, _naluSize, recordCtx->m_vFrameDur/8000*90000, 0, 1)){ 119 | // return -1; 120 | // } 121 | // recordCtx->m_vFrameDur = 0; 122 | if(!MP4WriteSample(recordCtx->m_mp4FHandle, recordCtx->m_vTrackId, _naluData, _naluSize, MP4_INVALID_DURATION, 0, 1)){ 123 | return -1; 124 | } 125 | printf("Iframe 我排第三\n"); 126 | } 127 | break; 128 | } 129 | case _NALU_P_: 130 | { 131 | _naluData[0] = (_naluSize-4) >>24; 132 | _naluData[1] = (_naluSize-4) >>16; 133 | _naluData[2] = (_naluSize-4) >>8; 134 | _naluData[3] = (_naluSize-4) &0xff; 135 | 136 | // if(!MP4WriteSample(recordCtx->m_mp4FHandle, recordCtx->m_vTrackId, _naluData, _naluSize, recordCtx->m_vFrameDur/8000*90000, 0, 0)){ 137 | // return -1; 138 | // } 139 | // recordCtx->m_vFrameDur = 0; 140 | if(!MP4WriteSample(recordCtx->m_mp4FHandle, recordCtx->m_vTrackId, _naluData, _naluSize, MP4_INVALID_DURATION, 0, 0)){ 141 | return -1; 142 | } 143 | printf("Pframe 我排第四\n"); 144 | break; 145 | } 146 | } 147 | return 0; 148 | } 149 | 150 | 151 | int mp4AEncode(MP4V2_CONTEXT * recordCtx, uint8_t * data ,int len){ 152 | if(recordCtx->m_vTrackId == MP4_INVALID_TRACK_ID){ 153 | return -1; 154 | } 155 | MP4WriteSample(recordCtx->m_mp4FHandle, recordCtx->m_aTrackId, data, len , MP4_INVALID_DURATION, 0, 1); 156 | recordCtx->m_vFrameDur += 160; 157 | return 0; 158 | } 159 | 160 | void closeMp4Encoder(MP4V2_CONTEXT * recordCtx){ 161 | if(recordCtx){ 162 | if (recordCtx->m_mp4FHandle != MP4_INVALID_FILE_HANDLE) { 163 | MP4Close(recordCtx->m_mp4FHandle,0); 164 | recordCtx->m_mp4FHandle = NULL; 165 | } 166 | 167 | free(recordCtx); 168 | recordCtx = NULL; 169 | } 170 | 171 | printf("ok : closeMp4Encoder \n"); 172 | } 173 | -------------------------------------------------------------------------------- /app/src/main/cpp/mp4record.h: -------------------------------------------------------------------------------- 1 | // 2 | // mp4record.h 3 | // 4 | 5 | #ifndef __RTSP_Player__mp4record__ 6 | #define __RTSP_Player__mp4record__ 7 | 8 | #import "mp4v2/mp4v2.h" 9 | 10 | #define _NALU_SPS_ 0 11 | #define _NALU_PPS_ 1 12 | #define _NALU_I_ 2 13 | #define _NALU_P_ 3 14 | 15 | typedef struct MP4V2_CONTEXT{ 16 | int m_vWidth,m_vHeight,m_vFrateR,m_vTimeScale; 17 | MP4FileHandle m_mp4FHandle; 18 | MP4TrackId m_vTrackId,m_aTrackId; 19 | double m_vFrameDur; 20 | } MP4V2_CONTEXT; 21 | 22 | MP4V2_CONTEXT * initMp4Encoder(const char * filename,int width,int height); 23 | int mp4VEncode(MP4V2_CONTEXT * recordCtx, uint8_t * data, int len); 24 | int mp4AEncode(MP4V2_CONTEXT * recordCtx, uint8_t * data, int len); 25 | void closeMp4Encoder(MP4V2_CONTEXT * recordCtx); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/me/archko/mp4/SLApolloUtils.java: -------------------------------------------------------------------------------- 1 | package com.me.archko.mp4; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.annotation.TargetApi; 5 | import android.app.ActivityManager; 6 | import android.content.ComponentName; 7 | import android.content.Context; 8 | import android.content.res.Configuration; 9 | import android.graphics.Color; 10 | import android.graphics.Rect; 11 | import android.net.ConnectivityManager; 12 | import android.net.NetworkInfo; 13 | import android.os.AsyncTask; 14 | import android.os.Build; 15 | import android.view.Gravity; 16 | import android.view.View; 17 | import android.view.ViewTreeObserver.OnGlobalLayoutListener; 18 | import android.widget.Toast; 19 | 20 | import java.util.List; 21 | 22 | /** 23 | * Mostly general and UI helpers. 24 | * 25 | * @author Andrew Neal (andrewdneal@gmail.com) 26 | */ 27 | public final class SLApolloUtils { 28 | 29 | /** 30 | * The threshold used calculate if a color is light or dark 31 | */ 32 | private static final int BRIGHTNESS_THRESHOLD = 130; 33 | 34 | /* This class is never initiated */ 35 | public SLApolloUtils() { 36 | } 37 | 38 | /** 39 | * Used to determine if the device is running Froyo or greater 40 | * 41 | * @return True if the device is running Froyo or greater, false otherwise 42 | */ 43 | public static final boolean hasFroyo() { 44 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO; 45 | } 46 | 47 | /** 48 | * Used to determine if the device is running Gingerbread or greater 49 | * 50 | * @return True if the device is running Gingerbread or greater, false 51 | * otherwise 52 | */ 53 | public static final boolean hasGingerbread() { 54 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD; 55 | } 56 | 57 | /** 58 | * Used to determine if the device is running Honeycomb or greater 59 | * 60 | * @return True if the device is running Honeycomb or greater, false 61 | * otherwise 62 | */ 63 | public static final boolean hasHoneycomb() { 64 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB; 65 | } 66 | 67 | /** 68 | * Used to determine if the device is running Honeycomb-MR1 or greater 69 | * 70 | * @return True if the device is running Honeycomb-MR1 or greater, false 71 | * otherwise 72 | */ 73 | public static final boolean hasHoneycombMR1() { 74 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1; 75 | } 76 | 77 | /** 78 | * Used to determine if the device is running ICS or greater 79 | * 80 | * @return True if the device is running Ice Cream Sandwich or greater, 81 | * false otherwise 82 | */ 83 | public static final boolean hasICS() { 84 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH; 85 | } 86 | 87 | /** 88 | * Used to determine if the device is running Jelly Bean or greater 89 | * 90 | * @return True if the device is running Jelly Bean or greater, false 91 | * otherwise 92 | */ 93 | public static final boolean hasJellyBean() { 94 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN; 95 | } 96 | 97 | /** 98 | * Used to determine if the device is running 99 | * Jelly Bean MR2 (Android 4.3) or greater 100 | * 101 | * @return True if the device is running Jelly Bean MR2 or greater, 102 | * false otherwise 103 | */ 104 | public static final boolean hasJellyBeanMR2() { 105 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2; 106 | } 107 | 108 | /** 109 | * Used to determine if the device is a tablet or not 110 | * 111 | * @param context The {@link android.content.Context} to use. 112 | * @return True if the device is a tablet, false otherwise. 113 | */ 114 | public static final boolean isTablet(final Context context) { 115 | final int layout = context.getResources().getConfiguration().screenLayout; 116 | return (layout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE; 117 | } 118 | 119 | /** 120 | * Used to determine if the device is currently in landscape mode 121 | * 122 | * @param context The {@link android.content.Context} to use. 123 | * @return True if the device is in landscape mode, false otherwise. 124 | */ 125 | public static final boolean isLandscape(final Context context) { 126 | final int orientation = context.getResources().getConfiguration().orientation; 127 | return orientation == Configuration.ORIENTATION_LANDSCAPE; 128 | } 129 | 130 | /** 131 | * Execute an {@link android.os.AsyncTask} on a thread pool 132 | * 133 | * @param forceSerial True to force the task to run in serial order 134 | * @param task Task to execute 135 | * @param args Optional arguments to pass to 136 | * {@link android.os.AsyncTask#execute(Object[])} 137 | * @param Task argument type 138 | */ 139 | @SuppressLint("NewApi") 140 | public static void execute(final boolean forceSerial, final AsyncTask task, 141 | final T... args) { 142 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.DONUT) { 143 | throw new UnsupportedOperationException( 144 | "This class can only be used on API 4 and newer."); 145 | } 146 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB || forceSerial) { 147 | task.execute(args); 148 | } else { 149 | task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, args); 150 | } 151 | } 152 | 153 | /** 154 | * Used to determine if there is an active data connection and what type of 155 | * connection it is if there is one 156 | * 157 | * @param context The {@link android.content.Context} to use 158 | * @return True if there is an active data connection, false otherwise. 159 | * Also, if the user has checked to only download via Wi-Fi in the 160 | * settings, the mobile data and other network connections aren't 161 | * returned at all 162 | */ 163 | public static final boolean isOnline(final Context context) { 164 | /* 165 | * This sort of handles a sudden configuration change, but I think it 166 | * should be dealt with in a more professional way. 167 | */ 168 | if (context == null) { 169 | return false; 170 | } 171 | 172 | boolean state = false; 173 | final boolean onlyOnWifi = true;//PreferenceUtils.getInstance(context).onlyOnWifi(); 174 | 175 | /* Monitor network connections */ 176 | final ConnectivityManager connectivityManager = (ConnectivityManager)context 177 | .getSystemService(Context.CONNECTIVITY_SERVICE); 178 | 179 | /* Wi-Fi connection */ 180 | final NetworkInfo wifiNetwork = connectivityManager 181 | .getNetworkInfo(ConnectivityManager.TYPE_WIFI); 182 | if (wifiNetwork != null) { 183 | state = wifiNetwork.isConnectedOrConnecting(); 184 | } 185 | 186 | /* Mobile data connection */ 187 | final NetworkInfo mbobileNetwork = connectivityManager 188 | .getNetworkInfo(ConnectivityManager.TYPE_MOBILE); 189 | if (mbobileNetwork != null) { 190 | if (!onlyOnWifi) { 191 | state = mbobileNetwork.isConnectedOrConnecting(); 192 | } 193 | } 194 | 195 | /* Other networks */ 196 | final NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo(); 197 | if (activeNetwork != null) { 198 | if (!onlyOnWifi) { 199 | state = activeNetwork.isConnectedOrConnecting(); 200 | } 201 | } 202 | 203 | return state; 204 | } 205 | 206 | /** 207 | * Display a {@link android.widget.Toast} letting the user know what an item does when long 208 | * pressed. 209 | * 210 | * @param view The {@link android.view.View} to copy the content description from. 211 | */ 212 | public static void showCheatSheet(final View view) { 213 | 214 | final int[] screenPos = new int[2]; // origin is device display 215 | final Rect displayFrame = new Rect(); // includes decorations (e.g. 216 | // status bar) 217 | view.getLocationOnScreen(screenPos); 218 | view.getWindowVisibleDisplayFrame(displayFrame); 219 | 220 | final Context context = view.getContext(); 221 | final int viewWidth = view.getWidth(); 222 | final int viewHeight = view.getHeight(); 223 | final int viewCenterX = screenPos[0] + viewWidth / 2; 224 | final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; 225 | final int estimatedToastHeight = (int)(48 * context.getResources().getDisplayMetrics().density); 226 | 227 | final Toast cheatSheet = Toast.makeText(context, view.getContentDescription(), 228 | Toast.LENGTH_SHORT); 229 | final boolean showBelow = screenPos[1] < estimatedToastHeight; 230 | if (showBelow) { 231 | // Show below 232 | // Offsets are after decorations (e.g. status bar) are factored in 233 | cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, viewCenterX 234 | - screenWidth / 2, screenPos[1] - displayFrame.top + viewHeight); 235 | } else { 236 | // Show above 237 | // Offsets are after decorations (e.g. status bar) are factored in 238 | cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, viewCenterX 239 | - screenWidth / 2, displayFrame.bottom - screenPos[1]); 240 | } 241 | cheatSheet.show(); 242 | } 243 | 244 | /** 245 | * Calculate whether a color is light or dark, based on a commonly known 246 | * brightness formula. 247 | * 248 | * @see {@literal http://en.wikipedia.org/wiki/HSV_color_space%23Lightness} 249 | */ 250 | public static final boolean isColorDark(final int color) { 251 | return (30 * Color.red(color) + 59 * Color.green(color) + 11 * Color.blue(color)) / 100 <= BRIGHTNESS_THRESHOLD; 252 | } 253 | 254 | /** 255 | * Runs a piece of code after the next layout run 256 | * 257 | * @param view The {@link android.view.View} used. 258 | * @param runnable The {@link Runnable} used after the next layout run 259 | */ 260 | @SuppressLint("NewApi") 261 | public static void doAfterLayout(final View view, final Runnable runnable) { 262 | final OnGlobalLayoutListener listener = new OnGlobalLayoutListener() { 263 | @SuppressWarnings("deprecation") 264 | @Override 265 | public void onGlobalLayout() { 266 | /* Layout pass done, unregister for further events */ 267 | if (hasJellyBean()) { 268 | view.getViewTreeObserver().removeOnGlobalLayoutListener(this); 269 | } else { 270 | view.getViewTreeObserver().removeGlobalOnLayoutListener(this); 271 | } 272 | runnable.run(); 273 | } 274 | }; 275 | view.getViewTreeObserver().addOnGlobalLayoutListener(listener); 276 | } 277 | 278 | /** 279 | * Method that removes the support for HardwareAcceleration from a {@link android.view.View}.
280 | *
281 | * Check AOSP notice:
282 | *
283 |      * 'ComposeShader can only contain shaders of different types (a BitmapShader and a
284 |      * LinearGradient for instance, but not two instances of BitmapShader)'. But, 'If your
285 |      * application is affected by any of these missing features or limitations, you can turn
286 |      * off hardware acceleration for just the affected portion of your application by calling
287 |      * setLayerType(View.LAYER_TYPE_SOFTWARE, null).'
288 | * 289 | * @param v The view 290 | */ 291 | @TargetApi(Build.VERSION_CODES.HONEYCOMB) 292 | public static void removeHardwareAccelerationSupport(View v) { 293 | if (v.getLayerType() != View.LAYER_TYPE_SOFTWARE) { 294 | v.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 295 | } 296 | } 297 | 298 | /** 299 | * Used to know if Apollo was sent into the background 300 | * 301 | * @param context The {@link android.content.Context} to use 302 | */ 303 | public static final boolean isApplicationSentToBackground(final Context context) { 304 | final ActivityManager activityManager = (ActivityManager)context 305 | .getSystemService(Context.ACTIVITY_SERVICE); 306 | final List tasks = activityManager.getRunningTasks(1); 307 | System.out.println("tasks:"+tasks); 308 | if (!tasks.isEmpty()) { 309 | //listTask(tasks); 310 | final ComponentName topActivity = tasks.get(0).topActivity; 311 | if (!topActivity.getPackageName().equals(context.getPackageName())) { 312 | return true; 313 | } 314 | } 315 | return false; 316 | } 317 | 318 | private static void listTask(List tasks) { 319 | for (ActivityManager.RunningTaskInfo taskInfo:tasks){ 320 | System.out.println("task:"+taskInfo.topActivity.getPackageName()+" task:"+taskInfo); 321 | } 322 | } 323 | } 324 | -------------------------------------------------------------------------------- /app/src/main/java/com/me/archko/mp4/TestMp4Activity.java: -------------------------------------------------------------------------------- 1 | package com.me.archko.mp4; 2 | 3 | import android.app.Activity; 4 | import android.app.ProgressDialog; 5 | import android.media.MediaCodec; 6 | import android.media.MediaFormat; 7 | import android.os.Bundle; 8 | import android.os.Environment; 9 | import android.util.Log; 10 | import android.view.SurfaceHolder; 11 | import android.view.SurfaceView; 12 | import android.view.View; 13 | import android.widget.Button; 14 | 15 | import com.seuic.jni.Mp4v2Helper; 16 | 17 | import java.io.DataInputStream; 18 | import java.io.File; 19 | import java.io.FileInputStream; 20 | import java.io.FileNotFoundException; 21 | import java.io.IOException; 22 | import java.nio.ByteBuffer; 23 | 24 | /** 25 | * @author: archko 2014/4/29 :15:57 26 | */ 27 | public class TestMp4Activity extends Activity { 28 | 29 | Button test; 30 | 31 | ProgressDialog mProgressDialog; 32 | 33 | private SurfaceView mSurface = null; 34 | private SurfaceHolder mSurfaceHolder; 35 | private Thread mDecodeThread; 36 | private MediaCodec mCodec; 37 | private boolean mStopFlag = false; 38 | private DataInputStream mInputStream; 39 | private String FileName = "mtv.h264"; 40 | private static final int VIDEO_WIDTH = 1920; 41 | private static final int VIDEO_HEIGHT = 1080; 42 | private int FrameRate = 15; 43 | private Boolean UseSPSandPPS = true; 44 | private String filePath = Environment.getExternalStorageDirectory() + "/" + FileName; 45 | String outFilepath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "h264.mp4"; 46 | 47 | //音频 48 | private MediaCodec mAudioDecode; 49 | 50 | @Override 51 | protected void onCreate(Bundle savedInstanceState) { 52 | super.onCreate(savedInstanceState); 53 | setContentView(R.layout.main_layout); 54 | mSurface = (SurfaceView) findViewById(R.id.surfaceview); 55 | test = (Button) findViewById(R.id.test); 56 | test.setOnClickListener(new View.OnClickListener() { 57 | @Override 58 | public void onClick(View v) { 59 | test(); 60 | } 61 | }); 62 | try { 63 | //获取文件输入流 64 | mInputStream = new DataInputStream(new FileInputStream(new File(filePath))); 65 | } catch (FileNotFoundException e) { 66 | e.printStackTrace(); 67 | try { 68 | mInputStream.close(); 69 | } catch (IOException e1) { 70 | e1.printStackTrace(); 71 | } 72 | } 73 | mSurfaceHolder = mSurface.getHolder(); 74 | mSurfaceHolder.addCallback(new SurfaceHolder.Callback() { 75 | @Override 76 | public void surfaceCreated(SurfaceHolder holder) { 77 | initCodec(holder); 78 | } 79 | 80 | @Override 81 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { 82 | 83 | } 84 | 85 | @Override 86 | public void surfaceDestroyed(SurfaceHolder holder) { 87 | mCodec.stop(); 88 | mCodec.release(); 89 | } 90 | }); 91 | } 92 | 93 | 94 | private void test() { 95 | startDecodingThread(); 96 | } 97 | 98 | 99 | private class decodeThread implements Runnable { 100 | @Override 101 | public void run() { 102 | try { 103 | decodeLoop(); 104 | } catch (Exception e) { 105 | Log.d("haha", "run: " + e.toString()); 106 | Mp4v2Helper.closeMp4Encoder(); 107 | Log.d("haha", "decodeLoop: end"); 108 | } 109 | } 110 | 111 | private void decodeLoop() { 112 | //存放目标文件的数据 113 | ByteBuffer[] inputBuffers = mCodec.getInputBuffers(); 114 | //解码后的数据,包含每一个buffer的元数据信息,例如偏差,在相关解码器中有效的数据大小 115 | MediaCodec.BufferInfo info = new MediaCodec.BufferInfo(); 116 | long startMs = System.currentTimeMillis(); 117 | long timeoutUs = 10000; 118 | byte[] marker0 = new byte[]{0, 0, 0, 1}; 119 | byte[] dummyFrame = new byte[]{0x00, 0x00, 0x01, 0x20}; 120 | byte[] streamBuffer = new byte[1024 * 1024 * 5]; 121 | 122 | try { 123 | while (true) { 124 | int length = mInputStream.available(); 125 | if (length > 0) { 126 | int count = mInputStream.read(streamBuffer); 127 | mStopFlag = false; 128 | int bytes_cnt = 0; 129 | while (mStopFlag == false) { 130 | bytes_cnt = streamBuffer.length; 131 | if (bytes_cnt == 0) { 132 | streamBuffer = dummyFrame; 133 | } 134 | 135 | int startIndex = 0; 136 | int remaining = bytes_cnt; 137 | while (true) { 138 | if (remaining == 0 || startIndex >= remaining) { 139 | break; 140 | } 141 | int nextFrameStart = KMPMatch(marker0, streamBuffer, startIndex + 2, remaining); 142 | if (nextFrameStart == -1) { 143 | nextFrameStart = remaining; 144 | } else { 145 | } 146 | 147 | int inIndex = mCodec.dequeueInputBuffer(timeoutUs); 148 | if (inIndex >= 0) { 149 | byte[] newData = new byte[nextFrameStart - startIndex]; 150 | System.arraycopy(streamBuffer, startIndex, newData, 0, newData.length); 151 | int i = Mp4v2Helper.mp4VEncode(newData, newData.length); 152 | Log.d("haha", "decodeLoop: result" + i); 153 | 154 | ByteBuffer byteBuffer = inputBuffers[inIndex]; 155 | byteBuffer.clear(); 156 | byteBuffer.put(streamBuffer, startIndex, nextFrameStart - startIndex); 157 | //在给指定Index的inputbuffer[]填充数据后,调用这个函数把数据传给解码器 158 | mCodec.queueInputBuffer(inIndex, 0, nextFrameStart - startIndex, 0, 0); 159 | startIndex = nextFrameStart; 160 | } else { 161 | continue; 162 | } 163 | 164 | int outIndex = mCodec.dequeueOutputBuffer(info, timeoutUs); 165 | if (outIndex >= 0) { 166 | //帧控制是不在这种情况下工作,因为没有PTS H264是可用的 167 | while (info.presentationTimeUs / 1000 > System.currentTimeMillis() - startMs) { 168 | try { 169 | Thread.sleep(100); 170 | } catch (InterruptedException e) { 171 | e.printStackTrace(); 172 | } 173 | } 174 | boolean doRender = (info.size != 0); 175 | //对outputbuffer的处理完后,调用这个函数把buffer重新返回给codec类。 176 | mCodec.releaseOutputBuffer(outIndex, doRender); 177 | } else { 178 | } 179 | } 180 | mStopFlag = true; 181 | Mp4v2Helper.closeMp4Encoder(); 182 | Log.d("haha", "decodeLoop: end"); 183 | } 184 | } 185 | 186 | } 187 | // streamBuffer = getBytes(mInputStream); 188 | } catch (IOException e) { 189 | e.printStackTrace(); 190 | } 191 | 192 | } 193 | } 194 | 195 | int KMPMatch(byte[] pattern, byte[] bytes, int start, int remain) { 196 | try { 197 | Thread.sleep(30); 198 | } catch (InterruptedException e) { 199 | e.printStackTrace(); 200 | } 201 | int[] lsp = computeLspTable(pattern); 202 | 203 | int j = 0; // Number of chars matched in pattern 204 | for (int i = start; i < remain; i++) { 205 | while (j > 0 && bytes[i] != pattern[j]) { 206 | // Fall back in the pattern 207 | j = lsp[j - 1]; // Strictly decreasing 208 | } 209 | if (bytes[i] == pattern[j]) { 210 | // Next char matched, increment position 211 | j++; 212 | if (j == pattern.length) 213 | return i - (j - 1); 214 | } 215 | } 216 | 217 | return -1; // Not found 218 | } 219 | 220 | int[] computeLspTable(byte[] pattern) { 221 | int[] lsp = new int[pattern.length]; 222 | lsp[0] = 0; // Base case 223 | for (int i = 1; i < pattern.length; i++) { 224 | // Start by assuming we're extending the previous LSP 225 | int j = lsp[i - 1]; 226 | while (j > 0 && pattern[i] != pattern[j]) 227 | j = lsp[j - 1]; 228 | if (pattern[i] == pattern[j]) 229 | j++; 230 | lsp[i] = j; 231 | } 232 | return lsp; 233 | } 234 | 235 | private void initCodec(SurfaceHolder holder) { 236 | try { 237 | //通过多媒体格式名创建一个可用的解码器 238 | mCodec = MediaCodec.createDecoderByType("video/avc"); 239 | } catch (IOException e) { 240 | e.printStackTrace(); 241 | } 242 | //初始化编码器 243 | final MediaFormat mediaformat = MediaFormat.createVideoFormat("video/avc", VIDEO_WIDTH, VIDEO_HEIGHT); 244 | //获取h264中的pps及sps数据 245 | if (UseSPSandPPS) { 246 | byte[] header_sps = {0, 0, 0, 1, 103, 66, 0, 42, (byte) 149, (byte) 168, 30, 0, (byte) 137, (byte) 249, 102, (byte) 224, 32, 32, 32, 64}; 247 | byte[] header_pps = {0, 0, 0, 1, 104, (byte) 206, 60, (byte) 128, 0, 0, 0, 1, 6, (byte) 229, 1, (byte) 151, (byte) 128}; 248 | mediaformat.setByteBuffer("csd-0", ByteBuffer.wrap(header_sps)); 249 | mediaformat.setByteBuffer("csd-1", ByteBuffer.wrap(header_pps)); 250 | } 251 | //设置帧率 252 | mediaformat.setInteger(MediaFormat.KEY_FRAME_RATE, FrameRate); 253 | //https://developer.android.com/reference/android/media/MediaFormat.html#KEY_MAX_INPUT_SIZE 254 | //设置配置参数,参数介绍 : 255 | // format 如果为解码器,此处表示输入数据的格式;如果为编码器,此处表示输出数据的格式。 256 | //surface 指定一个surface,可用作decode的输出渲染。 257 | //crypto 如果需要给媒体数据加密,此处指定一个crypto类. 258 | // flags 如果正在配置的对象是用作编码器,此处加上CONFIGURE_FLAG_ENCODE 标签。 259 | mCodec.configure(mediaformat, holder.getSurface(), null, 0); 260 | // startDecodingThread(); 261 | 262 | int i = Mp4v2Helper.initMp4Encoder(outFilepath, 1080, 720); 263 | Log.d("hahah", i + "init"); 264 | } 265 | 266 | 267 | private void startDecodingThread() { 268 | mCodec.start(); 269 | mDecodeThread = new Thread(new decodeThread()); 270 | mDecodeThread.start(); 271 | } 272 | 273 | } 274 | -------------------------------------------------------------------------------- /app/src/main/java/com/seuic/jni/Mp4v2Helper.java: -------------------------------------------------------------------------------- 1 | package com.seuic.jni; 2 | 3 | import android.util.Log; 4 | 5 | /** 6 | * 描述: 7 | * 作者:chezi008 on 2017/4/12 16:14 8 | * 邮箱:chezi008@163.com 9 | */ 10 | 11 | public class Mp4v2Helper { 12 | 13 | public static native int initMp4Encoder(String outputFilePath,int width,int height); 14 | 15 | public static native int mp4VEncode(byte[] data, int size); 16 | 17 | public static native int mp4AEncode(byte[] data, int size); 18 | 19 | public static native void closeMp4Encoder(); 20 | 21 | static { 22 | Log.i("NativeClass", "before load library"); 23 | System.loadLibrary("Mp4v2Helper");//注意这里为自己指定的.so文件,无lib前缀,亦无后缀 24 | Log.i("NativeClass", "after load library"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chezi008/Mp4v2Demo/ca2db3839b2e07524a1016a88e50d6e9c1c89438/app/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chezi008/Mp4v2Demo/ca2db3839b2e07524a1016a88e50d6e9c1c89438/app/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chezi008/Mp4v2Demo/ca2db3839b2e07524a1016a88e50d6e9c1c89438/app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chezi008/Mp4v2Demo/ca2db3839b2e07524a1016a88e50d6e9c1c89438/app/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/layout/main_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 14 |