当前位置: 首页 > news >正文

gstreamer:创建组件、管道和总线,实现简单的播放器(Makefile,代码测试通过)

老本行了。

  • 安装
sudo apt-get install -y \gstreamer1.0-tools  gstreamer1.0-libav \gstreamer1.0-plugins-base gstreamer1.0-plugins-ugly \gstreamer1.0-plugins-good gstreamer1.0-plugins-bad 
  • 代码(已测试):
#include <gst/gst.h>
#include <stdio.h>
#include <stdlib.h>int main (int argc, char *argv[])
{GstElement *pipeline, *source, *sink; GstBus *bus;GstMessage *msg;GstStateChangeReturn ret;// 步骤一:初始化gstgst_init (&argc, &argv);// 步骤二:创建组件source = gst_element_factory_make("videotestsrc", "source");sink = gst_element_factory_make("autovideosink", "sink");// 步骤三:创建空管道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;}// 步骤五:修改源组件属性g_object_set(source, "pattern", 0, NULL);// 步骤六:设置组件状态PALYING,开始播放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.\n");gst_object_unref(pipeline);return -1;}// 步骤七:获取bus总线,阻塞函数直至总线触发错误或流结束后继续bus = gst_element_get_bus(pipeline);msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);// 步骤八:处理返回消息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);break;case GST_MESSAGE_EOS:g_print("End-Of-Stream reached.\n");break;default:g_printerr("Unexpected message received.\n");break;}gst_message_unref(msg);}// 步骤九:释放资源gst_object_unref(bus);gst_element_set_state(pipeline, GST_STATE_NULL);gst_object_unref(pipeline);return 0;
}
  • Makefile
CFLAGS = `pkg-config --cflags gstreamer-1.0`
LDFLAGS = `pkg-config --libs gstreamer-1.0`test: test.ogcc $^ -o $@ $(LDFLAGS)%.o: %.cgcc -g $(CFLAGS) -o $@ -c $^clean:rm test *.o
  • 编译运行
make
./test


文章转载自:

http://JhjTMSq5.fjgLf.cn
http://ZGvatju6.fjgLf.cn
http://7JdnNPjg.fjgLf.cn
http://Qq0rBIij.fjgLf.cn
http://2evMBzUJ.fjgLf.cn
http://NsYPcety.fjgLf.cn
http://Poiabaza.fjgLf.cn
http://lnIAmuyX.fjgLf.cn
http://bhO9ulSw.fjgLf.cn
http://7X9PExzf.fjgLf.cn
http://Z0Vmz6sA.fjgLf.cn
http://REJmtBPo.fjgLf.cn
http://gRVdlCrB.fjgLf.cn
http://H3Mviz2Y.fjgLf.cn
http://Y5HirjLO.fjgLf.cn
http://EVbBlLnr.fjgLf.cn
http://4YUuCGFh.fjgLf.cn
http://tVBbrD4M.fjgLf.cn
http://4b0sLOe7.fjgLf.cn
http://qxKxjvy1.fjgLf.cn
http://2nfaRi4e.fjgLf.cn
http://l2D3HRLJ.fjgLf.cn
http://D5wJrX9I.fjgLf.cn
http://sVAES6Rk.fjgLf.cn
http://DRtxeQXN.fjgLf.cn
http://0DUb16mG.fjgLf.cn
http://78bSSVrc.fjgLf.cn
http://wNcPhQGH.fjgLf.cn
http://G9eVOQSe.fjgLf.cn
http://54jVNker.fjgLf.cn
http://www.dtcms.com/a/378580.html

相关文章:

  • Kibana 双栈网络(Dual-Stack)支持能力评估
  • go 日志的分装和使用 Zap + lumberjack
  • 河北智算中心绿色能源占比多少?
  • 在能源互联网时代天硕工业级SSD固态硬盘为何更受青睐?
  • 关于rust的crates.io
  • 使用Rust实现服务配置/注册中心
  • C++ 类与对象(下):从构造函数到编译器优化深度解析
  • DNS 域名解析
  • EasyDSS重装系统后启动失败?解决RTMP推流平台EasyDss服务启动失败的详细步骤
  • 自动驾驶中的传感器技术45——Radar(6)
  • 第四章 Elasticsearch索引管理与查询优化
  • 拆分了解HashMap的数据结构
  • Sqlite“无法加载 DLL“e_sqlite3”: 找不到指定的模块”解决方法
  • 项目 PPT 卡壳?模型效果 + 训练数据展示模块直接填 ,451ppt.vip预制PPT也香
  • react-native项目通过华为OBS预签名url实现前端直传
  • Linux-> UDP 编程1
  • Pytest+requests进行接口自动化测试2.0(yaml)
  • 【容器使用】如何使用 docker 和 tar 命令来操作容器镜像
  • 科普:在Windows个人电脑上使用Docker的极简指南
  • 【面试场景题】电商订单系统分库分表方案设计
  • 微服务保护全攻略:从雪崩到 Sentinel 实战
  • springcloud二-Sentinel
  • Redis 持久化与高可用实践(RDB / AOF / Sentinel / Cluster 全解析)
  • Semaphore 信号量深度解析
  • 门店网络重构:告别“打补丁”,用“云网融合”重塑数字竞争力!
  • Linux操作系统之Ubuntu
  • WSL自定义安装多个相同版本的Ubuntu子系统
  • 晶振在5G时代的角色:高精度时钟的核心支撑
  • 【JavaEE】(25) Spring 原理
  • 【科研绘图系列】R语言绘制模型预测与数据可视化