首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从QCamera或QVideoWidget获取视频字节

从QCamera或QVideoWidget获取视频字节
EN

Stack Overflow用户
提问于 2022-10-09 06:12:40
回答 1查看 63关注 0票数 0

如何从QCameraQVideoWidget获得字节数组(帧)?

我成功地从相机和麦克风捕捉视频和音频,现在我想将它们发送到socket TCP通道,以创建一个简单的视频/音频调用软件。

我尝试过的

  • I已经重新实现了QAbstractVideoSurface方法,

但是“现在”的方法并没有被调用。怎么啦?

如何在QCameraViewfinder中使用这个类?

这是我的代码

代码语言:javascript
复制
#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()
{}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74002498

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档