PDA

View Full Version : Convert QVidoFrame to QPixMap / QImage is very slow



hasti
22nd September 2014, 11:53
I've used QVideoProbe to access camera frames. My platform is Android. I've converted each camera frames to QImage and then pixmap and show on QLabel. My problem is this process is very slow. frames are showned very slowly. can i convert QVideoFrame straight to QPixMap or other faster way to showing camera frames? here is my code:
QCamera *camera = new QCamera(this);

camera->setCaptureMode(QCamera::CaptureViewfinder);

QVideoProbe *videoProbe = new QVideoProbe(this);

bool ret = videoProbe->setSource(camera);
qDebug() <<"videoProbe->setSource(camera):" << ret;

if (ret) {
connect(videoProbe, SIGNAL(videoFrameProbed(const QVideoFrame &)),
this, SLOT(present(const QVideoFrame &)));

}

camera->start();
...
...


bool MainWindow::present(const QVideoFrame &frame)
{
qDebug() <<"counter:" << ++counter;

QVideoFrame cloneFrame(frame);
if(cloneFrame.map(QAbstractVideoBuffer::ReadOnly))
{
QImage img(
cloneFrame.size(), QImage::Format_ARGB32);
qt_convert_NV21_to_ARGB32(cloneFrame.bits(),
(quint32 *)img.bits(),
cloneFrame.width(),
cloneFrame.height());

label->setPixmap(QPixmap::fromImage(img));

cloneFrame.unmap();
}

return true;
}


I've used QPainter and passed it a QImage / OPixmap and used painter.drawImage and painter.drawPixmap. but still camera frames are shown very slowly in QPainter.

hasti
22nd September 2014, 12:47
I've used QVideoProbe to access camera frames. My platform is Android. I've converted each camera frames to QImage and then pixmap and show on QLabel. My problem is this process is very slow. frames are showned very slowly. can i convert QVideoFrame straight to QPixMap or other faster way to showing camera frames? here is my code:
QCamera *camera = new QCamera(this);

camera->setCaptureMode(QCamera::CaptureViewfinder);

QVideoProbe *videoProbe = new QVideoProbe(this);

bool ret = videoProbe->setSource(camera);
qDebug() <<"videoProbe->setSource(camera):" << ret;

if (ret) {
connect(videoProbe, SIGNAL(videoFrameProbed(const QVideoFrame &)),
this, SLOT(present(const QVideoFrame &)));

}

camera->start();
...
...


bool MainWindow:resent(const QVideoFrame &frame)
{
qDebug() <<"counter:" << ++counter;

QVideoFrame cloneFrame(frame);
if(cloneFrame.map(QAbstractVideoBuffer::ReadOnly))
{
QImage img(
cloneFrame.size(), QImage::Format_ARGB32);
qt_convert_NV21_to_ARGB32(cloneFrame.bits(),
(quint32 *)img.bits(),
cloneFrame.width(),
cloneFrame.height());

label->setPixmap(QPixmap::fromImage(img));

cloneFrame.unmap();
}

return true;
}


I've used QPainter and passed it a QImage / OPixmap and used painter.drawImage and painter.drawPixmap. but still camera frames are shown very slowly in QPainter.

anda_skoa
22nd September 2014, 14:24
If you only need to display the video, have you tried using the camera as the media object of a QVideoWidget or the video widget as the camera's view finder?

Cheers,
_

hasti
22nd September 2014, 14:30
Thanks for your reply. Yes I've tried using QVideoWidget and QCameraViewFinder for camera live streaming
, but on android nothing displayed. camera setviewfinder not worked on android for me.

anda_skoa
22nd September 2014, 16:25
Does it work on the desktop?
I.e. is it a bug on Android or does this not work at all?

Cheers,
_