0

I'm writing a C++ program to encode frames from a DirectX game to the H.264/MPEG-4 AVC format. I am using libx264 alone with no other dependencies at the moment.

I have a ID3D11Texture2D* resolved back buffer of the next game frame. I need to somehow copy this into the x264_picture input (apparently YUV420P format according to limited help I've found) but I cannot find any way to do so online.

Here is my code at the moment:

void Fx264VideoEncoder::Fx264VideoEncoderImpl::InitFrameInputBuffer(const FTexture2DRHIRef& BackBuffer, FFrame& Frame)
{
    x264_picture_alloc(Frame.InputPicture, X264_CSP_I420, x264Parameters.i_width, x264Parameters.i_height);

    // We need to take the back buffer and convert it to an input format that libx264 can understand
    {
        ID3D11Texture2D* ResolvedBackBufferDX11 = (ID3D11Texture2D*)(GetD3D11TextureFromRHITexture(Frame.ResolvedBackBuffer)->GetResource());
        EPixelFormat PixelFormat = Frame.ResolvedBackBuffer->GetFormat();

        // ...?
    }
}
  • [DirectXTex](https://github.com/Microsoft/DirectXTex) has software conversion for some video formats in [this source file](https://github.com/Microsoft/DirectXTex/blob/master/DirectXTex/DirectXTexConvert.cpp). – Chuck Walbourn Jan 17 '19 at 18:29
  • @ChuckWalbourn Thanks, i'll check that out. – Chris Sixsmith Jan 17 '19 at 21:14

0 Answers0