2015-11-30 55 views
0

我正在使用不支持的v4L相機,我需要使用gstreamer將視頻流傳輸到遠程PC。
我已成功使用Qt和QImages在主機上進行流式處理。 更早我問過關於如何將外部幀輸入gstreamer的問題here如何通過udp通過gstreamer發送QImages


我讀博客here,並試圖使用gstreamer 1.0來實現它,但不知如何它不按預期工作。
所以我想通過gstreamer在相同的網絡,但在不同的工作站上流式傳輸qimages。我想知道是否有人可以給我起點如何使用gstreamer 1.0發送Qimages。我不是要求代碼,而只是一個方向。
我對這個多媒體的東西很新,所以如果你用外行的語言解釋它,我將不勝感激。

在此先感謝

回答

2

首先,你需要確定你要使用通過UDP傳輸它什麼協議和編碼類型。對於大多數情況,我建議使用h264而不是RTP。

GStreamer提供了大量的插件來執行此操作,其中包括一個名爲gst-launch的命令行實用程序。下面是一些基本的發送/接收命令:

gst-launch-1.0 videotestsrc pattern=ball ! video/x-raw,width=1280,height=720 ! videoconvert ! x264enc ! h264parse ! rtph264pay ! udpsink host=localhost port=7777

gst-launch-1.0 udpsrc port=7777 ! rtpbin ! rtph264depay ! decodebin ! videoconvert ! autovideosink

當你編寫使用的GStreamer管道,最簡單的方式來獲得幀到管道與appsrc應用。所以,你可能有這樣的事情:

const char* pipeline = "appsrc name=mysrc caps=video/x-raw,width=1280,height=720,format=RGB ! videoconvert ! x264enc ! h264parse ! rtph264pay ! udpsink host=localhost port=7777"; 

GError* error(NULL); 
GstElement* bin = gst_parse_bin_from_description(tail_pipe_s.c_str(), true, &error); 
if(bin == NULL || error != NULL) { 
     ... 
} 

GstElement* appsrc = gst_bin_get_by_name(GST_BIN(bin), "mysrc"); 

GstAppSrcCallbacks* appsrc_callbacks = (GstAppSrcCallbacks*)malloc(sizeof(GstAppSrcCallbacks)); 
memset(appsrc_callbacks, 0, sizeof(GstAppSrcCallbacks)); 
appsrc_callbacks->need_data = need_buffers; 
appsrc_callbacks->enough_data = enough_buffers; 
gst_app_src_set_callbacks(GST_APP_SRC(appsrc), appsrc_callbacks, (gpointer)your_data, free); 

gst_object_unref(appsrc); 

然後在後臺線程您對gst_app_src_push_buffer調用,這將涉及您的QImage讀取原始數據,並將其轉換爲一個GstBuffer。

OR

也許QT有我不知道的一些更簡單的方法。 :)