from QCamera or QVideoWidget get video bytes
-
Take a look at https://wiki.qt.io/Qt_5.13_Multimedia_Backends, QVideoProbe needs the backend to support "Video probe" feature.
As listed in the tables, recording of Windows and Unix doesn't support it, but player and camera (except wmf) do support.
So I think it may be possible to monitor the camera object directly, but you'll need to handle the media encoding yourself. -
@Bonnie said in from QCamera or QVideoWidget get video bytes:
QVideoProbe
I test QVideoProbe but unfortunately return false
qDebug() << "return" << prob->setSource(recorder);QCamera* mCamera = new QCamera(); QMediaRecorder* recorder = new QMediaRecorder(mCamera); QVideoEncoderSettings settings = recorder->videoSettings(); QVideoProbe* prob = new QVideoProbe(); settings.setResolution(640, 480); settings.setQuality(QMultimedia::VeryHighQuality); settings.setFrameRate(30.0); settings.setCodec("video/mp4"); recorder->setVideoSettings(settings); recorder->setContainerFormat("mp4"); mCamera->setCaptureMode(QCamera::CaptureVideo);
-
@Bonnie said in from QCamera or QVideoWidget get video bytes:
QVideoProbe
I test QVideoProbe but unfortunately return false
qDebug() << "return" << prob->setSource(recorder);QCamera* mCamera = new QCamera(); QMediaRecorder* recorder = new QMediaRecorder(mCamera); QVideoEncoderSettings settings = recorder->videoSettings(); QVideoProbe* prob = new QVideoProbe(); settings.setResolution(640, 480); settings.setQuality(QMultimedia::VeryHighQuality); settings.setFrameRate(30.0); settings.setCodec("video/mp4"); recorder->setVideoSettings(settings); recorder->setContainerFormat("mp4"); mCamera->setCaptureMode(QCamera::CaptureVideo);
-
Ok now return true!
but it display
QVideoFrame(QSize(640, 480), Format_YUYV, NoHandle, ReadOnly, [no timestamp])
image base64: ""I don't understand. I can pay you for consulting If you resolve me problem
-
void QtVideoWidgetsIssueTrack::processFrame(const QVideoFrame& frame) { qDebug() << "processFrame"; if (frame.isValid()) { QVideoFrame cloneFrame(frame); cloneFrame.map(QAbstractVideoBuffer::ReadOnly); qDebug() << cloneFrame; const QImage image(cloneFrame.bits(), cloneFrame.width(), cloneFrame.height(), QVideoFrame::imageFormatFromPixelFormat(cloneFrame.pixelFormat())); QByteArray ba; QBuffer bu(&ba); bu.open(QBuffer::ReadWrite); //bu.open(QIODevice::WriteOnly); image.save(&bu, "PNG"); //bu.close(); //QString imgBase64 = ba.toBase64(); QString imgBase64 = QString::fromLatin1(ba.toBase64().data()); qDebug() << "image base64: " << imgBase64; cloneFrame.unmap(); } }
-
void QtVideoWidgetsIssueTrack::processFrame(const QVideoFrame& frame) { qDebug() << "processFrame"; if (frame.isValid()) { QVideoFrame cloneFrame(frame); cloneFrame.map(QAbstractVideoBuffer::ReadOnly); qDebug() << cloneFrame; const QImage image(cloneFrame.bits(), cloneFrame.width(), cloneFrame.height(), QVideoFrame::imageFormatFromPixelFormat(cloneFrame.pixelFormat())); QByteArray ba; QBuffer bu(&ba); bu.open(QBuffer::ReadWrite); //bu.open(QIODevice::WriteOnly); image.save(&bu, "PNG"); //bu.close(); //QString imgBase64 = ba.toBase64(); QString imgBase64 = QString::fromLatin1(ba.toBase64().data()); qDebug() << "image base64: " << imgBase64; cloneFrame.unmap(); } }
@zabitqt Oh, you can't convert it to QImage like this, as your debug info shows, the frame data you get from the camera is in YUV format, which QImage doesn't support.
If you want to get a QImage, just callframe.image()
, you don't even need to clone, map and unmap... -
@zabitqt Oh, you can't convert it to QImage like this, as your debug info shows, the frame data you get from the camera is in YUV format, which QImage doesn't support.
If you want to get a QImage, just callframe.image()
, you don't even need to clone, map and unmap... -
@Bonnie said in from QCamera or QVideoWidget get video bytes:
frame.image()
It doesn't exist method frame.image(). OK I have understand that the problem is QImage that not support Format_YUYV. I search a solution in google. Thank you so much!