📄 mp4file.cpp
字号:
scheme_version); SetTrackStringProperty(trackId, "mdia.minf.stbl.stsd.enca.sinf.schi.iKMS.kms_URI", kms_uri); #if 0 if (kms_uri != NULL) { free((void *)kms_uri); } #endif 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); (void)InsertChildAtom(MakeTrackName(trackId, "mdia.minf"), "nmhd", 0); (void)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, const char *base_url){ MP4TrackId trackId = AddCntlTrackDefault(timeScale, sampleDuration, "href"); if (base_url != NULL) { (void)AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.href"), "burl"); SetTrackStringProperty(trackId, "mdia.minf.stbl.stsd.href.burl.base_url", base_url); } 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); (void)InsertChildAtom(MakeTrackName(trackId, "mdia.minf"), "vmhd", 0); (void)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;}// ismacryptedMP4TrackId MP4File::AddEncVideoTrack(u_int32_t timeScale, MP4Duration sampleDuration, u_int16_t width, u_int16_t height, u_int8_t videoType, mp4v2_ismacrypParams *icPp, const char *oFormat ){ 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_fmt = ATOMID(oFormat); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.encv.sinf.frma.data-format", original_fmt); (void)AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.encv.sinf"), "schm"); (void)AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.encv.sinf"), "schi"); (void)AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.encv.sinf.schi"), "iKMS"); (void)AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.encv.sinf.schi"), "iSFM"); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.encv.sinf.schm.scheme_type", icPp->scheme_type); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.encv.sinf.schm.scheme_version", icPp->scheme_version); SetTrackStringProperty(trackId, "mdia.minf.stbl.stsd.encv.sinf.schi.iKMS.kms_URI", icPp->kms_uri); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.encv.sinf.schi.iSFM.selective-encryption", icPp->selective_enc); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.encv.sinf.schi.iSFM.key-indicator-length", icPp->key_ind_len); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.encv.sinf.schi.iSFM.IV-length", icPp->iv_len); #if 0 if (icPp->kms_uri != NULL) { free(icPp->kms_uri); } #endif SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.encv.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.encv.esds.decConfigDescr.objectTypeId", videoType); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.encv.esds.decConfigDescr.streamType", MP4VisualStreamType); return trackId;}MP4TrackId MP4File::AddH264VideoTrack( u_int32_t timeScale, MP4Duration sampleDuration, u_int16_t width, u_int16_t height, uint8_t AVCProfileIndication, uint8_t profile_compat, uint8_t AVCLevelIndication, uint8_t sampleLenFieldSizeMinusOne){ MP4TrackId trackId = AddVideoTrackDefault(timeScale, sampleDuration, width, height, "avc1"); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.avc1.width", width); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.avc1.height", height); //FIXME - check this // shouldn't need this #if 0 AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.avc1"), "avcC"); #endif SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.avc1.avcC.AVCProfileIndication", AVCProfileIndication); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.avc1.avcC.profile_compatibility", profile_compat); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.avc1.avcC.AVCLevelIndication", AVCLevelIndication); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.avc1.avcC.lengthSizeMinusOne", sampleLenFieldSizeMinusOne); return trackId;}MP4TrackId MP4File::AddEncH264VideoTrack( u_int32_t timeScale, MP4Duration sampleDuration, u_int16_t width, u_int16_t height, MP4Atom *srcAtom, mp4v2_ismacrypParams *icPp){ u_int32_t original_fmt = 0; MP4Atom *avcCAtom; 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); (void)AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.encv"), "avcC"); // create default values avcCAtom = FindAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.encv.avcC")); // export source atom ((MP4AvcCAtom *) srcAtom)->Clone((MP4AvcCAtom *)avcCAtom); /* set all the ismacryp-specific values */ (void)AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.encv.sinf"), "schm"); (void)AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.encv.sinf"), "schi"); (void)AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.encv.sinf.schi"), "iKMS"); (void)AddChildAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.encv.sinf.schi"), "iSFM"); // per ismacrypt E&A V1.1 section 9.1.2.1 'avc1' is renamed '264b' // avc1 must not appear as a sample entry name or original format name original_fmt = ATOMID("264b"); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.encv.sinf.frma.data-format", original_fmt); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.encv.sinf.schm.scheme_type", icPp->scheme_type); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.encv.sinf.schm.scheme_version", icPp->scheme_version); SetTrackStringProperty(trackId, "mdia.minf.stbl.stsd.encv.sinf.schi.iKMS.kms_URI", icPp->kms_uri); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.encv.sinf.schi.iSFM.selective-encryption", icPp->selective_enc); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.encv.sinf.schi.iSFM.key-indicator-length", icPp->key_ind_len); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.encv.sinf.schi.iSFM.IV-length", icPp->iv_len); return trackId;}void MP4File::AddH264SequenceParameterSet (MP4TrackId trackId, const uint8_t *pSequence, uint16_t sequenceLen){ const char *format; MP4Atom *avcCAtom; // get 4cc media format - can be avc1 or encv for ismacrypted track format = GetTrackMediaDataName(trackId); if (!strcasecmp(format, "avc1")) avcCAtom = FindAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.avc1.avcC")); else if (!strcasecmp(format, "encv")) avcCAtom = FindAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.encv.avcC")); else // huh? unknown track format return; MP4BitfieldProperty *pCount; MP4Integer16Property *pLength; MP4BytesProperty *pUnit; if ((avcCAtom->FindProperty("avcC.numOfSequenceParameterSets", (MP4Property **)&pCount) == false) || (avcCAtom->FindProperty("avcC.sequenceEntries.sequenceParameterSetLength", (MP4Property **)&pLength) == false) || (avcCAtom->FindProperty("avcC.sequenceEntries.sequenceParameterSetNALUnit", (MP4Property **)&pUnit) == false)) { VERBOSE_ERROR(m_verbosity, WARNING("Could not find avcC properties")); return; } uint32_t count = pCount->GetValue(); if (count > 0) { // see if we already exist for (uint32_t index = 0; index < count; index++) { if (pLength->GetValue(index) == sequenceLen) { uint8_t *seq; uint32_t seqlen; pUnit->GetValue(&seq, &seqlen, index); if (memcmp(seq, pSequence, sequenceLen) == 0) { free(seq); return; } free(seq); } } } pLength->AddValue(sequenceLen); pUnit->AddValue(pSequence, sequenceLen); pCount->IncrementValue(); return;}void MP4File::AddH264PictureParameterSet (MP4TrackId trackId, const uint8_t *pPict, uint16_t pictLen){ MP4Atom *avcCAtom = FindAtom(MakeTrackName(trackId, "mdia.minf.stbl.stsd.avc1.avcC")); MP4Integer8Property *pCount; MP4Integer16Property *pLength; MP4BytesProperty *pUnit; if ((avcCAtom->FindProperty("avcC.numOfPictureParameterSets", (MP4Property **)&pCount) == false) || (avcCAtom->FindProperty("avcC.pictureEntries.pictureParameterSetLength", (MP4Property **)&pLength) == false) || (avcCAtom->FindProperty("avcC.pictureEntries.pictureParameterSetNALUnit", (MP4Property **)&pUnit) == false)) { VERBOSE_ERROR(m_verbosity, WARNING("Could not find avcC picture table properties")); return; } uint32_t count = pCount->GetValue(); if (count > 0) { // see if we already exist for (uint32_t index = 0; index < count; index++) { if (pLength->GetValue(index) == pictLen) { uint8_t *seq; uint32_t seqlen; pUnit->GetValue(&seq, &seqlen, index); if (memcmp(seq, pPict, pictLen) == 0) { VERBOSE_WRITE(m_verbosity, fprintf(stderr, "picture matches %d\n", index)); free(seq); return; } free(seq); } } } pLength->AddValue(pictLen); pUnit->AddValue(pPict, pictLen); pCount->IncrementValue(); VERBOSE_WRITE(m_verbosity, fprintf(stderr, "new picture added %d\n", pCount->GetValue())); return;}void MP4File::SetH263Vendor( MP4TrackId trackId, u_int32_t vendor){ SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.s263.d263.vendor", vendor);}void MP4File::SetH263DecoderVersion( MP4TrackId trackId, u_int8_t decoderVersion){ SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.s263.d263.decoderVersion", decoderVersion);}void MP4File::SetH263Bitrates( MP4TrackId trackId, u_int32_t avgBitrate, u_int32_t maxBitrate){ SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.s263.d263.bitr.avgBitrate", avgBitrate); SetTrackIntegerProperty(trackId, "mdia.minf.stbl.stsd.s263.d263.bitr.maxBitrate", maxBitrate);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -