从QML Camera获取原始H.264和AAC数据

时间:2015-12-02 15:20:08

标签: c++ qml qt5 h.264 aac

根据此代码:

import QtQuick 2.5
import QtMultimedia 5.5

Item {
    id: root
    Camera {
        objectName: "camera"
                id: camera
                captureMode: Camera.CaptureVideo
                videoRecorder.videoCodec: "h264"
                videoRecorder.audioCodec: "aac"
        }
}

是否可以在不将其写入磁盘驱动器的情况下获取原始H.264和AAC数据(例如,在unsigned char *类型中)?我可以从C ++端访问那些流吗? 实际上,将来这些数据将使用librtmp发送到nginx服务器。

1 个答案:

答案 0 :(得分:0)

我将使用GStreamer。

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <gst/gst.h>

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    GstElement *pipeline;
    GstBus *bus;
    GstMessage *msg;

    putenv("GST_DEBUG=6");
    putenv("GST_PLUGIN_PATH_1_0=E:\\sdk\\gstreamer\\1.0\\x86_64\\lib\\gstreamer-1.0\\");
    putenv("GST_PLUGIN_PATH=E:\\sdk\\gstreamer\\1.0\\x86_64\\lib\\gstreamer-1.0\\");

    /* Initialize GStreamer */
    gst_init (&argc, &argv);

    /* Build the pipeline */
    //pipeline = gst_parse_launch ("playbin uri=http://docs.gstreamer.com/media/sintel_trailer-480p.webm", 
    //NULL);
    pipeline = gst_parse_launch ("ksvideosrc device-index=0 ! autovideosink", NULL); // Windows OS specific

    /* Start playing */
    gst_element_set_state (pipeline, GST_STATE_PLAYING);

    /* Wait until error or EOS */
    bus = gst_element_get_bus (pipeline);
    msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, (GstMessageType)(GST_MESSAGE_ERROR | GST_MESSAGE_EOS));

    /* Free resources */
    if (msg != NULL)
      gst_message_unref (msg);
    gst_object_unref (bus);
    gst_element_set_state (pipeline, GST_STATE_NULL);
    gst_object_unref (pipeline);

    return app.exec();
}

您可以使用此lib为QML编写自己的插件。 感谢Qt论坛的正确路径。