简体   繁体   English

DirectShow快速视频播放

[英]DirectShow Jerky Video Playback at Speed

I am using DirectShow/VMR9 to playback a MPEG 4 video in my application. 我正在使用DirectShow / VMR9在我的应用程序中播放MPEG 4视频。 I use IMediaSeeking SetRate to set the speed of the video. 我使用IMediaSeeking SetRate设置视频的速度。 Playing back a video I have created plays well at speeds up to 4x, above this the video becomes very jerky. 播放我创建的视频时,其播放速度最高可达4倍,在此之上,视频变得非常生涩。 Playing back the same file using Windows media player at speeds above 4x is not jerky. 使用Windows媒体播放器以高于4倍的速度播放同一文件并不容易。 Can anyone shed some light as to why windows media player can play my file OK at speed but my DirectShow filter graph cannot. 任何人都可以阐明为什么Windows Media Player可以快速播放我的文件但我的DirectShow过滤器无法显示的原因。

My graph topology is Recording.avi -> AVI Splitter -> Mpeg4s Decoder DMO -> Ds.NET Grabber -> Color Space Converter -> Video Mixing Renderer 9. 我的图形拓扑是Recording.avi-> AVI Splitter-> Mpeg4s解码器DMO-> Ds.NET Grabber->色彩空间转换器->视频混合渲染器9。

Please let me know if you need any further information. 如果您需要任何进一步的信息,请告诉我。

Update 更新资料

I removed the grabber (and thus csc as well) and playback is not jerky up to 8x which would be good enough but I do need the grabber. 我卸下了采集卡(因此也取下了csc),并且播放速度最高不超过8倍,这已经足够了,但是我确实需要采集卡。 The CSC ended up there when I added the grabber. 当我添加采集卡时,CSC结束了。 I would like if possible to remove the CSC to see if that improves things while retaining the grabber. 我想尽可能删除CSC,以查看是否在保留采集卡的同时有所改善。 Below are my graphs with intermediate formats with and without the filter. 以下是我的带有中间格式(带和不带过滤器)的图表。 I tried setting the media subtype of the grabber to NV12 (like the non grabber graph), however I get error a "No combination of intermediate filters could be found to make the connection." 我尝试将抓取器的媒体子类型设置为NV12(例如非抓取器图),但是出现错误“找不到中间过滤器的组合来建立连接”。 I include my code for configuring the grabber. 我包括用于配置采集卡的代码。

Is it possible to get this to work without the csc? 没有csc,是否可以使它正常工作?

Also not sure if it is relevant but I do not understand how the video dimensions are changed on the graph without grabber. 也不确定它是否相关,但我不了解在没有抓取器的情况下视频尺寸如何在图形上更改。

With Grabber 与抓斗

Recording.avi ----- (AVI) ----- AVI Splitter ----- (MP4V - 704*576 – 24bits ) ----- Mpeg4s Decoder DMO ----- (RGB24 704*576) ----- Ds.NET Grabber - (RGB24 704*576) ----- Color Space Converter ----- (ARGB32 704*576) ----- Video Mixing Renderer 9 Recording.avi -----(AVI)----- AVI分离器-----(MP4V-704 * 576 – 24bits)----- Mpeg4s解码器DMO -----(RGB24 704 * 576 )----- Ds.NET抓取器-(RGB24 704 * 576)-----色彩空间转换器-----((ARGB32 704 * 576)-----视频混合渲染器9

Without Grabber 没有抓斗

Recording.avi ----- (AVI) ----- AVI Splitter ----- (MP4V - 704*576 – 24bits ) ----- Mpeg4s Decoder DMO ----- (NV12 768*576 12 bits) ----- Video Mixing Renderer 9. Recording.avi -----(AVI)----- AVI分离器-----(MP4V-704 * 576 – 24bits)----- Mpeg4s解码器DMO -----(NV12 768 * 576 12位)-----视频混合渲染器9。

 private void ConfigureSampleGrabber(ISampleGrabber sampleGrabber)
 {
        AMMediaType media;
        int hr;

        // Set the media type to Video/RBG24
        media = new AMMediaType();
        media.majorType = MediaType.Video;
        media.subType = MediaSubType.ARGB32; // tried NV12 here, gives error.
        media.formatType = FormatType.VideoInfo;
        hr = sampleGrabber.SetMediaType(media);
        DsError.ThrowExceptionForHR(hr);

        DsUtils.FreeAMMediaType(media);
        media = null;

        // Configure the samplegrabber
        hr = sampleGrabber.SetBufferSamples(true);
        DsError.ThrowExceptionForHR(hr);
    }

CPU Usage details CPU使用率详细信息

Core i3 - 3300MHz – with hyperthreading 4GB RAM 酷睿i3-3300MHz –具有超线程4GB RAM

4x Speed 4倍速度

CPU1 ~45% CPU1〜45%

CPU2 ~0% CPU2〜0%

CPU3 ~33% CPU3〜33%

CPU4 ~0% CPU4〜0%

8x Speed 8倍速度

CPU1 ~40% CPU1〜40%

CPU2 ~25% (but very spiky 0-50%) CPU2〜25%(但非常尖刻0-50%)

CPU3 ~40% CPU3〜40%

CPU4 ~0% CPU4〜0%

Core i3 - 3300MHz – Hyperthreading disabled in BIOS. 核心i3-3300MHz –在BIOS中禁用了超线程。

4x Speed 4倍速度

CPU1 ~45% CPU1〜45%

CPU2 ~33% CPU2〜33%

8x Speed (same results at 16x Speed) 8倍速(16倍速时,结果相同)

CPU1 ~66% CPU1〜66%

CPU2 ~45% CPU2〜45%

A typical cause would be that at this playback rate your decoding thread is running at 100% CPU and is not capable to decode more frames, you start seeing irregular frame presentation and/or frames dropped. 一个典型的原因是,在此回放速率下,您的解码线程在100%CPU上运行并且无法解码更多帧,您开始看到不规则的帧呈现和/或掉帧。

Where to look: 在哪里看:

  • check your CPU with task manager or another application to see if one of the cores is maxed out and is no longer going to idle state 使用任务管理器或其他应用程序检查您的CPU,以查看其中一个内核是否已用完并且不再进入空闲状态
  • checked VMR properties to see if frames are dropped, or jitter is getting too high 检查VMR属性以查看帧是否丢失或抖动太高

在此处输入图片说明

For the playback of videos the MediaPlayer is using MediaFoundation. 为了播放视频,MediaPlayer正在使用MediaFoundation。 And for most videos the playback is hardware accelerated. 对于大多数视频,播放是通过硬件加速的。 If you have some filters between the decoder and the renderer in DirectShow, there is no hardware acceleration in DirectShow. 如果在DirectShow的解码器和渲染器之间有一些过滤器,则DirectShow中没有硬件加速。 Try it again without the DS.Net Grabber and the color-space-converter (=> csc is also a huge performance killer) 在没有DS.Net Grabber和色彩空间转换器的情况下重试(=> csc还是一个巨大的性能杀手)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM