C++ 如何将FFmepg AVFrame转换为Gdiplus::位图?

C++ 如何将FFmepg AVFrame转换为Gdiplus::位图?,c++,bitmap,ffmpeg,gdi+,gdi,C++,Bitmap,Ffmpeg,Gdi+,Gdi,伙计们,我用FFmpeg处理视频,现在我想把AVFrame转换成Gdiplus::Bitmap,然后做些别的事情,帧是24位RGB。但有时它失败了 这是我的代码: int ProcessFrame(AVFrame* src, const int margin_left, const int margin_top, const int margin_right, const int margin_bottom) { // Start Gidplus Gdiplus::Gdiplu

伙计们,我用FFmpeg处理视频,现在我想把AVFrame转换成Gdiplus::Bitmap,然后做些别的事情,帧是24位RGB。但有时它失败了

这是我的代码:

int ProcessFrame(AVFrame* src, const int margin_left, const int margin_top, const int margin_right, const int margin_bottom)
{

    // Start Gidplus
    Gdiplus::GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR gdiplusToken;
    Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

    int stride = src->width * 3;

    // Load the image
    Gdiplus::Bitmap* bitmap = new Gdiplus::Bitmap(src->width, src->height, stride, PixelFormat24bppRGB, src->data[0]);
    Gdiplus::Rect imageRect(margin_left, margin_top, bitmap->GetWidth() - margin_left - margin_right, bitmap->GetHeight() - margin_top - margin_bottom);
    Gdiplus::BitmapData bitmapData;
    bitmap->LockBits(&imageRect, Gdiplus::ImageLockModeRead, PixelFormat24bppRGB, &bitmapData);

    //Do something else

    bitmap->UnlockBits(&bitmapData);

    // Delete bitmap
    delete bitmap;

    // Shut down Gdiplus
    Gdiplus::GdiplusShutdown(gdiplusToken);

    return 0;
}
我发现位图有一个方法

Gdiplus::Bitmap* bitmap = new Gdiplus::Bitmap::FromStream();
所以我们可以先把AVFrame转换成Stream

还是更好的方法


有人能帮我吗?谢谢

它只是偶尔失败,还是一直失败?当它失败时会发生什么?