我刚开始编写一个应用程序,我的想法是创建类似 StreamMyGame 但供个人使用的东西,已经有一个名为 Single Player Game Transmiter 的项目可以实现其中的一些(http://sourceforge.net/projects/spgt/files/ )。
到目前为止,我没有编码也没有流式传输,我只是捕获视频并将其显示在我的应用程序窗口中。
那么我该如何处理编码/流式传输呢?我在想原始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
孤岛危机 2 捕获 (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 钩子方法来获取帧。