GStreamer —— 2.6、Windows下Qt加載GStreamer庫后運行 - “教程6:媒體格式和Pad功能“(附:完整源碼)

運行效果

在這里插入圖片描述

?

簡介

?????上一個教程演示了GUI 工具包集成(gtk)。本教程介紹媒體格式和Pad功能。Pad Capabilities 是 GStreamer 的一個基本元素,盡管大多數它們不可見,因為框架會處理它們 自然而然。這個有點理論性的教程展示了:

??????????? 什么是 Pad 功能。

??????????? 如何檢索它們。

??????????? 何時檢索它們。

??????????? 為什么你需要了解它們。

?

?????如前所述,Pads 允許信息進入和離開 一個元素。Pad 的功能(或簡稱 Caps),那么, 指定哪些類型的信息可以通過 Pad 傳輸。為 示例,“分辨率為 320x200 像素和 30 幀的 RGB 視頻 per second“或”16 bits per sample audio, 5.1 channels at 44100 samples” 每秒“,甚至是 MP3 或 H264 等壓縮格式。Pads 可以支持多種功能(例如,視頻接收器可以 支持不同類型的 RGB 或 YUV 格式的視頻)和功能可以是 指定為范圍 (例如,音頻接收器可以支持示例 速率為每秒 1 到 48000 個樣本)。但是,實際的 從 Pad 到 Pad 傳輸的信息必須只有一個 Well Specify 類型。通過稱為協商的過程,兩個鏈接的 Pad 就 一個通用類型,因此 Pad 的 Capabilities 變得固定(它們只有一個類型并且不包含范圍)。演練 下面的示例代碼應該清楚地說明了這一切。為了將兩個元素鏈接在一起,它們必須共享一個 common subset of Capabilities (否則它們不可能 相互理解)。這是 Capabilities 的主要目標。作為應用程序開發人員,您通常會通過鏈接 元素一起(如果使用 all-in-all 元素,則程度較小 喜歡 )。在這種情況下,您需要知道 Pad Caps(因為它們 都熟悉地引用了)的元素,或者至少知道什么 它們是 GStreamer 拒絕將兩個元素與協商聯系起來的時候 錯誤。

?

GStreamer相關運行庫
INCLUDEPATH += D:/Software/GStreamer/1.0/mingw_x86_64/include/gstreamer-1.0/gst
INCLUDEPATH += D:/Software/GStreamer/1.0/mingw_x86_64/include
INCLUDEPATH += D:/Software/GStreamer/1.0/mingw_x86_64/include/gstreamer-1.0
INCLUDEPATH += D:/Software/GStreamer/1.0/mingw_x86_64/include/glib-2.0
INCLUDEPATH += D:/Software/GStreamer/1.0/mingw_x86_64/lib/glib-2.0/includeLIBS += D:/Software/GStreamer/1.0/mingw_x86_64/lib/gstreamer-1.0.lib
LIBS += D:/Software/GStreamer/1.0/mingw_x86_64/lib/glib-2.0.lib
LIBS += D:/Software/GStreamer/1.0/mingw_x86_64/lib/gobject-2.0.lib

?

完整源碼
#include <gst/gst.h>/* Functions below print the Capabilities in a human-friendly format */
static gboolean print_field (GQuark field, const GValue * value, gpointer pfx)
{gchar *str = gst_value_serialize (value);g_print ("%s  %15s: %s\n", (gchar *) pfx, g_quark_to_string (field), str);g_free (str);return TRUE;
}static void print_caps (const GstCaps * caps, const gchar * pfx)
{guint i;g_return_if_fail (caps != NULL);if (gst_caps_is_any (caps)){g_print ("%sANY\n", pfx);return;}if (gst_caps_is_empty (caps)){g_print ("%sEMPTY\n", pfx);return;}for (i = 0; i < gst_caps_get_size (caps); i++){GstStructure *structure = gst_caps_get_structure (caps, i);g_print ("%s%s\n", pfx, gst_structure_get_name (structure));gst_structure_foreach (structure, print_field, (gpointer) pfx);}
}/* 打印有關pod模板的信息,包括其功能 */
static void print_pad_templates_information (GstElementFactory * factory)
{g_print ("Pad Templates for %s:\n", gst_element_factory_get_longname (factory));if (!gst_element_factory_get_num_pad_templates (factory)) { g_print ("  none\n"); return; }GstStaticPadTemplate *padtemplate;const GList *pads = gst_element_factory_get_static_pad_templates (factory);while (pads){padtemplate = (GstStaticPadTemplate*)pads->data;pads = g_list_next (pads);if (padtemplate->direction == GST_PAD_SRC)g_print ("  SRC template: '%s'\n", padtemplate->name_template);else if (padtemplate->direction == GST_PAD_SINK)g_print ("  SINK template: '%s'\n", padtemplate->name_template);elseg_print ("  UNKNOWN!!! template: '%s'\n", padtemplate->name_template);if (padtemplate->presence == GST_PAD_ALWAYS)g_print ("    Availability: Always\n");else if (padtemplate->presence == GST_PAD_SOMETIMES)g_print ("    Availability: Sometimes\n");else if (padtemplate->presence == GST_PAD_REQUEST)g_print ("    Availability: On request\n");elseg_print ("    Availability: UNKNOWN!!!\n");if (padtemplate->static_caps.string){GstCaps *caps;g_print ("    Capabilities:\n");caps = gst_static_caps_get (&padtemplate->static_caps);print_caps (caps, "      ");gst_caps_unref (caps);}g_print ("\n");}
}/* 顯示給定元素中請求pod的能力 */
static void print_pad_capabilities (GstElement *element, gchar *pad_name)
{/* 取回pad */GstPad *pad = gst_element_get_static_pad (element, pad_name);if (!pad) { g_printerr ("Could not retrieve pad '%s'\n", pad_name); return; }/* 獲取當前在 pad 上配置的具有最后一個 GST_EVENT_CAPS 事件的功能。(如果協商尚未完成,則檢索可接受的上限) */GstCaps *caps = gst_pad_get_current_caps (pad);if (!caps){caps = gst_pad_query_caps (pad, NULL);}/* 打印后釋放 */g_print ("Caps for the %s pad:\n", pad_name);print_caps (caps, "      ");gst_caps_unref (caps);gst_object_unref (pad);
}int main(int argc, char *argv[])
{/* 初始化GStreamer */gst_init (&argc, &argv);/* 創建元素工廠 */GstElementFactory *source_factory = gst_element_factory_find ("audiotestsrc");GstElementFactory *sink_factory = gst_element_factory_find ("autoaudiosink");if (!source_factory || !sink_factory) { g_printerr ("Not all element factories could be created.\n"); return -1; }/* 打印這些工廠的pod模板信息 */print_pad_templates_information (source_factory);print_pad_templates_information (sink_factory);/* 要求工廠實例化實際元素 */GstElement *source = gst_element_factory_create (source_factory, "source");GstElement *sink = gst_element_factory_create (sink_factory, "sink");/* 創建空管道 */GstElement *pipeline = gst_pipeline_new ("test-pipeline");if (!pipeline || !source || !sink) { g_printerr ("Not all elements could be created.\n"); return -1; }/* 構建管道 */gst_bin_add_many (GST_BIN (pipeline), source, sink, NULL);if (gst_element_link (source, sink) != TRUE) { g_printerr ("Elements could not be linked.\n"); gst_object_unref (pipeline); return -1; }/* 打印初始能力(處于NULL狀態) */g_print ("In NULL state:\n");print_pad_capabilities (sink, (gchar *)"sink");/* 開始播放 */GstStateChangeReturn ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);if (ret == GST_STATE_CHANGE_FAILURE) { g_printerr ("Unable to set the pipeline to the playing state (check the bus for error messages).\n"); }gboolean terminate = FALSE;GstMessage *msg;/* 等待錯誤、EOS或狀態更改 */GstBus *bus = gst_element_get_bus (pipeline);do{// 等待獲取符合條件的消息msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, (GstMessageType)(GST_MESSAGE_ERROR | GST_MESSAGE_EOS | GST_MESSAGE_STATE_CHANGED));/* 解析消息 */if (msg != NULL){GError *err;gchar *debug_info;switch (GST_MESSAGE_TYPE (msg)){case GST_MESSAGE_ERROR:gst_message_parse_error (msg, &err, &debug_info);g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message);g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none");g_clear_error (&err);g_free (debug_info);terminate = TRUE; break;case GST_MESSAGE_EOS:g_print ("End-Of-Stream reached.\n");terminate = TRUE; break;case GST_MESSAGE_STATE_CHANGED:/* 我們只對來自管道的狀態更改消息感興趣 */if (GST_MESSAGE_SRC (msg) == GST_OBJECT (pipeline)){GstState old_state, new_state, pending_state;gst_message_parse_state_changed (msg, &old_state, &new_state, &pending_state);g_print ("\nPipeline state changed from %s to %s:\n", gst_element_state_get_name (old_state), gst_element_state_get_name (new_state));/* 打印sink元素的當前功能 */print_pad_capabilities (sink, (gchar *)("sink"));}break;default:/* 通常不會運行到這里 */g_printerr ("Unexpected message received.\n"); break;}gst_message_unref (msg);}} while (!terminate);/* 釋放資源 */gst_object_unref (bus);gst_element_set_state (pipeline, GST_STATE_NULL);gst_object_unref (pipeline);gst_object_unref (source_factory);gst_object_unref (sink_factory);return 0;
}

?

關注

筆者 - jxd

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/72960.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/72960.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/72960.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

【前綴和與差分 C/C++】洛谷 P8218 求區間和

2025 - 03 - 09 - 第 72 篇 Author: 鄭龍浩 / 仟濹 【前綴和與差分 C/C】 文章目錄 洛谷 P8218 求區間和題目描述輸入格式輸出格式輸入輸出樣例 #1輸入 #1輸出 #1 說明/提示思路代碼 洛谷 P8218 求區間和 題目描述 給定 n n n 個正整數組成的數列 a 1 , a 2 , ? , a n a_…

初識Bert

在學習Bert之前我們先了解“遞歸神經網絡&#xff08;RNN Recurrent neural network)” 和 “長短期記憶&#xff08;LSTM Long short-term memory)” 我們如果僅僅識別每個字的含義&#xff0c;那么在一句話中沒有相同的字還是可以的但是如果一句話中有相同的字&#xff0c;那…

clickhouse源碼分析

《ClickHouse源碼分析》 當我們談論數據庫時&#xff0c;ClickHouse是一個不容忽視的名字。它是一個用于聯機分析處理&#xff08;OLAP&#xff09;的列式數據庫管理系統&#xff08;DBMS&#xff09;&#xff0c;以其快速的數據查詢能力而聞名。對于想要深入了解這個高效工具…

[網絡爬蟲] 動態網頁抓取 — Selenium 元素定位

&#x1f31f;想系統化學習爬蟲技術&#xff1f;看看這個&#xff1a;[數據抓取] Python 網絡爬蟲 - 學習手冊-CSDN博客 在使用 Selenium 時&#xff0c;往往需要先定位到指定元素&#xff0c;然后再執行相應的操作。例如&#xff0c;再向文本輸入框中輸入文字之前&#xff0c;…

ArcGIS操作:15 計算點的經緯度,并添加到屬性表

注意&#xff1a;需要轉化為地理坐標系 1、打開屬性表&#xff0c;添加字段 2、計算字段&#xff08;以計算緯度為例 !Shape!.centroid.Y ) 3、效果

[項目]基于FreeRTOS的STM32四軸飛行器: 七.遙控器按鍵

基于FreeRTOS的STM32四軸飛行器: 七.遙控器 一.遙控器按鍵搖桿功能說明二.搖桿和按鍵的配置三.按鍵掃描 一.遙控器按鍵搖桿功能說明 兩個手柄四個ADC。 左側手柄&#xff1a; 前后推為飛控油門&#xff0c;左右推為控制飛機偏航角。 右側手柄&#xff1a; 控制飛機飛行方向&a…

Redis 內存淘汰策略深度解析

Redis 作為高性能的內存數據庫&#xff0c;其內存資源的高效管理直接關系到系統的穩定性和性能。當 Redis 的內存使用達到配置的最大值&#xff08;maxmemory&#xff09;時&#xff0c;新的寫入操作將觸發內存淘汰機制&#xff08;Eviction Policy&#xff09;&#xff0c;以釋…

【面試】Java 集合

集合 1、常見的集合有哪些2、說說 List、Set、Queue、Map 四者的區別3、Collection 和 Collections 有什么區別4、Comparable 和 Comparator 的區別5、ArrayList 和 LinkedList 的區別是什么6、ArrayList 和 Vector 的區別是什么7、ArrayList 和 Vector 的擴容機制8、CopyOnWri…

【c++】平移字符串

說明 實現字符串的左移與右移 示例代碼 #include <iostream> #include <string> using namespace std;int main() {string str1 "12345";//左移2位string str2 str1.substr(2) str1.substr(0, 2);cout << str2 << endl;//右移2位&…

密碼學(終極版)

加密 & 解密 備注&#xff1a;密碼學領域不存在完全不能破解的密碼&#xff0c;但是如果一個密碼需要很久很久&#xff0c;例如一萬年才能破解&#xff0c;就認為這個密碼是安全的了。 對稱加密 非對稱加密 公鑰加密、私鑰解密 私鑰簽名、公鑰認證 非對稱的底層原理是…

FreeRTOS任務狀態查詢

一.任務相關API vTaskList&#xff08;&#xff09;&#xff0c;創建一個表格描述每個任務的詳細信息 char biaoge[1000]; //定義一個緩存 vTaskList(biaoge); //將表格存到這緩存中 printf("%s /r/n",biaoge); 1.uxTaskPriorityGet&#xff08;&#xf…

yolov5代碼詳解--3.python代碼腳本

三、val.py val.py的主要作用是對訓練好的模型進行驗證&#xff08;或評估&#xff09;。具體來說&#xff0c;它用于在指定的驗證集上評估模型的性能&#xff0c;計算各項評估指標&#xff0c;并輸出結果。val.py通常在模型訓練完成后運行&#xff0c;用于驗證模型的檢測精度、…

無人機應用探索:玻纖增強復合材料的疲勞性能研究

隨著無人機技術的快速發展&#xff0c;輕量化已成為其結構設計的核心需求。玻纖增強復合材料憑借高強度、低密度和優異的耐環境性能&#xff0c;成為無人機機身、旋翼支架等關鍵部件的理想選擇。然而&#xff0c;無人機在服役過程中需應對復雜多變的環境&#xff1a;高空飛行時…

Python SQLite3 保姆級教程:從零開始學數據庫操作

Python SQLite3 保姆級教程&#xff1a;從零開始學數據庫操作 本文適合純新手&#xff01;無需任何數據庫基礎&#xff0c;跟著步驟操作即可掌握 SQLite3 的核心用法。 目標&#xff1a;讓你像用記事本一樣輕松操作數據庫&#xff01; 目錄 什么是 SQLite3&#xff1f;環境準…

C語言中的整數類型(short,int,long和long long)

整數是編程中最常見的一種數據類型&#xff0c;C語言提供了多種整數類型&#xff0c;包括 short、int、long 和 long long&#xff0c;它們的主要區別在于存儲范圍和內存占用的大小。 本節將詳細講解這些整數類型的定義、特性、使用場景以及注意事項&#xff0c;幫助你全面理解…

使用jcodec庫,訪問網絡視頻提取封面圖片上傳至oss

注釋部分為FFmpeg&#xff08;確實方便但依賴太大&#xff0c;不想用&#xff09; package com.zuodou.upload;import com.aliyun.oss.OSS; import com.aliyun.oss.model.ObjectMetadata; import com.aliyun.oss.model.PutObjectRequest; import com.zuodou.oss.OssProperties;…

游戲引擎學習第147天

倉庫:https://gitee.com/mrxiao_com/2d_game_3 上一集回顧 具體來說&#xff0c;我們通過隱式計算來解決問題&#xff0c;而不是像數字微分分析器那樣逐步增加數據。我們已經涵蓋了這個部分&#xff0c;并計劃繼續處理音量問題。不過&#xff0c;實際上我們現在不需要繼續處理…

使用Dockerfile打包java項目生成鏡像部署到Linux_java項目打docker鏡像的dockerfile

比起容器、鏡像來說&#xff0c;Dockerfile 非常普通&#xff0c;它就是一個純文本&#xff0c;里面記錄了一系列的構建指令&#xff0c;比如選擇基礎鏡像、拷貝文件、運行腳本等等&#xff0c;每個指令都會生成一個 Layer&#xff0c;而 Docker 順序執行這個文件里的所有步驟&…

Linux -- 磁盤結構、文件系統ext2

一、磁盤 1.磁盤的物理結構 2.磁盤的存儲結構 盤片&#xff1a;是機械硬盤存儲數據的主要介質&#xff0c;一般由鋁合金或玻璃等材料制成&#xff0c;表面涂有一層磁性材料。數據通過磁頭在盤片的磁性涂層上進行磁化來記錄&#xff0c;磁化的不同方向代表二進制的 0 和 1。盤面…

標量、向量、矩陣與張量:從維度理解數據結構的層次

在數學和計算機科學中,維度描述了數據結構的復雜性,而標量、向量、矩陣、張量則是不同維度的數據表示形式。它們的關系可以理解為從簡單到復雜的擴展,以下是詳細解析: 1. 標量(Scalar):0維數據 定義:單個數值,沒有方向,只有大小。 維度:0維(無索引)。 示例: 溫度…