FFMPEG Frame to DirectX Surface

前端 未结 1 1774
挽巷
挽巷 2021-02-06 19:14

Given a pointer to an AVFrame from FFMPEG\'s avcodec_decode_video() function how do I copy the image to a DirectX surface? (Assume I have a pointer to an appropriat

相关标签:
1条回答
  • 2021-02-06 19:35

    You can use FFMPEG's img_convert() function to simultaneously copy the image to your surface and convert it to RGB format. Here's a few lines of code pasted from a recent project of mine which did a similar thing (although I was using SDL instead of DirectX):

        AVFrame *frame;
        avcodec_decode_video(_ffcontext, frame, etc...);
    
        lockYourSurface();
        uint8_t *buf = getPointerToYourSurfacePixels();
    
    // Create an AVPicture structure which contains a pointer to the RGB surface.
        AVPicture pict;
    
        memset(&pict, 0, sizeof(pict));
    
        avpicture_fill(&pict, buf, PIX_FMT_RGB32,
                       _ffcontext->width, _ffcontext->height);
    
    
    
    // Convert the image into RGB and copy to the surface.
        img_convert(&pict, PIX_FMT_RGB32, (AVPicture *)frame,
                    _context->pix_fmt, _context->width, _context->height);
    
    
        unlockYourSurface();
    
    0 讨论(0)
提交回复
热议问题