简体   繁体   中英

FFMPEG Frame to DirectX Surface

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM