如何从QCamera或QVideoWidget获得字节数组(帧)?
我成功地从相机和麦克风捕捉视频和音频,现在我想将它们发送到socket TCP通道,以创建一个简单的视频/音频调用软件。
我尝试过的:
QAbstractVideoSurface方法,但是“现在”的方法并没有被调用。怎么啦?
如何在QCameraViewfinder中使用这个类?
这是我的代码
#include <QtMultimedia/QAbstractVideoSurface>
class QMyAbstractVideoSurface :
public QAbstractVideoSurface
{
Q_OBJECT
public:
explicit QMyAbstractVideoSurface(QObject* parent = 0);
~QMyAbstractVideoSurface();
QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const;
bool present(const QVideoFrame& frame);
bool start(const QVideoSurfaceFormat& format);
void stop();
};
#include "QMyAbstractVideoSurface.h"
#include <QDebug>
QMyAbstractVideoSurface::QMyAbstractVideoSurface(QObject* parent) {
}
bool QMyAbstractVideoSurface::start(const QVideoSurfaceFormat& format) {
return QAbstractVideoSurface::start(format);
}
void QMyAbstractVideoSurface::stop() {
QAbstractVideoSurface::stop();
}
bool QMyAbstractVideoSurface::present(const QVideoFrame& frame) {
QVideoFrame cloneFrame(frame);
QByteArray a((char*)cloneFrame.bits());
qDebug() << "present";
qDebug() << a.toBase64();
return true;
}
QList<QVideoFrame::PixelFormat> QMyAbstractVideoSurface::
supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const
{
Q_UNUSED(handleType);
return QList<QVideoFrame::PixelFormat>()
<< QVideoFrame::Format_ARGB32
<< QVideoFrame::Format_ARGB32_Premultiplied
<< QVideoFrame::Format_RGB32
<< QVideoFrame::Format_RGB24
<< QVideoFrame::Format_RGB565
<< QVideoFrame::Format_RGB555
<< QVideoFrame::Format_ARGB8565_Premultiplied
<< QVideoFrame::Format_BGRA32
<< QVideoFrame::Format_BGRA32_Premultiplied
<< QVideoFrame::Format_BGR32
<< QVideoFrame::Format_BGR24
<< QVideoFrame::Format_BGR565
<< QVideoFrame::Format_BGR555
<< QVideoFrame::Format_BGRA5658_Premultiplied
<< QVideoFrame::Format_AYUV444
<< QVideoFrame::Format_AYUV444_Premultiplied
<< QVideoFrame::Format_YUV444
<< QVideoFrame::Format_YUV420P
<< QVideoFrame::Format_YV12
<< QVideoFrame::Format_UYVY
<< QVideoFrame::Format_YUYV
<< QVideoFrame::Format_NV12
<< QVideoFrame::Format_NV21
<< QVideoFrame::Format_IMC1
<< QVideoFrame::Format_IMC2
<< QVideoFrame::Format_IMC3
<< QVideoFrame::Format_IMC4
<< QVideoFrame::Format_Y8
<< QVideoFrame::Format_Y16
<< QVideoFrame::Format_Jpeg
<< QVideoFrame::Format_CameraRaw
<< QVideoFrame::Format_AdobeDng;
}
QMyAbstractVideoSurface::~QMyAbstractVideoSurface()
{}发布于 2022-10-09 12:19:18
您可能正在寻找一个QVideoSink:https://doc-snapshots.qt.io/qt6-dev/qvideosink.html。
QVideoSink类可用于从Qt多媒体逐帧检索视频数据。
它应该设置在QMediaCaptureSession:https://doc-snapshots.qt.io/qt6-dev/qmediacapturesession.html#setVideoSink上。
对于Qt5,您有QAbstractVideoSurface https://doc.qt.io/qt-5/qabstractvideosurface.html或QVideoProbe https://doc.qt.io/qt-5/qvideoprobe.html。
https://stackoverflow.com/questions/74002498
复制相似问题