⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mp4.cpp

📁 完整的RTP RTSP代码库
💻 CPP
📖 第 1 页 / 共 5 页
字号:
			return ((MP4File*)hFile)->AddODTrack();		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return MP4_INVALID_TRACK_ID;}extern "C" MP4TrackId MP4AddSceneTrack(MP4FileHandle hFile){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			return ((MP4File*)hFile)->AddSceneTrack();		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return MP4_INVALID_TRACK_ID;}extern "C" MP4TrackId MP4AddAudioTrack(	MP4FileHandle hFile, 	u_int32_t timeScale, 	MP4Duration sampleDuration, 	u_int8_t audioType){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			return ((MP4File*)hFile)->				AddAudioTrack(timeScale, sampleDuration, audioType);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return MP4_INVALID_TRACK_ID;}//// API to initialize ismacryp properties to sensible defaults.// if the input pointer is null then an ismacryp params is malloc'd.// caller must see to it that it is properly disposed of.//extern "C" mp4v2_ismacrypParams *MP4DefaultISMACrypParams(mp4v2_ismacrypParams *ptr){    try    {        if (ptr == NULL) {            ptr = (mp4v2_ismacrypParams *)MP4Malloc(sizeof(mp4v2_ismacrypParams));        }        memset(ptr, 0, sizeof(*ptr));        return ptr;    }    catch (...) {      return MP4_INVALID_TRACK_ID;    }}extern "C" MP4TrackId MP4AddEncAudioTrack(MP4FileHandle hFile, 					  u_int32_t timeScale, 					  MP4Duration sampleDuration,                                          mp4v2_ismacrypParams *icPp,					  u_int8_t audioType){  if (MP4_IS_VALID_FILE_HANDLE(hFile)) {    try {      if (icPp == NULL) {	return ((MP4File*)hFile)->	  AddEncAudioTrack(timeScale, sampleDuration, audioType,			   0, 0, 			   0, 0, 			   false, NULL, false);      } else {	return ((MP4File*)hFile)->	  AddEncAudioTrack(timeScale, sampleDuration, audioType,			   icPp->scheme_type, icPp->scheme_version, 			   icPp->key_ind_len, icPp->iv_len, 			   icPp->selective_enc, icPp->kms_uri, true);      }    } catch (MP4Error* e) {      PRINT_ERROR(e);      delete e;    }  }  return MP4_INVALID_TRACK_ID;}extern "C" MP4TrackId MP4AddAmrAudioTrack(		MP4FileHandle hFile,		u_int32_t timeScale,		u_int16_t modeSet,		u_int8_t modeChangePeriod,		u_int8_t framesPerSample,		bool isAmrWB){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			return ((MP4File*)hFile)->				AddAmrAudioTrack(timeScale, modeSet, modeChangePeriod, framesPerSample, isAmrWB);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return MP4_INVALID_TRACK_ID;}extern "C" void MP4SetAmrVendor(		MP4FileHandle hFile,		MP4TrackId trackId,		u_int32_t vendor){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			((MP4File*)hFile)->				SetAmrVendor(trackId, vendor);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}}extern "C" void MP4SetAmrDecoderVersion(		MP4FileHandle hFile,		MP4TrackId trackId,		u_int8_t decoderVersion){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			((MP4File*)hFile)->				SetAmrDecoderVersion(trackId, decoderVersion);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}}extern "C" void MP4SetAmrModeSet(		MP4FileHandle hFile,		MP4TrackId trackId,		u_int16_t modeSet){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			((MP4File*)hFile)->				SetAmrModeSet(trackId, modeSet);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}}extern "C" uint16_t MP4GetAmrModeSet(				     MP4FileHandle hFile,				     MP4TrackId trackId){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {		  return ((MP4File*)hFile)->				GetAmrModeSet(trackId);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return 0;}extern "C" MP4TrackId MP4AddHrefTrack (MP4FileHandle hFile,				       uint32_t timeScale,				       MP4Duration sampleDuration,				       const char *base_url){  if (MP4_IS_VALID_FILE_HANDLE(hFile)) {    try {      MP4File *pFile = (MP4File *)hFile;      return pFile->AddHrefTrack(timeScale, 				 sampleDuration,				 base_url);    }    catch (MP4Error* e) {      PRINT_ERROR(e);      delete e;    }  }  return MP4_INVALID_TRACK_ID;}extern "C" const char *MP4GetHrefTrackBaseUrl (MP4FileHandle hFile,					       MP4TrackId trackId){  if (MP4_IS_VALID_FILE_HANDLE(hFile)) {    try {      return ((MP4File*)hFile)->GetTrackStringProperty(trackId,						       "mdia.minf.stbl.stsd.href.burl.base_url");    }    catch (MP4Error* e) {      PRINT_ERROR(e);      delete e;    }  }  return NULL;}extern "C" MP4TrackId MP4AddVideoTrack(	MP4FileHandle hFile, 	u_int32_t timeScale, 	MP4Duration sampleDuration,	u_int16_t width, 	u_int16_t height, 	u_int8_t videoType){  if (MP4_IS_VALID_FILE_HANDLE(hFile)) {    try {      MP4File *pFile = (MP4File *)hFile;      return pFile->AddMP4VideoTrack(timeScale, 				     sampleDuration, 				     width, 				     height, 				     videoType);    }    catch (MP4Error* e) {      PRINT_ERROR(e);      delete e;    }  }  return MP4_INVALID_TRACK_ID;}extern "C" MP4TrackId MP4AddEncVideoTrack(MP4FileHandle hFile, 					  u_int32_t timeScale, 					  MP4Duration sampleDuration,					  u_int16_t width, 					  u_int16_t height,                                           mp4v2_ismacrypParams *icPp,					  u_int8_t videoType,					  const char *oFormat){  if (MP4_IS_VALID_FILE_HANDLE(hFile)) {    try { 	  // test for valid ismacrypt session descriptor      if (icPp == NULL) {		return MP4_INVALID_TRACK_ID;      }      MP4File *pFile = (MP4File *)hFile;	return pFile->AddEncVideoTrack(timeScale, 			sampleDuration, 			width, 			height, 			videoType, 			icPp, 			oFormat);    } catch (MP4Error* e) {      PRINT_ERROR(e);      delete e;    }  }  return MP4_INVALID_TRACK_ID;}extern "C" MP4TrackId MP4AddH264VideoTrack(MP4FileHandle hFile, 					   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){  if (MP4_IS_VALID_FILE_HANDLE(hFile)) {    try {      MP4File *pFile = (MP4File *)hFile;      return pFile->AddH264VideoTrack(timeScale, 				      sampleDuration, 				      width, 				      height, 				      AVCProfileIndication,				      profile_compat,				      AVCLevelIndication,				      sampleLenFieldSizeMinusOne);    }    catch (MP4Error* e) {      PRINT_ERROR(e);      delete e;    }  }  return MP4_INVALID_TRACK_ID;}extern "C" MP4TrackId MP4AddEncH264VideoTrack(	MP4FileHandle hFile, 	u_int32_t timeScale, 	MP4Duration sampleDuration,	u_int16_t width, 	u_int16_t height, 	MP4FileHandle srcFile, 	MP4TrackId srcTrackId,     mp4v2_ismacrypParams *icPp){  MP4Atom *srcAtom;  MP4File *pFile;  if (MP4_IS_VALID_FILE_HANDLE(hFile)) {    try {	pFile = (MP4File *)srcFile;	srcAtom = pFile->FindTrackAtom(srcTrackId, "mdia.minf.stbl.stsd.avc1.avcC");	if (srcAtom == NULL)		return MP4_INVALID_TRACK_ID;	pFile = (MP4File *)hFile;	return pFile->AddEncH264VideoTrack(timeScale, 			 sampleDuration, 			 width, 			 height, 			 srcAtom,			 icPp);    }    catch (MP4Error* e) {      PRINT_ERROR(e);      delete e;    }  }  return MP4_INVALID_TRACK_ID;}extern "C" void MP4AddH264SequenceParameterSet (MP4FileHandle hFile,						MP4TrackId trackId,						const uint8_t *pSequence,						uint16_t sequenceLen){  if (MP4_IS_VALID_FILE_HANDLE(hFile)) {    try {      MP4File *pFile = (MP4File *)hFile;      pFile->AddH264SequenceParameterSet(trackId,					 pSequence,					 sequenceLen);      return;    }    catch (MP4Error* e) {      PRINT_ERROR(e);      delete e;    }  }    return;}extern "C" void MP4AddH264PictureParameterSet (MP4FileHandle hFile,					       MP4TrackId trackId,					       const uint8_t *pPict,					       uint16_t pictLen){  if (MP4_IS_VALID_FILE_HANDLE(hFile)) {    try {      MP4File *pFile = (MP4File *)hFile;      pFile->AddH264PictureParameterSet(trackId,					pPict,					pictLen);      return;    }    catch (MP4Error* e) {      PRINT_ERROR(e);      delete e;    }  }    return;}extern "C" MP4TrackId MP4AddH263VideoTrack(		MP4FileHandle hFile,		u_int32_t timeScale,		MP4Duration sampleDuration,		u_int16_t width,		u_int16_t height,		u_int8_t h263Level,		u_int8_t h263Profile,		u_int32_t avgBitrate,		u_int32_t maxBitrate){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			return ((MP4File*)hFile)->				AddH263VideoTrack(timeScale, sampleDuration, width, height, h263Level, h263Profile, avgBitrate, maxBitrate);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}		return MP4_INVALID_TRACK_ID;}extern "C" void MP4SetH263Vendor(		MP4FileHandle hFile,		MP4TrackId trackId,		u_int32_t vendor){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			((MP4File*)hFile)->				SetH263Vendor(trackId, vendor);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}}extern "C" void MP4SetH263DecoderVersion(		MP4FileHandle hFile,		MP4TrackId trackId,		u_int8_t decoderVersion){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {				try {			((MP4File*)hFile)->				SetH263DecoderVersion(trackId, decoderVersion);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}}extern "C" void MP4SetH263Bitrates(		MP4FileHandle hFile,		MP4TrackId trackId,		u_int32_t avgBitrate,		u_int32_t maxBitrate){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			((MP4File*)hFile)->				SetH263Bitrates(trackId, avgBitrate, maxBitrate);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}}extern "C" MP4TrackId MP4AddHintTrack(	MP4FileHandle hFile, MP4TrackId refTrackId){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			return ((MP4File*)hFile)->AddHintTrack(refTrackId);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return MP4_INVALID_TRACK_ID;}extern "C" MP4TrackId MP4AddTextTrack(	MP4FileHandle hFile, MP4TrackId refTrackId){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			return ((MP4File*)hFile)->AddTextTrack(refTrackId);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return MP4_INVALID_TRACK_ID;}extern "C" MP4TrackId MP4AddChapterTextTrack(	MP4FileHandle hFile, MP4TrackId refTrackId){	if (MP4_IS_VALID_FILE_HANDLE(hFile)) {		try {			return ((MP4File*)hFile)->AddChapterTextTrack(refTrackId);		}		catch (MP4Error* e) {			PRINT_ERROR(e);			delete e;		}	}	return MP4_INVALID_TRACK_ID;}extern "C" MP4TrackId MP4CloneTrack (MP4FileHandle srcFile, 				     MP4TrackId srcTrackId,				     MP4FileHandle dstFile,				     MP4TrackId dstHintTrackReferenceTrack){  MP4TrackId dstTrackId = MP4_INVALID_TRACK_ID;  if (dstFile == NULL) {    dstFile = srcFile;  }  const char* trackType =     MP4GetTrackType(srcFile, srcTrackId);  if (!trackType) {    return dstTrackId;  }  const char *media_data_name =     MP4GetTrackMediaDataName(srcFile, srcTrackId);  if (media_data_name == NULL) return dstTrackId;  if (MP4_IS_VIDEO_TRACK_TYPE(trackType)) {    if (ATOMID(media_data_name) == ATOMID("mp4v")) {      MP4SetVideoProfileLevel(dstFile, 			      MP4GetVideoProfileLevel(srcFile));      dstTrackId = MP4AddVideoTrack(				    dstFile,				    MP4GetTrackTimeScale(srcFile, 							 srcTrackId),				    MP4GetTrackFixedSampleDuration(srcFile, 								   srcTrackId),				    MP4GetTrackVideoWidth(srcFile, 							  srcTrackId),				    MP4GetTrackVideoHeight(srcFile, 							   srcTrackId),				    MP4GetTrackEsdsObjectTypeId(srcFile, 								srcTrackId));    } else if (ATOMID(media_data_name) == ATOMID("avc1")) {      uint8_t AVCProfileIndication;      uint8_t profile_compat;      uint8_t AVCLevelIndication;      uint32_t sampleLenFieldSizeMinusOne;      uint64_t temp;            if (MP4GetTrackH264ProfileLevel(srcFile, srcTrackId, 				      &AVCProfileIndication,				      &AVCLevelIndication) == false) {	return dstTrackId;      }      if (MP4GetTrackH264LengthSize(srcFile, srcTrackId, 				    &sampleLenFieldSizeMinusOne) == false) {	return dstTrackId;      }      sampleLenFieldSizeMinusOne--;      if (MP4GetTrackIntegerProperty(srcFile, srcTrackId, 				     "mdia.minf.stbl.stsd.*[0].avcC.profile_compatibility",				     &temp) == false) return dstTrackId;      profile_compat = temp & 0xff;            dstTrackId = MP4AddH264VideoTrack(dstFile, 					MP4GetTrackTimeScale(srcFile, 							     srcTrackId),					MP4GetTrackFixedSampleDuration(srcFile, 								       srcTrackId),					MP4GetTrackVideoWidth(srcFile, 							      srcTrackId),					MP4GetTrackVideoHeight(srcFile, 							       srcTrackId),					AVCProfileIndication,					profile_compat,					AVCLevelIndication,					sampleLenFieldSizeMinusOne);        uint8_t **seqheader, **pictheader;	uint32_t *pictheadersize, *seqheadersize;	uint32_t ix;	MP4GetTrackH264SeqPictHeaders(srcFile, srcTrackId, 				      &seqheader, &seqheadersize,				      &pictheader, &pictheadersize);	for (ix = 0; seqheadersize[ix] != 0; ix++) {	  MP4AddH264SequenceParameterSet(dstFile, dstTrackId,					 seqheader[ix], seqheadersize[ix]);	  free(seqheader[ix]);	}	free(seqheader);	free(seqheadersize);	for (ix = 0; pictheadersize[ix] != 0; ix++) {	  MP4AddH264PictureParameterSet(dstFile, dstTrackId,					pictheader[ix], pictheadersize[ix]);	  free(pictheader[ix]);	}	free(pictheader);	free(pictheadersize);    } else      return dstTrackId;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -