📄 mp4file.cpp
字号:
MP4TrackId MP4File::AddSceneTrack(){ MP4TrackId trackId = AddSystemsTrack(MP4_SCENE_TRACK_TYPE); AddTrackToIod(trackId); AddTrackToOd(trackId); return trackId;}// NULL terminated list of brands which require the IODS atomchar *brandsWithIods[] = { "mp42", "isom", NULL};bool MP4File::ShallHaveIods(){ u_int32_t compatibleBrandsCount; MP4StringProperty *pMajorBrandProperty; MP4Atom* ftypAtom = m_pRootAtom->FindAtom("ftyp"); if (ftypAtom == NULL) return false; // Check the major brand ftypAtom->FindProperty( "ftyp.majorBrand", (MP4Property**)&pMajorBrandProperty); ASSERT(pMajorBrandProperty); for(u_int32_t j = 0 ; brandsWithIods[j] != NULL ; j++) { if (!strcasecmp( ((MP4StringProperty*)pMajorBrandProperty)->GetValue(), brandsWithIods[j])) return true; } // Check the compatible brands MP4Integer32Property* pCompatibleBrandsCountProperty; ftypAtom->FindProperty( "ftyp.compatibleBrandsCount", (MP4Property**)&pCompatibleBrandsCountProperty); ASSERT(pCompatibleBrandsCountProperty); compatibleBrandsCount = pCompatibleBrandsCountProperty->GetValue(); MP4TableProperty* pCompatibleBrandsProperty; ftypAtom->FindProperty( "ftyp.compatibleBrands", (MP4Property**)&pCompatibleBrandsProperty); MP4StringProperty* pBrandProperty = (MP4StringProperty*)pCompatibleBrandsProperty->GetProperty(0); ASSERT(pBrandProperty); for(u_int32_t i = 0 ; i < compatibleBrandsCount ; i++) { for(u_int32_t j = 0 ; brandsWithIods[j] != NULL ; j++) { if (!strcasecmp(pBrandProperty->GetValue(i), brandsWithIods[j])) return true; } } return false;}void MP4File::SetAmrVendor( MP4TrackId trackId, u_int32_t vendor){ SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.*.damr.vendor", vendor);}void MP4File::SetAmrDecoderVersion( MP4TrackId trackId, u_int8_t decoderVersion){ SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.*.damr.decoderVersion", decoderVersion);}void MP4File::SetAmrModeSet( MP4TrackId trackId, u_int16_t modeSet){ SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.*.damr.modeSet", modeSet);}uint16_t MP4File::GetAmrModeSet(MP4TrackId trackId){ return GetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.*.damr.modeSet");}MP4TrackId MP4File::AddAmrAudioTrack( u_int32_t timeScale, u_int16_t modeSet, u_int8_t modeChangePeriod, u_int8_t framesPerSample, bool isAmrWB){ u_int32_t fixedSampleDuration = (timeScale * 20)/1000; // 20mSec/Sample MP4TrackId trackId = AddTrack(MP4_AUDIO_TRACK_TYPE, timeScale); AddTrackToOd(trackId); SetTrackFloatProperty(trackId, "tkhd.volume", 1.0); InsertChildAtom(MakeTrackName(trackId, "mdia.minf"), "smhd", 0); AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd"), isAmrWB ? "sawb" : "samr"); // stsd is a unique beast in that it has a count of the number // of child atoms that needs to be incremented after we add the mp4a atom MP4Integer32Property* pStsdCountProperty; FindIntegerProperty( MakeTrackName(trackId, "mdia.minf.stbl.stsd.entryCount"), (MP4Property**)&pStsdCountProperty); pStsdCountProperty->IncrementValue(); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.*.timeScale", timeScale); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.*.damr.modeSet", modeSet); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.*.damr.modeChangePeriod", modeChangePeriod); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.*.damr.framesPerSample", framesPerSample); m_pTracks[FindTrackIndex(trackId)]-> SetFixedSampleDuration(fixedSampleDuration); return trackId;}MP4TrackId MP4File::AddAudioTrack( u_int32_t timeScale, MP4Duration sampleDuration, u_int8_t audioType){ MP4TrackId trackId = AddTrack(MP4_AUDIO_TRACK_TYPE, timeScale); AddTrackToOd(trackId); SetTrackFloatProperty(trackId, "tkhd.volume", 1.0); InsertChildAtom(MakeTrackName(trackId, "mdia.minf"), "smhd", 0); AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd"), "mp4a"); // stsd is a unique beast in that it has a count of the number // of child atoms that needs to be incremented after we add the mp4a atom MP4Integer32Property* pStsdCountProperty; FindIntegerProperty( MakeTrackName(trackId, "mdia.minf.stbl.stsd.entryCount"), (MP4Property**)&pStsdCountProperty); pStsdCountProperty->IncrementValue(); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.mp4a.timeScale", timeScale); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.mp4a.esds.ESID", #if 0 // note - for a file, these values need to // be 0 - wmay - 04/16/2003 trackId#else 0#endif ); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.mp4a.esds.decConfigDescr.objectTypeId", audioType); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.mp4a.esds.decConfigDescr.streamType", MP4AudioStreamType); m_pTracks[FindTrackIndex(trackId)]-> SetFixedSampleDuration(sampleDuration); return trackId;}MP4TrackId MP4File::AddEncAudioTrack(u_int32_t timeScale, MP4Duration sampleDuration, u_int8_t audioType, u_int32_t scheme_type, u_int16_t scheme_version, u_int8_t key_ind_len, u_int8_t iv_len, bool selective_enc, char *kms_uri, bool use_ismacryp ){ u_int32_t original_fmt = 0; MP4TrackId trackId = AddTrack(MP4_AUDIO_TRACK_TYPE, timeScale); AddTrackToOd(trackId); SetTrackFloatProperty(trackId, "tkhd.volume", 1.0); InsertChildAtom(MakeTrackName(trackId, "mdia.minf"), "smhd", 0); AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd"), "enca"); // stsd is a unique beast in that it has a count of the number // of child atoms that needs to be incremented after we add the enca atom MP4Integer32Property* pStsdCountProperty; FindIntegerProperty(MakeTrackName(trackId, "mdia.minf.stbl.stsd.entryCount"), (MP4Property**)&pStsdCountProperty); pStsdCountProperty->IncrementValue(); /* set all the ismacryp-specific values */ // original format is mp4a if (use_ismacryp) { original_fmt = ('m'<<24 | 'p'<<16 | '4'<<8 | 'a'); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.enca.sinf.frma.data-format", original_fmt); AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.enca.sinf"), "schm"); AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.enca.sinf"), "schi"); AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.enca.sinf.schi"), "iKMS"); AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.enca.sinf.schi"), "iSFM"); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.enca.sinf.schm.scheme_type", scheme_type); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.enca.sinf.schm.scheme_version", scheme_version); SetTrackStringProperty(trackId, "mdia.minf.stbl.stsd.enca.sinf.schi.iKMS.kms_URI", kms_uri); if (kms_uri != NULL) { free(kms_uri); } SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.enca.sinf.schi.iSFM.selective-encryption", selective_enc); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.enca.sinf.schi.iSFM.key-indicator-length", key_ind_len); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.enca.sinf.schi.iSFM.IV-length", iv_len); /* end ismacryp */ } SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.enca.timeScale", timeScale); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.enca.esds.ESID", #if 0 // note - for a file, these values need to // be 0 - wmay - 04/16/2003 trackId#else 0#endif ); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.enca.esds.decConfigDescr.objectTypeId", audioType); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.enca.esds.decConfigDescr.streamType", MP4AudioStreamType); m_pTracks[FindTrackIndex(trackId)]-> SetFixedSampleDuration(sampleDuration); return trackId;}MP4TrackId MP4File::AddCntlTrackDefault (uint32_t timeScale, MP4Duration sampleDuration, const char *type){ MP4TrackId trackId = AddTrack(MP4_CNTL_TRACK_TYPE, timeScale); InsertChildAtom(MakeTrackName(trackId, "mdia.minf"), "nmhd", 0); AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd"), type); // stsd is a unique beast in that it has a count of the number // of child atoms that needs to be incremented after we add the mp4v atom MP4Integer32Property* pStsdCountProperty; FindIntegerProperty( MakeTrackName(trackId, "mdia.minf.stbl.stsd.entryCount"), (MP4Property**)&pStsdCountProperty); pStsdCountProperty->IncrementValue(); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsz.sampleSize", sampleDuration); m_pTracks[FindTrackIndex(trackId)]-> SetFixedSampleDuration(sampleDuration); return trackId;}MP4TrackId MP4File::AddHrefTrack (uint32_t timeScale, MP4Duration sampleDuration){ MP4TrackId trackId = AddCntlTrackDefault(timeScale, sampleDuration, "href"); return trackId;} MP4TrackId MP4File::AddVideoTrackDefault( u_int32_t timeScale, MP4Duration sampleDuration, u_int16_t width, u_int16_t height, const char *videoType){ MP4TrackId trackId = AddTrack(MP4_VIDEO_TRACK_TYPE, timeScale); AddTrackToOd(trackId); SetTrackFloatProperty(trackId, "tkhd.width", width); SetTrackFloatProperty(trackId, "tkhd.height", height); InsertChildAtom(MakeTrackName(trackId, "mdia.minf"), "vmhd", 0); AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd"), videoType); // stsd is a unique beast in that it has a count of the number // of child atoms that needs to be incremented after we add the mp4v atom MP4Integer32Property* pStsdCountProperty; FindIntegerProperty( MakeTrackName(trackId, "mdia.minf.stbl.stsd.entryCount"), (MP4Property**)&pStsdCountProperty); pStsdCountProperty->IncrementValue(); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsz.sampleSize", sampleDuration); m_pTracks[FindTrackIndex(trackId)]-> SetFixedSampleDuration(sampleDuration); return trackId;}MP4TrackId MP4File::AddMP4VideoTrack( u_int32_t timeScale, MP4Duration sampleDuration, u_int16_t width, u_int16_t height, u_int8_t videoType){ MP4TrackId trackId = AddVideoTrackDefault(timeScale, sampleDuration, width, height, "mp4v"); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.mp4v.width", width); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.mp4v.height", height); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.mp4v.esds.ESID", #if 0 // note - for a file, these values need to // be 0 - wmay - 04/16/2003 trackId#else 0#endif ); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.mp4v.esds.decConfigDescr.objectTypeId", videoType); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.mp4v.esds.decConfigDescr.streamType", MP4VisualStreamType); return trackId;}MP4TrackId MP4File::AddEncVideoTrack(u_int32_t timeScale, MP4Duration sampleDuration, u_int16_t width, u_int16_t height, u_int8_t videoType, u_int32_t scheme_type, u_int16_t scheme_version, u_int8_t key_ind_len, u_int8_t iv_len, bool selective_enc, char *kms_uri, bool use_ismacryp ){ u_int32_t original_fmt = 0; MP4TrackId trackId = AddVideoTrackDefault(timeScale, sampleDuration, width, height, "encv"); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.encv.width", width); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.encv.height", height); /* set all the ismacryp-specific values */ // original format is mp4v if (use_ismacryp) { original_fmt = ATOMID("mp4v"); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.encv.sinf.frma.data-format", original_fmt); AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.encv.sinf"), "schm"); AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.encv.sinf"), "schi"); AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.encv.sinf.schi"), "iKMS"); AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.encv.sinf.schi"), "iSFM"); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.encv.sinf.schm.scheme_type", scheme_type);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -