HarmonyOS AVDexmuer无法获取视频时长

照着这里的文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/audio-video-demuxer-V5

下面的duration输出为0:

for (uint32_t index = 0; index < track_count; ++index) {
  OH_AVFormat *track_format = OH_AVSource_GetTrackFormat(av_source_, index);
  if (!track_format) {
    XLOG_ERROR("OH_AVSource_GetTrackFormat failed");
    if (error) {
      *error = MAKE_ERROR(kErrorDomainDecode, kErrorCodeGetTrackFormatFailed);
    }
    return;
  }
  OH_AVFormat_GetIntValue(track_format, OH_MD_KEY_TRACK_TYPE, &track_type);
  OH_MediaType media_type = static_cast<OH_MediaType>(track_type);
  if (media_type == OH_MediaType::MEDIA_TYPE_VID) {
    {
      int64_t duraion;
      OH_AVFormat_GetLongValue(track_format, OH_MD_KEY_DURATION, &duraion);
      XLOG_INFO("video duration: %lld", duraion);
    }
    {
      int32_t duraion;
      OH_AVFormat_GetIntValue(track_format, OH_MD_KEY_DURATION, &duraion);
      XLOG_INFO("video duration: %d", duraion);
    }
    {
      double duration;
      OH_AVFormat_GetDoubleValue(track_format, OH_MD_KEY_DURATION, &duration);
      XLOG_INFO("video duration: %f", duration);
    }
  } else {
    {
      int64_t duraion;
      OH_AVFormat_GetLongValue(track_format, OH_MD_KEY_DURATION, &duraion);
      XLOG_INFO("audio duration: %lld", duraion);
    }
    {
      int32_t duraion;
      OH_AVFormat_GetIntValue(track_format, OH_MD_KEY_DURATION, &duraion);
      XLOG_INFO("audio duration: %d", duraion);
    }
    {
      double duration;
      OH_AVFormat_GetDoubleValue(track_format, OH_MD_KEY_DURATION, &duration);
      XLOG_INFO("video duration: %f", duration);
    }
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
HarmonyOS
2024-12-25 11:14:00
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
FengTianYa

目前系统只提供文件的时长,从soruce_format获取,没有提供轨道的时长。

分享
微博
QQ
微信
回复
2024-12-25 13:15:46
相关问题
HarmonyOS 怎么获取视频的播放时长
1025浏览 • 1回复 待解决
HarmonyOS 如何获取视频时长和分辨率
839浏览 • 1回复 待解决
HarmonyOS视频是否可以限制视频时长
1059浏览 • 1回复 待解决
如何录制视频并设置最大录制时长
939浏览 • 0回复 待解决
HarmonyOS视频压缩模块无法压缩视频
1323浏览 • 1回复 待解决
HarmonyOS 统计页面停留时长
630浏览 • 1回复 待解决
HarmonyOS 画中画视频无法播放
725浏览 • 1回复 待解决
HarmonyOS H265视频无法播放
919浏览 • 1回复 待解决