HarmonyOS OH_MD_KEY_DURATION无法得到视频的时长

OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_DURATION, &videoDuration);接口调用返回失败,且无法获取视频时长

void DeMuxer::GetTrackInfo() {
  int trackType = -1;
  for (int32_t index = 0; index < trackCount; index++) {
    OH_AVDemuxer_SelectTrackByID(demuxer, index);
    OH_AVFormat *trackFormat = OH_AVSource_GetTrackFormat(source, index);
    OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &trackType);
    if (trackType == MEDIA_TYPE_VID) {
      bool getWidthRet = OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_WIDTH, &width);
      OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_HEIGHT, &height);
      OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_ROTATION, &rotation);
      OH_AVFormat_GetDoubleValue(trackFormat, OH_MD_KEY_FRAME_RATE, &frameRate);
      OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_BITRATE, &bitrate);
      bool getDurationRet = OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_DURATION, &videoDuration);
      videoDuration = 8700 * 1000;
      char *videoTemp;
      OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, const_cast<char const **>(&videoTemp));
      vTrackId = index;
      SL_MEDIA_LOGD(MODULE_DEMUXER,
        "demuxer:videoMime:%{public}s--width:%{public}d--getWidthRet:%{public}d--height:%{public}d"
      "--frameRate:%{public}f--bitrate%{public}ld--videoDuration%{public}ld--getDurationRet%{"
      "public}d--videoTrackId:%{public}d",
      videoTemp, width, getWidthRet, height, frameRate, bitrate, videoDuration, getDurationRet,
      vTrackId);
      videoMime = videoTemp;
      mutexManager->vTrackId = vTrackId;
    }

    if (trackType == MEDIA_TYPE_AUD) {
      aTrackId = index;
      OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, &audioChannelCount);
      OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, &audioSampleRate);
      OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, &audioSampleFormat);
      OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AAC_IS_ADTS, &aacIsADTS);
      char *audioTemp;
      OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, const_cast<char const **>(&audioTemp));
      OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_BITRATE, &audioBitrate);
      OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_DURATION, &audioDuration);
      SL_MEDIA_LOGD(MODULE_DEMUXER,
        "demuxer:audioMime:%{public}s--audioBitrate:%{public}lld--aacIsADTS:%{public}d"
      "--audioSampleFormat:%{public}d--audioSampleRate:%{public}d"
      "--audioChannelCount%{public}d--audioTrackId:%{public}d--audioDuration:%{public}ld",
      audioTemp, audioBitrate, aacIsADTS, audioSampleFormat, audioSampleRate, audioChannelCount,aTrackId,audioDuration);
      audioMime = audioTemp;
      mutexManager->aTrackId = aTrackId;
    }
    OH_AVFormat_Destroy(trackFormat);
    trackType = -1;
  }
}

是我通过Demuxer获取参数的代码,其他参数都是能够正常获取的,只有duration获取失败,没有发现有什么报错的日志

HarmonyOS
1天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
fox280

建议后续尝试通过sourceFormat获取,而不是trackFormat

分享
微博
QQ
微信
回复
22h前
相关问题
HarmonyOS AVDexmuer无法获取视频时长
49浏览 • 1回复 待解决
HarmonyOS 怎么获取视频播放时长
415浏览 • 1回复 待解决
HarmonyOS animateToduration无效
50浏览 • 1回复 待解决
如何录制视频并设置最大录制时长
156浏览 • 0回复 待解决
HarmonyOS视频压缩模块无法压缩视频
440浏览 • 1回复 待解决
HarmonyOS 统计页面停留时长
54浏览 • 1回复 待解决