掌握DirectShow的MP4文件时间 [英] Getting MP4 File Duration with DirectShow

查看:544
本文介绍了掌握DirectShow的MP4文件时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要得到一个MP4文件的持续时间,优选为以秒为两倍。我使用DirectShow(见下面的代码),但它一直扔一个特别无益的错误。我想知道,如果有人有一个简单的解决了这一点。 (说真的,谁知道得到的信息会如此困难)

 公共静态无效getDuration(字符串moviePath)
{
FilgraphManager m_objFilterGraph = NULL;
m_objFilterGraph =新FilgraphManager();
m_objFilterGraph.RenderFile(moviePath);

IMediaPosition m_objMediaPosition = NULL;
m_objMediaPosition = m_objFilterGraph为IMediaPosition;

Console.WriteLine(m_objMediaPosition.Duration);
}



每当我运行此代码,我得到的错误:从HRESULT异常: 0x80040265



我使用也试过这样:获取视频
长度,但它不工作,或者是因为我不认为它的​​工作原理上的MP4文件。



说真的,我觉得。像必须有这样做更简单的方法。



请注意:我宁愿避免使用的exe像ffmpeg的,然后解析输出来获取信息<。 / p>

解决方案

您正确地接近问题。你需要建立一个良好的管道从源代码 .MP4 文件和最多的视频和音频渲染器开始。然后 IMediaPosition.Duration 会得到你想要的东西。目前,你得到 VFW_E_UNSUPPORTED_STREAM ,因为你不能建立管道。



需要注意的是在干净的Windows为MPEG-4没有很好的支持DirectShow中,你需要安装添加缺少的块第三方解析器。这是你的问题的可能原因。有很好的免费DirectShow的MPEG-4过滤器可填补这一空白。



链接下的代码示例获取影片的长度基本上是太有效,但它使用了已弃用的组件,它在其他make额外的假设到有问题的媒体文件。前提是在系统中 .MP4 支持, IMediaPosition.Duration 是给你,你找什么。


I need to get the duration of an mp4 file, preferably as a double in seconds. I was using DirectShow (see code below), but it keeps throwing a particularly unhelpful error. I'm wondering if someone has an easy solution to this. (Seriously, who knew that getting that information would be so difficult)

public static void getDuration(string moviePath)
    {
        FilgraphManager m_objFilterGraph = null;
        m_objFilterGraph = new FilgraphManager();
        m_objFilterGraph.RenderFile(moviePath);

        IMediaPosition m_objMediaPosition = null;
        m_objMediaPosition = m_objFilterGraph as IMediaPosition;

        Console.WriteLine(m_objMediaPosition.Duration);
    }

Whenever I run this code, I get the error: "Exception from HRESULT: 0x80040265"

I also tried using this: Getting length of video but it doesn't work either because I don't think that it works on MP4 files.

Seriously, I feel like there has to be a much easier way to do this.

Note: I would prefer to avoid using exe's like ffmpeg and then parsing the output to get the information.

解决方案

You are approaching the problem correctly. You need to build a good pipeline starting from source .MP4 file and up to video and audio renderers. Then IMediaPosition.Duration will get you what you want. Currently you are getting VFW_E_UNSUPPORTED_STREAM because you cannot build the pipeline.

Note that there is no good support for MPEG-4 in DirectShow in clean Windows, you need a third party parser installed to add missing blocks. This is the likely cause of your problem. There are good Free DirectShow Mpeg-4 Filters available to fill this gap.

The code sample under the link Getting length of video is basically valid too, however it uses deprecated component which in additional make additional assumptions onto the media file in question. Provided that there is support for .MP4 in the system, IMediaPosition.Duration is to give you what you look for.

这篇关于掌握DirectShow的MP4文件时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆