【问题标题】:How to find duration of an uploaded mp4 or f4v video?如何查找上传的 mp4 或 f4v 视频的时长?
【发布时间】:2010-10-18 14:34:02
【问题描述】:

我通过安装 k-lite mega codec pack 尝试使用 directshowlib-2005。它找不到mp4文件或f4v文件的时长(avi、wmv和flv都没有问题)。我使用directshowlib-2005 的ImediaSeeking 接口来查找持续时间。但是对于 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;               

        }
    }

谁能帮我告诉我应该安装的确切编解码器以找到上面提到的持续时间?

【问题讨论】:

  • 我提出的一个稍微不同的问题的答案可能对你有用:stackoverflow.com/questions/3936816/…
  • 而 MP4 文件可以包含多种编解码器。可能是 H.264(很可能),也可能是其他东西。
  • 嗨,在寻找为什么我的代码不适用于 mp4 时,我发现了以下语句:“它是否在容器中并不重要,重要的是你是否有它的解析器/读取器。没有库存的 DirectShow 解析器来读取原始 H.264 文件,也没有我能想到的第三方解析器。此外,IMediaSeeking 是否可以使用这样的原始文件取决于实现。最后,大多数与 H.264 相关的过滤器使用 MPEG2Video 或 VideoInfo2,它们都不能与 MediaDet 一起使用,因此您必须自己构建图表。”你能帮我吗?

标签: c# asp.net video duration directshow.net


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-09
    • 2020-11-16
    • 1970-01-01
    • 2018-07-25
    • 2012-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多