gpt4 book ai didi

c# - 如何找到上传的 mp4 或 f4v 视频的持续时间?

转载 作者:太空宇宙 更新时间:2023-11-03 14:26:06 24 4
gpt4 key购买 nike

我已经尝试通过安装 k-lite mega codec pack 使用 directshowlib-2005无法找到 mp4 文件或 f4v 文件的持续时间(avi、wmv 和 flv 没有问题)。我使用 directshowlib-2005 的 ImediaSeeking 接口(interface)来查找持续时间。但是对于 mp4 和 f4v,GetDuration 方法返回零

我知道这是编解码器的问题,但我不知道要安装哪个编解码器来获取 mp4 和 f4v 文件的持续时间。

我使用的代码如下所示:

static public bool GetVideoLength(string fileName, out long length)
{
DirectShowLib.FilterGraph graphFilter = new DirectShowLib.FilterGraph();
DirectShowLib.IGraphBuilder graphBuilder;
//DirectShowLib.IMediaPosition mediaPos=null;
DirectShowLib.IMediaSeeking mediaPos;
length = 4294967296;

try
{
graphBuilder = (DirectShowLib.IGraphBuilder)graphFilter;
graphBuilder.RenderFile(fileName, null);
//mediaPos = (DirectShowLib.IMediaPosition)graphBuilder;
mediaPos = (DirectShowLib.IMediaSeeking)graphBuilder;
// mediaPos.get_Duration(out length);
mediaPos.GetDuration(out length);

return true;
}
catch
{
return false;
}
finally
{
mediaPos = null;
graphBuilder = null;
graphFilter = null;

}
}

任何人都可以告诉我应该安装的确切编解码器来帮助我找到上面提到的持续时间吗?

最佳答案

我会简单地使用 MediaInfo .它也有一个 CLI,因此您可以从您的代码中调用它并获取此信息。它几乎可以处理各种编解码器和容器。

关于c# - 如何找到上传的 mp4 或 f4v 视频的持续时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3960212/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com