SceneCapture2D to Avencoder

Hello i’m trying to take the texture target from a UTextureRenderTarget2D and use the copytexture to copy it to a AVEncoder instance.

I have the AVEncoder working, because i can get this to work with the OnBackBufferReadyToPresent callback.

However when i replace the reference with the one for the texture target the copy texture simply stops working.

I found somecode on where which seems to do it successfully.

However this interface seems to have been replaced with the CopyTexture command.

But like the awnser here i’m trying to use the enqueue render command.

UOpencvLibBPLibrary *This = this;
ENQUEUE_RENDER_COMMAND(Readback)([This]
(FRHICommandListImmediate& RHICmdList)
{
AVEncoder::FBufferId BufferId;
FTimespan Now = FTimespan::FromSeconds(FApp::GetCurrentTime()) - This->startingTime;
FRHITexture2D *texture_pointer = This->targetTexture->GetRenderTargetResource()->GetTexture2DRHI();
RHICmdList.Transition(FRHITransitionInfo(texture_pointer, ERHIAccess::Unknown, ERHIAccess::ReadOnlyMask));
FRHIRenderPassInfo RPInfo(texture_pointer, ERenderTargetActions::Load_Store);
RHICmdList.BeginRenderPass(RPInfo, TEXT(“CopyBackbuffer”));
if (!This->VideoEncoder->CopyTexture(texture_pointer,
Now,
Now - This->LastVideoInputTimestamp,
BufferId,
texture_pointer->GetSizeXY()
))
{
UE_LOG(LogTemp, Error, TEXT(“Failed to copy”));
return;
}
RHICmdList.EndRenderPass();
This->VideoEncoder->Encode(BufferId, false, 0, nullptr);
This->LastVideoInputTimestamp = Now;
});

The code example above simply crashes in the render thread, so i’m wonder if this is the right approach or if i need to flush my render command somehow?

The engine version is 4.26.1.

Anyways appreciate the help.