How to encode scene capture textures into h264 video?

I have some scene captures and I want to encode their rendering results into h264 videos, with UE4’s internal AmfVideoEncoder. But I failed to achieve that:(

The offical usage of AmfVideoEncoder registers back buffer capture with UE4:
FSlateApplication::Get().GetRenderer()->OnBackBufferReadyToPresent().AddRaw(this, &FGameplayMediaEncoder::OnBackBufferReady);

The only modification I did was replacing the back buffer with scene capture’s rendering target textures. But the “OnEncodedVideoFrame” callback function won’t be called and “CopyTexture” was always return false. Maybe I missed some synchronized operation before copying texture or encoding? Does anyone know how to do in correct way or with some other ideas? Thank you very much!

Hi were you able to solve this issue?

Sorry I think I might’ve found the issue. I believe this bug is due to an old version of the AVEncoder. The solution may be solved in the new version but because I was using UE5EA, this was not fixed.

Essentially the problem was that the frame size + image format matched the inputted render target texture. This was captured in a separate if condition that didn’t write to a GPUFence which signals the data had successfully been copied over.

The solution if you must use it is to set the render target image format to RGBA 16F instead of 8 bit per pixel.

1 Like

Sorry for late reply, I found this error was gone when I used the new video encode code snippet. I upload my video encode implementation, just in case of others need it.
CameraVideoEncoder.cpp (17.7 KB)
CameraVideoEncoder.h (2.5 KB)

1 Like

Can you briefly explain how to use it ? Is it encoding the scene captured by camera acotor(such as CineCameraActor) into h264 video? Can I call the function in blueprint?
I would appreciate it for your apply!