使用 DirectShow 确定音频文件的长度

发布于 2024-08-20 07:25:49 字数 124 浏览 8 评论 0原文

我刚刚开始使用 DirectShow.NET,并且试图获取音频文件的长度(以秒为单位)。音频可以是 .mp3、.wav、.aac 或 .m4a。

我可以使用 DirectShow 获取此信息,还是需要一些其他 API?

I am just starting with DirectShow.NET, and I am trying to get the length (in seconds) of an audio file. The audio may be .mp3, .wav, .aac, or .m4a.

Can I get this information using DirectShow, or do I need some other APIs?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无妨# 2024-08-27 07:25:49

是的,您可以使用 DirectShow 来做到这一点。有多种方法可以做到这一点。一种方法是查询 IMediaSeeking 界面图形对象,然后调用 GetDuration该接口上的方法。

GetDuration 返回一个 64 位整数值,表示播放该文件所需的时间。

您需要调用 GetTimeFormat 方法来找出持续时间的单位。最可能的默认值是 TIME_FORMAT_MEDIA_TIME,即十分之一微秒。

在这种情况下,您可以将持续时间除以 10*1000*1000 以获得秒数。

如果您想强制使用单位,还可以在调用 GetDuration 之前调用 SetTimeFormat

yes you can do this with DirectShow. There are a variety of ways to do this. One way is to query the IMediaSeeking interface on the graph object, and then call the GetDuration method on this interface.

GetDuration returns a 64bit integer value for how long it would take to play the file.

You will need to call the GetTimeFormat method to find out what units the duration is in. The most likely default value is TIME_FORMAT_MEDIA_TIME which is 10ths of a microsecond.

IN that case you would divide the duration by 10*1000*1000 to get seconds.

You can also call SetTimeFormat before calling GetDuration if you want to force the units.

镜花水月 2024-08-27 07:25:49

您还可以使用 IMediaPosition 接口中的 get_Duration() 。

这将返回一个双精度值,视频持续时间以秒为单位。

    Double Lenght;

    m_FilterGraph = new FilterGraph()

//Configure the FilterGraph()

    m_mediaPosition = m_FilterGraph as IMediaPosition;
    m_mediaPosition.get_Duration(out Length);

You can also use get_Duration() from IMediaPosition interface.

This return a double value with the video duration in seconds.

    Double Lenght;

    m_FilterGraph = new FilterGraph()

//Configure the FilterGraph()

    m_mediaPosition = m_FilterGraph as IMediaPosition;
    m_mediaPosition.get_Duration(out Length);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文