Coder Social home page Coder Social logo

dxgicapturesample's Introduction

dxgicapturesample's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

dxgicapturesample's Issues

类型转换错误提示vs2022,

when i create a new project of vs2022,i copy the code to my new project ,and do the same property settings like cloned project form u repo,it comes the error as its show in the blow picture,i have no idea about the error,if u can give me some help,thats wounld be great!
image

Trying to capture sequential screen grabs; time depends on mouse movement

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.

  • Brought everything into Visual Studio 17, x64
  • Made changes to get things to compile, for four CComQIPtr assignments:
CComQIPtr<ID3D11Texture2D> spTextureResource = CComQIPtr<ID3D11Texture2D>(spDXGIResource);
CComQIPtr<IDXGISurface1> spDXGISurface = CComQIPtr<IDXGISurface1>(spD3D11Texture2D);
CComQIPtr<IDXGIOutput1> spDXGIOutput1 = CComQIPtr<IDXGIOutput1>(*OutputIter); 
CComQIPtr<IDXGIDevice1> spDXGIDevice = CComQIPtr<IDXGIDevice1>(spD3D11Device);
  • Added a loop around GetOutputBits, and timed it (using std::chrono, not shown)
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:

  • Do you have any idea why the mouse might be holding up continuous acquisition?
  • If I wanted to preprocess the screen-grab on the GPU card (e.g. with CUDA code) - is there a logical place to insert this? (I'm very new to Direct3D.)

Question

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;
}

Capture a windowed app

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?

Pixel

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

Can't capture fullscreen program on windows 8.1

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.