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

📄 mp4info.cpp

📁 完整的RTP RTSP代码库
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	const char* typeName = "Unknown";	const char *media_data_name;	char originalFormat[8];	char  oformatbuffer[32];	originalFormat[0] = 0;	*oformatbuffer = 0;	uint8_t type = 0;		media_data_name = MP4GetTrackMediaDataName(mp4File, trackId);	// encv 264b	if (strcasecmp(media_data_name, "encv") == 0) {	  if (MP4GetTrackMediaDataOriginalFormat(mp4File, 						 trackId, 						 originalFormat, 						 sizeof(originalFormat)) == false)	      media_data_name = NULL;	      	}  	char  typebuffer[80];	if (media_data_name == NULL) {	  typeName = "Unknown - no media data name";	  foundTypeName = true;	} else if ((strcasecmp(media_data_name, "avc1") == 0) ||	  	(strcasecmp(originalFormat, "264b") == 0)) {	  // avc	  uint8_t profile, level;	  char profileb[20], levelb[20];	  if (MP4GetTrackH264ProfileLevel(mp4File, trackId, 					  &profile, &level)) {	    if (profile == 66) {	      strcpy(profileb, "Baseline");	    } else if (profile == 77) {	      strcpy(profileb, "Main");	    } else if (profile == 88) {	      strcpy(profileb, "Extended");	    } else if (profile == 100) {	      strcpy(profileb, "High");	    } else if (profile == 110) {	      strcpy(profileb, "High 10");	    } else if (profile == 122) {	      strcpy(profileb, "High 4:2:2");	    } else if (profile == 144) {	      strcpy(profileb, "High 4:4:4");	    } else {	      snprintf(profileb, 20, "Unknown Profile %x", profile);	    } 	    switch (level) {	    case 10: case 20: case 30: case 40: case 50:	      snprintf(levelb, 20, "%u", level / 10);	      break;	    case 11: case 12: case 13:	    case 21: case 22:	    case 31: case 32:	    case 41: case 42:	    case 51:	      snprintf(levelb, 20, "%u.%u", level / 10, level % 10);	      break;	    default:	      snprintf(levelb, 20, "unknown level %x", level);	      break;	    }	    if (originalFormat != NULL && originalFormat[0] != '\0') 	      snprintf(oformatbuffer, 32, "(%s) ", originalFormat);	    snprintf(typebuffer, sizeof(typebuffer), "H264 %s%s@%s", 		    oformatbuffer, profileb, levelb);	    typeName = typebuffer;	  } else {	    typeName = "H.264 - profile/level error";	  }	  foundTypeName = true;	} else if (strcasecmp(media_data_name, "s263") == 0) {	  // 3gp h.263	  typeName = "H.263";	  foundTypeName = true;	} else if ((strcasecmp(media_data_name, "mp4v") == 0) ||		   (strcasecmp(media_data_name, "encv") == 0)) {	  // note encv might needs it's own field eventually.	  type = MP4GetTrackEsdsObjectTypeId(mp4File, trackId);	  if (type == MP4_MPEG4_VIDEO_TYPE) {	    type = MP4GetVideoProfileLevel(mp4File, trackId);	    typeName = Mpeg4VisualProfileName(type);	    if (typeName == NULL) {	      typeName = "MPEG-4 Unknown Profile";	    } else {	      foundTypeName = true;	    }	  } else {	    for (u_int8_t i = 0; i < numMpegVideoTypes; i++) {	      if (type == mpegVideoTypes[i]) {		typeName = mpegVideoNames[i];		foundTypeName = true;		break;	      }	    }	  }	} else {	  typeName = media_data_name;	  foundTypeName = true; // we don't have a type value to display	}	MP4Duration trackDuration =		MP4GetTrackDuration(mp4File, trackId);	double msDuration =		UINT64_TO_DOUBLE(MP4ConvertFromTrackDuration(mp4File, trackId,			trackDuration, MP4_MSECS_TIME_SCALE));	u_int32_t avgBitRate =		MP4GetTrackBitRate(mp4File, trackId);	// Note not all mp4 implementations set width and height correctly	// The real answer can be buried inside the ES configuration info	u_int16_t width = MP4GetTrackVideoWidth(mp4File, trackId);	u_int16_t height = MP4GetTrackVideoHeight(mp4File, trackId);	double fps = MP4GetTrackVideoFrameRate(mp4File, trackId);	char *sInfo = (char*)MP4Malloc(256);	// type duration avgBitrate frameSize frameRate	if (foundTypeName) {	  sprintf(sInfo,		  "%u\tvideo\t%s%s, %.3f secs, %u kbps, %ux%u @ %f fps\n",		  trackId,		  MP4IsIsmaCrypMediaTrack(mp4File, trackId) ? "encv - " : "",		  typeName,		  msDuration / 1000.0,		  (avgBitRate + 500) / 1000,		  width,		  height,		  fps		  );	} else {	  sprintf(sInfo,		  "%u\tvideo\t%s(%u), %.3f secs, %u kbps, %ux%u @ %f fps\n",		  trackId,		  typeName,		  type, 		  msDuration / 1000.0,		  (avgBitRate + 500) / 1000,		  width,		  height,		  fps		  );	}	return sInfo;}static char* PrintCntlInfo(	MP4FileHandle mp4File,	MP4TrackId trackId){  const char *media_data_name = MP4GetTrackMediaDataName(mp4File, trackId);  const char *typeName = "Unknown";  if (media_data_name == NULL) {    typeName = "Unknown - no media data name";  } else if (strcasecmp(media_data_name, "href") == 0) {    typeName = "ISMA Href";  } else {    typeName = media_data_name;  }  MP4Duration trackDuration =     MP4GetTrackDuration(mp4File, trackId);   double msDuration =     UINT64_TO_DOUBLE(MP4ConvertFromTrackDuration(mp4File, trackId, 						 trackDuration, MP4_MSECS_TIME_SCALE));  char *sInfo = (char *)MP4Malloc(256);  snprintf(sInfo, 256,	   "%u\tcontrol\t%s, %.3f secs\n",	   trackId, 	   typeName,	   msDuration / 1000.0);  return sInfo;}	  static char* PrintHintInfo(	MP4FileHandle mp4File,	MP4TrackId trackId){	MP4TrackId referenceTrackId =		MP4GetHintTrackReferenceTrackId(mp4File, trackId);	char* payloadName = NULL;	if (!MP4GetHintTrackRtpPayload(mp4File, trackId, &payloadName))	  return NULL;	char *sInfo = (char*)MP4Malloc(256);	snprintf(sInfo, 256, 		"%u\thint\tPayload %s for track %u\n",		trackId,		payloadName,		referenceTrackId);	free(payloadName);	return sInfo;}static char* PrintTrackInfo(	MP4FileHandle mp4File,	MP4TrackId trackId){	char* trackInfo = NULL;	const char* trackType =		MP4GetTrackType(mp4File, trackId);	if (trackType == NULL) return NULL;	if (!strcmp(trackType, MP4_AUDIO_TRACK_TYPE)) {		trackInfo = PrintAudioInfo(mp4File, trackId);	} else if (!strcmp(trackType, MP4_VIDEO_TRACK_TYPE)) {		trackInfo = PrintVideoInfo(mp4File, trackId);	} else if (!strcmp(trackType, MP4_HINT_TRACK_TYPE)) {		trackInfo = PrintHintInfo(mp4File, trackId);	} else if (strcmp(trackType, MP4_CNTL_TRACK_TYPE) == 0) {	  trackInfo = PrintCntlInfo(mp4File, trackId);	} else {		trackInfo = (char*)MP4Malloc(256);		if (!strcmp(trackType, MP4_OD_TRACK_TYPE)) {		  snprintf(trackInfo, 256,				"%u\tod\tObject Descriptors\n",				trackId);		} else if (!strcmp(trackType, MP4_SCENE_TRACK_TYPE)) {		  snprintf(trackInfo, 256,				"%u\tscene\tBIFS\n",				trackId);		} else {		  snprintf(trackInfo, 256,					"%u\t%s\n",					trackId, trackType);		}	}	return trackInfo;}extern "C" char* MP4Info(	MP4FileHandle mp4File,	MP4TrackId trackId){	char* info = NULL;	if (MP4_IS_VALID_FILE_HANDLE(mp4File)) {		try {			if (trackId == MP4_INVALID_TRACK_ID) {			  uint buflen = 4 * 1024;				info = (char*)MP4Calloc(buflen);				buflen -= snprintf(info, buflen,						"Track\tType\tInfo\n");				u_int32_t numTracks = MP4GetNumberOfTracks(mp4File);				for (u_int32_t i = 0; i < numTracks; i++) {					trackId = MP4FindTrackId(mp4File, i);					char* trackInfo = PrintTrackInfo(mp4File, trackId);					strncat(info, trackInfo, buflen);					uint newlen = strlen(trackInfo);					if (newlen > buflen) buflen = 0;					else buflen -= newlen;					MP4Free(trackInfo);				}			} else {				info = PrintTrackInfo(mp4File, trackId);			}		}		catch (MP4Error* e) {			delete e;		}	}	return info;}extern "C" char* MP4FileInfo(	const char* fileName,	MP4TrackId trackId){	MP4FileHandle mp4File =		MP4Read(fileName);	if (!mp4File) {		return NULL;	}	char* info = MP4Info(mp4File, trackId);	MP4Close(mp4File);	return info;	// caller should free this}

⌨️ 快捷键说明

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