pgurenko / dxgicapturesample Goto Github PK
View Code? Open in Web Editor NEWDXGICaptureSample
License: MIT License
DXGICaptureSample
License: MIT License
Hi.
I would like to capture windowed apps (non full Desktop) using the great DXGI performance. Given an process and its width and height, is DXGI capable to do it?
I would like to have a very fast screen capture in a loop, extracting a portion of this data to send to a server. To start, I made some small additions to your (great) code, to try and benchmark the capturing of multiple desktops.
CComQIPtr<ID3D11Texture2D> spTextureResource = CComQIPtr<ID3D11Texture2D>(spDXGIResource);
CComQIPtr<IDXGISurface1> spDXGISurface = CComQIPtr<IDXGISurface1>(spD3D11Texture2D);
CComQIPtr<IDXGIOutput1> spDXGIOutput1 = CComQIPtr<IDXGIOutput1>(*OutputIter);
CComQIPtr<IDXGIDevice1> spDXGIDevice = CComQIPtr<IDXGIDevice1>(spD3D11Device);
for (int j = 0; j < 10; j++) {
int i = 0;
do {
hr = g_DXGIManager.GetOutputBits(pBuf, rcDim);
i++;
} while (hr == DXGI_ERROR_WAIT_TIMEOUT || i < 2);
if( FAILED(hr) ) {
printf("GetOutputBits failed with hr=0x%08x\n", hr);
return hr;
}
}
When I run this, it takes a long time, if I don't move the mouse. With no mouse movement, it typically takes 3.6 - 4.2s. If I move the mouse continuously, then run, it takes 137 ms.
I don't need the mouse pointer graphics information in the screen grab. I've tried both leaving in the 'mouse pointer' code and commenting it out, but it doesn't seem to make a difference.
I've run this on both my PC (running virtual desktop) and laptop (single desktop), and the behavior is similar (~1.8s no movement; ~158 ms movement).
I've also tried both CSDesktop
and CSMonitor1
, the behavior is the same.
Questions:
Hi. Thank you for your work.
I'm trying to capture a DirectX game running in fullscreen mode.
I set capture source to monitor 1:
g_DXGIManager.SetCaptureSource(CSMonitor1);
I use timeout in command line to be able to switch to the fullscreen game before the program starts:
timeout 10 & DXGICaptureSample.exe
On Windows 10 the program is able to get a screenshot of the game. On Windows 8.1 it fails, the console output says display size is 0x0 (which should be 1920x1080).
Do you know a way to make it work for fullscreen applications under Windows 8.1?
I am trying to install this on VS2015 Community Edition, using windows 10, however I've got the following errors:
identifier "unique_ptr" is undefined
Hi,
would you be so kind and explain to me what would be necessary to get raw access to the image captured? i would like to spit out the pixelcolors on the std output.
for example
g_DXGIManager.SetCaptureSource(CSMonitor1);
RECT rcDim;
rcDim.left = 1;
rcDim.top = 1;
rcDim.right = 361;
rcDim.bottom = 2;
hr = g_DXGIManager.GetOutputBits(pBuf, rcDim);
printf(pBuf)
i was able to get some output but could not recognice any pixel colors.
my endgoal would be a list of uniq colors in a known area on a known monitor and how much pixels there are of.
so a call of the exe would result in:
0xFF0000,2
0x00FF00,20
0x0000FF,30
0x000000,100
0xFFFFFF,200
Thanks in Advance,
JR
Hi,
I have a few question to your project. How many fps can you achieve?
i tried to measure how many fps your capture would give. it only gets 6 fps... any idea? i tested it with windows 10 + NVIDIA GeForce GT 720M
// DXGICaptureSample.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "DXGIManager.h"
#include <time.h>
DXGIManager g_DXGIManager;
void init() {
CoInitialize(NULL);
}
int capture() {
//printf("DXGICaptureSample. Fast windows screen capture\n");
//printf("Capturing desktop to: capture.bmp\n");
//printf("Log: logfile.log\n");
g_DXGIManager.SetCaptureSource(CSDesktop);
RECT rcDim;
g_DXGIManager.GetOutputRect(rcDim);
DWORD dwWidth = rcDim.right - rcDim.left;
DWORD dwHeight = rcDim.bottom - rcDim.top;
//printf("dwWidth=%d dwHeight=%d\n", dwWidth, dwHeight);
DWORD dwBufSize = dwWidth*dwHeight*4;
BYTE* pBuf = new BYTE[dwBufSize];
CComPtr<IWICImagingFactory> spWICFactory = NULL;
HRESULT hr = spWICFactory.CoCreateInstance(CLSID_WICImagingFactory);
if( FAILED(hr) )
return hr;
int i=0;
do
{
hr = g_DXGIManager.GetOutputBits(pBuf, rcDim);
i++;
}
while (hr == DXGI_ERROR_WAIT_TIMEOUT || i < 2);
if( FAILED(hr) )
{
printf("GetOutputBits failed with hr=0x%08x\n", hr);
return hr;
}
//printf("Saving capture to file\n");
CComPtr<IWICBitmap> spBitmap = NULL;
hr = spWICFactory->CreateBitmapFromMemory(dwWidth, dwHeight, GUID_WICPixelFormat32bppBGRA, dwWidth*4, dwBufSize, (BYTE*)pBuf, &spBitmap);
if( FAILED(hr) )
return hr;
CComPtr<IWICStream> spStream = NULL;
hr = spWICFactory->CreateStream(&spStream);
if (SUCCEEDED(hr)) {
hr = spStream->InitializeFromFilename(L"capture.bmp", GENERIC_WRITE);
}
CComPtr<IWICBitmapEncoder> spEncoder = NULL;
if (SUCCEEDED(hr)) {
hr = spWICFactory->CreateEncoder(GUID_ContainerFormatBmp, NULL, &spEncoder);
}
if (SUCCEEDED(hr)) {
hr = spEncoder->Initialize(spStream,WICBitmapEncoderNoCache);
}
CComPtr<IWICBitmapFrameEncode> spFrame = NULL;
if (SUCCEEDED(hr)) {
hr = spEncoder->CreateNewFrame(&spFrame, NULL);
}
if (SUCCEEDED(hr)) {
hr = spFrame->Initialize(NULL);
}
if (SUCCEEDED(hr)) {
hr = spFrame->SetSize(dwWidth, dwHeight);
}
WICPixelFormatGUID format;
spBitmap->GetPixelFormat(&format);
if (SUCCEEDED(hr)) {
hr = spFrame->SetPixelFormat(&format);
}
if (SUCCEEDED(hr)) {
hr = spFrame->WriteSource(spBitmap, NULL);
}
if (SUCCEEDED(hr)) {
hr = spFrame->Commit();
}
if (SUCCEEDED(hr)) {
hr = spEncoder->Commit();
}
delete[] pBuf;
return 0;
}
int _tmain(int argc, _TCHAR* argv[]) {
init();
clock_t t1 = clock();
int i;
int iterations = 100;
for (i = 0;i < iterations;i++) {
capture();
}
clock_t t2 = clock();
printf("%d iterations: %0.0f fps\n", iterations, iterations / ((double)(t2 - t1) / CLOCKS_PER_SEC));
return 0;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.