伙计们,我通过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;
}
我发现Bitmap有一个方法
Gdiplus::Bitmap* bitmap = new Gdiplus::Bitmap::FromStream();
所以也许我们可以先将AVFrame转换为Stream
还是更好的方式?
任何人都可以帮助我吗?感谢