UE4: output game frames to file

坚强是说给别人听的谎言 提交于 2019-12-07 12:32:02

问题


This applies to Unreal Engine 4.9

Each frame, I'd like to save it to file (overwriting the existing one).

For a simple D3D11 demo that I have made, I've been able to do this with:

void Engine::CaptureFrame(D3DX11_IMAGE_FILE_FORMAT format, const LPCTSTR fileName){

    backbuffer->GetResource(&resource);
    ID3D11Texture2D* texture;
    HRESULT hResult = resource->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<LPVOID*>(&texture));
    D3DX11SaveTextureToFile(deviceContext, texture, format, fileName);

    //Clean up
    texture->Release();
    resource->Release();
}

I have done this with OpenGL, too, using a library called "FreeImage".

I don't want to modify UE4 source and am looking for a way to "hook" into UE4 and "capture" the frame.

I've managed to do this with Open Broadcasting Software, but I'd like to do this natively, within UE4, either via c++ or blueprints.

I am also aware that I can do this from the editor, but that is not what I want to do. I want to do this at run-time, automatically.

How can I go about this? Is it even possible?


回答1:


For anyone else who wants to do this, you have a couple of options.

Option A

If you don't care how many screenshot files are generated and don't care what they are called, then you can use a blueprint:

The images will be output to \Unreal Projects\ProjectName\Saved\Screenshots\Windows where ProjectName is the name of your project.

Option B

If you don't want multiple screenshot files and need control over where they go, then you can do this via code:

//Called every frame
void AMyDempActor::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

    FString filename = "test.png";
    FScreenshotRequest::RequestScreenshot(filename, false, false);

}

Here is the documentation on FScreenshotRequest



来源:https://stackoverflow.com/questions/33488681/ue4-output-game-frames-to-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!