FFMPEG Frame to DirectX Surface

ⅰ亾dé卋堺 提交于 2019-12-03 14:06:48

问题


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 appropriately sized DX X8R8G8B8 surface.)

Thanks.

John.


回答1:


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();


来源:https://stackoverflow.com/questions/321298/ffmpeg-frame-to-directx-surface

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