Qt6.5 QCamera setting the cameraFormat was NV12 why output was UYVY?
-
I was setting the format(Format_NV12) on QCamera by setCameraFormat, but the output format was uyvy(Format_UYVY) from QVideoSink on apple m1 machine finally, why?
It was NORMAL on apple intel machine(output was nv12).
That's very strangely!
Qt Version: 6.5
And rollback to 6.4.3,no such problem!!!
code:
QCameraDevice cameraDevice; const QList<QCameraDevice> availableCameras = QMediaDevices::videoInputs(); for (const QCameraDevice &availableCamera : availableCameras) { if (availableCamera == QMediaDevices::defaultVideoInput()) cameraDevice = availableCamera; } camera_.reset(new QCamera(cameraDevice)); if (camera_->cameraFormat().isNull()) { auto formats = cameraDevice.videoFormats(); if (!formats.isEmpty()) { QCameraFormat bestFormat; for (const auto &fmt : formats) { if (fmt.pixelFormat() == QVideoFrameFormat::Format_NV12 && fmt.resolution().width() > fmt.resolution().height() && bestFormat.resolution().width() < fmt.resolution().width() && bestFormat.resolution().height() < fmt.resolution().height()) { bestFormat = fmt; } } camera_->setCameraFormat(bestFormat); } } captureSession_.setCamera(camera_.data()); captureSession_.setVideoSink(&videoSink_); connect(&videoSink_, &QVideoSink::videoFrameChanged, this, &VideoCaputer::OnFrameChanged); ... void VideoCaputer::OnFrameChanged(const QVideoFrame &frame) { // why? just on apple m1 if (frame.pixelFormat() == QVideoFrameFormat::Format_UYVY) { qDebug()<< "pixelFormat error"; return; } }
-
I was setting the format(Format_NV12) on QCamera by setCameraFormat, but the output format was uyvy(Format_UYVY) from QVideoSink on apple m1 machine finally, why?
It was NORMAL on apple intel machine(output was nv12).
That's very strangely!
Qt Version: 6.5
And rollback to 6.4.3,no such problem!!!
code:
QCameraDevice cameraDevice; const QList<QCameraDevice> availableCameras = QMediaDevices::videoInputs(); for (const QCameraDevice &availableCamera : availableCameras) { if (availableCamera == QMediaDevices::defaultVideoInput()) cameraDevice = availableCamera; } camera_.reset(new QCamera(cameraDevice)); if (camera_->cameraFormat().isNull()) { auto formats = cameraDevice.videoFormats(); if (!formats.isEmpty()) { QCameraFormat bestFormat; for (const auto &fmt : formats) { if (fmt.pixelFormat() == QVideoFrameFormat::Format_NV12 && fmt.resolution().width() > fmt.resolution().height() && bestFormat.resolution().width() < fmt.resolution().width() && bestFormat.resolution().height() < fmt.resolution().height()) { bestFormat = fmt; } } camera_->setCameraFormat(bestFormat); } } captureSession_.setCamera(camera_.data()); captureSession_.setVideoSink(&videoSink_); connect(&videoSink_, &QVideoSink::videoFrameChanged, this, &VideoCaputer::OnFrameChanged); ... void VideoCaputer::OnFrameChanged(const QVideoFrame &frame) { // why? just on apple m1 if (frame.pixelFormat() == QVideoFrameFormat::Format_UYVY) { qDebug()<< "pixelFormat error"; return; } }
-
@zruibin Did you check whether
bestFormat
isFormat_NV12
or not?
I just think maybecameraDevice.videoFormats()
doesn't supportFormat_NV12
on that machine/camera?