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

📄 mp4info.cpp

📁 6410BSP1
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        "MPEG-2 SNR",        "MPEG-2 Spatial",        "MPEG-2 High",        "MPEG-2 4:2:2",        "MPEG-1",        "JPEG",        "YUV12",        "H.263",        "H.261",    };    u_int8_t numMpegVideoTypes =        sizeof(mpegVideoTypes) / sizeof(u_int8_t);    bool foundTypeName = false;    const char* typeName = "Unknown";    const char *media_data_name;    uint8_t type = 0;        media_data_name = MP4GetTrackMediaDataName(mp4File, trackId);    char  typebuffer[80];    if (media_data_name == NULL) {      typeName = "Unknown - no media data name";      foundTypeName = true;    } else if (strcasecmp(media_data_name, "avc1") == 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 {          sprintf(profileb, "Unknown Profile %x", profile);        }         switch (level) {        case 10: case 20: case 30: case 40: case 50:          sprintf(levelb, "%u", level / 10);          break;        case 11: case 12: case 13:        case 21: case 22:        case 31: case 32:        case 41: case 42:        case 51:          sprintf(levelb, "%u.%u", level / 10, level % 10);          break;        default:          sprintf(levelb, "unknown level %x", level);          break;        }        sprintf(typebuffer, "H264 %s@%s", 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;    MP4GetHintTrackRtpPayload(mp4File, trackId, &payloadName);    char *sInfo = (char*)MP4Malloc(256);    sprintf(sInfo,        "%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 (!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)) {            sprintf(trackInfo,                "%u\tod\tObject Descriptors\n",                trackId);        } else if (!strcmp(trackType, MP4_SCENE_TRACK_TYPE)) {            sprintf(trackInfo,                "%u\tscene\tBIFS\n",                trackId);        } else {            sprintf(trackInfo,                    "%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) {                info = (char*)MP4Calloc(4*1024);                sprintf(info, "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);                    strcat(info, trackInfo);                    MP4Free(trackInfo);                }            } else {                info = PrintTrackInfo(mp4File, trackId);            }        }        __except (EXCEPTION_EXECUTE_HANDLER) {//            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 + -