from QCamera or QVideoWidget get video bytes
-
@zabitqt said in from QCamera or QVideoWidget get video bytes:
I want array of bytes
char* is basically an array of bytes in C/C++.
If you want QByteArray then use https://doc.qt.io/qt-6/qbytearray.html#QByteArray-1 -
QVideoProbe* probe = new QVideoProbe;
qDebug() << "lo stato di probe";
qDebug() << probe->setSource(recorder);
QObject::connect(probe, SIGNAL(videoFrameProbed(QVideoFrame)), this, SLOT(processFrame(QVideoFrame)));The function probe->setSource(recorder); return always false. Why?
-
QVideoProbe* probe = new QVideoProbe;
qDebug() << "lo stato di probe";
qDebug() << probe->setSource(recorder);
QObject::connect(probe, SIGNAL(videoFrameProbed(QVideoFrame)), this, SLOT(processFrame(QVideoFrame)));The function probe->setSource(recorder); return always false. Why?
@zabitqt said in from QCamera or QVideoWidget get video bytes:
qDebug() << probe->setSource(recorder);
What exactly is recorder here and was it initialised?
-
@zabitqt said in from QCamera or QVideoWidget get video bytes:
qDebug() << probe->setSource(recorder);
What exactly is recorder here and was it initialised?
QCamera* mCamera = new QCamera(); QMediaRecorder* recorder = new QMediaRecorder(mCamera); QVideoEncoderSettings settings = recorder->videoSettings(); 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); recorder->record(); mCamera->start();
Could be that If the media recorder instance does not support monitoring video, this function will return false?
-
QCamera* mCamera = new QCamera(); QMediaRecorder* recorder = new QMediaRecorder(mCamera); QVideoEncoderSettings settings = recorder->videoSettings(); 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); recorder->record(); mCamera->start();
Could be that If the media recorder instance does not support monitoring video, this function will return false?
@zabitqt said in from QCamera or QVideoWidget get video bytes:
Could be that If the media recorder instance does not support monitoring video, this function will return false?
According to documentation: "If the media recorder instance does not support monitoring video, this function will return false"
-
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. -
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!