GStreamer 基本用法
文章目录
一、简介
GStreamer本质上只是一个多媒体应用框架,具体的多媒体播放功能由插件来完成。
GStreamer插件分属4个不同的插件集:
- gst-plugins-base。这类插件格式规范,维护的也很好。
- gst-plugins-good。这类插件有高质量的代码(但格式未必规范),而且许可证也符合要求。
- gst-plugins-ugly。这类插件有高质量的代码,但许可证方面有问题。
- gst-plugins-bad。这类插件尚不成熟,需要更多文档、测试和应用
二、安装软件包
1、DeepIn 下安装命令
sudo apt-get install libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-pulseaudio
三、系统测试
1、播放测试
# 系统环境正常时可听到声音
$ gst-launch-1.0 audiotestsrc ! pulsesink
2、播放音视频文件
# 方式1(验证可行)
gst-launch-1.0 playbin uri=file:///path/to/song.mp3
# 方式2(未找到命令)
gst-play-1.0 song.mp3
3、查看插件
# 查看所有插件
$ gst-inspect-1.0
# 查看单个插件
$ gst-inspect-1.0 volume
四、简单示例程序
1、程序代码
player.c
#include <gst/gst.h>
int
main (int argc, char *argv[])
{
GstElement *pipeline;
GstBus *bus;
GstMessage *msg;
/* Initialize GStreamer */
gst_init (&argc, &argv);
/* Build the pipeline */
pipeline =
gst_parse_launch
("playbin uri=playbin uri=http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4",
NULL);
/* 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,
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 0;
}
2、编译代码
方式一:gcc 编译
gcc player.c -o player `pkg-config --cflags --libs gstreamer-1.0`
方式二:cmake 编译(CMakeLists.txt)
# 所需 cmake 工具的最低版本
cmake_minimum_required(VERSION 2.6)
# 工程名称
project(player)
# 生成可执行程序
add_executable(${PROJECT_NAME} player.c)
# 查找pkg-config依赖库
find_package(PkgConfig)
pkg_check_modules(GST REQUIRED gstreamer-1.0>=1.8 gstreamer-app-1.0>=1.8)
# 引用 gstreamer 头文件
target_include_directories(${PROJECT_NAME} PUBLIC ${GST_INCLUDE_DIRS})
# 链接 gstreamer 库文件
target_link_libraries(${PROJECT_NAME} ${GST_LIBRARIES})
3、备用资源
# 视频
http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4
# 音频
http://sc1.111ttt.cn:8281/mp3/a613e7c304354059b8e3cd65db30bb81/2018/1/03/13/396131213056.mp3
五、OpenWrt常见问题
-
Could not determine type of stream.# 勾选此选项 Multimedia/gstreamer1-plugins-base/ GStreamer playback module -
pipeline could not be constructed: no element "playbin".Multimedia/gstreamer1-plugins-base/ GStreamer playback module -
Could not determine type of stream.# 勾选此选项 Multimedia/gstreamer1-plugins-base/ GStreamer typefindfunctions module -
GstID3Demux:id3demux0: Internal data stream error.# 勾选此选项 Multimedia/gstreamer1-plugins-good/ GStreamer id3demux module GStreamer audioparsers module -
GstPlaySink:playsink: No volume control found# 勾选此选项 Multimedia/gstreamer1-plugins-base/ GStreamer volume module -
GstURIDecodeBin:uridecodebin0: No decoder available for type 'audio/x-wav'.# 勾选此选项 Multimedia/gstreamer1-plugins-good/ GStreamer waveparse module -
The autoaudiosink element is missing.# 勾选此选项 Multimedia/gstreamer1-plugins-good/ GStreamer autodetect module
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论