本人由于專案需要,使用了WRTC 的二次開發的視頻語言。由于上面提供的QT 界面,需要將功能集成到MFC上,所以把其他功能都 移植到MFC上。
再移植視頻的時候,QTdemo有如下代碼,意思是獲取視頻禎,然后顯示界面上。
void VideoWidget::paintEvent(QPaintEvent* e) {
if (image_.get()) {
static int frames = 0;
frames++;
if (!timer2.isValid()) {
timer2.start();
}
QImage qimage(image_.get(), image_width_, image_height_, image_width_ * 4,
QImage::Format_ARGB32);
QPainter painter(this);
painter.scale(float(this->width()) / image_width_,
float(this->height()) / image_height_);
painter.drawImage(0, 0, qimage);
if (timer2.elapsed() >= 1000) {
std::cout << "rps: " << frames << std::endl;
frames = 0;
timer2.restart();
}
}
}
void VideoWidget::RenderFrame(std::unique_ptr<ARGBBuffer> video_frame) {
static int frames = 0;
frames++;
if (!timer.isValid()) {
timer.start();
}
if (!video_frame)
return;
if (image_width_ != video_frame->resolution.width ||
image_height_ != video_frame->resolution.height) {
image_width_ = video_frame->resolution.width;
image_height_ = video_frame->resolution.height;
image_size_ = image_width_ * image_height_ * 4;
image_.reset(new uint8_t[image_size_]);
}
// std::copy(video_frame->buffer, video_frame->buffer + image_size_,
// image_.get());
memcpy(image_.get(), video_frame->buffer, image_size_);
this->update();
if (timer.elapsed() >= 1000) {
std::cout << "fps: " << frames << std::endl;
frames = 0;
timer.restart();
}
}
我在MFC 上能獲取禎,但是死活顯示不出來。
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, image_size_);
void * pData = GlobalLock(hGlobal);
memcpy(pData, video_frame->buffer, image_size_);
GlobalUnlock(hGlobal);
IStream * pStream = NULL;
if (CreateStreamOnHGlobal(hGlobal, TRUE, &pStream) == S_OK)
{
CImage *image = new CImage();
image->Create(image_width_, image_height_, image_width_*4);
// Load IStream Fail
HRESULT hResult = image->Load(pStream);
//CImage image;
////HRESULT hr = image.Load(pStream);
//if (SUCCEEDED(image.Load(TEXT("1111.png"))))
//{
// image.Draw(GetDC()->m_hDC,0,0,100,500);
//}
pStream->Release();
}
GlobalFree(hGlobal);
我應該 怎么樣顯示這樣的視頻圖片。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/69183.html
上一篇:問一個關于QT C++問題
