【问题标题】:Getting raw H.264 and AAC data from QML Camera从 QML 相机获取原始 H.264 和 AAC 数据
【发布时间】:2015-12-02 15:20:08
【问题描述】:
根据这段代码:
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服务器。
【问题讨论】:
标签:
c++
qml
qt5
h.264
aac
【解决方案1】:
我将使用 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();
}
您可以使用此库为 QML 编写自己的插件。
感谢 Qt 论坛的正确路径。