【发布时间】:2012-07-14 05:50:03
【问题描述】:
我刚开始编写应用程序,我的想法是创建类似 StreamMyGame 的东西,但供个人使用,已经有一个名为 Single Player Game Transmiter 的项目可以实现其中的一些(http://sourceforge.net/projects/spgt /文件/)。
到目前为止,我既不是编码也不是流式传输,我只是捕获视频并将其显示在我的应用程序窗口中。
那么我该如何处理编码/流式传输?我在想原始 JPEG 的 UDP 流将是最简单的路径,但我不确定。
此外,我如何优化我目前所拥有的?它可以很好地播放视频,但是在捕获游戏窗口时,它似乎不像原始视频那样活泼,我认为这可能是因为它在后台运行。这就引出了另一个问题,如何捕获具有指定标题的窗口而不是活动窗口?
https://github.com/fr500/desktop_streamer
编辑:
使用当前捕获方法的一些测试:
视频播放器捕捉 (960x720p)
starting benchmark
================================================
looking for window: test.mp4
looking for window: test.mp4
looking for window: test.mp4
looking for window: test.mp4
looking for window: test.mp4
================================================
starting single thread capture only test
Time Elapsed: 19480 milliseconds
Frame Time: 32 milliseconds
Rough FPS: 30
Sleeping 2 seconds
starting single thread capture and save as bmp test
Time Elapsed: 19768 milliseconds
Frame Time: 32 milliseconds
Rough FPS: 30
Sleeping 2 seconds
starting single thread capture and save as jpg test
Time Elapsed: 28593 milliseconds
Frame Time: 47 milliseconds
Rough FPS: 20
Sleeping 2 seconds
starting dual thread capture only test
Time Elapsed: 19515 milliseconds
Frame Time: 32 milliseconds
Rough FPS: 30
Sleeping 2 seconds
starting quad thread capture only test
Time Elapsed: 19481 milliseconds
Frame Time: 32 milliseconds
Rough FPS: 30
Sleeping 2 seconds
Crysis 2 Capture (1024x768p)
starting benchmark
================================================
looking for window: Crysis 2 (TM)
looking for window: Crysis 2 (TM)
looking for window: Crysis 2 (TM)
looking for window: Crysis 2 (TM)
looking for window: Crysis 2 (TM)
looking for window: Crysis 2 (TM)
looking for window: Crysis 2 (TM)
================================================
starting single thread capture only test
Time Elapsed: 20003 milliseconds
Frame Time: 33 milliseconds
Rough FPS: 29
Sleeping 2 seconds
starting single thread capture and save as bmp test
Time Elapsed: 20105 milliseconds
Frame Time: 33 milliseconds
Rough FPS: 29
Sleeping 2 seconds
starting single thread capture and save as jpg test
Time Elapsed: 17353 milliseconds
Frame Time: 28 milliseconds
Rough FPS: 34
Sleeping 2 seconds
starting dual thread capture only test
Time Elapsed: 19991 milliseconds
Frame Time: 33 milliseconds
Rough FPS: 30
Sleeping 2 seconds
starting quad thread capture only test
Time Elapsed: 19983 milliseconds
Frame Time: 33 milliseconds
Rough FPS: 30
Sleeping 2 seconds
将图像保存为 BMP 并不会真正增加任何开销,但保存为 JPG 确实让我了解了视频编码可能产生的开销。最大的问题仍然是获取帧本身,它现在太慢了,无法跟上,因此丢失了一些帧。如果能够以 60+ fps 的速度捕获帧,那么对于单人游戏来说,编码 + 流媒体延迟确实是可以控制的。
我将尝试使用 DX 钩子方法来获取帧。
【问题讨论】:
标签: c# encoding streaming capture