官网链接:https://gstreamer.freedesktop.org/download/
两个都要下载。安装的时候,在custom选择安装路径。然后返回上一步选择complete完全安装,两个安装方式一样。
将 D:\gstreamer\1.0\msvc_x86_64\bin 添加至环境变量
在vs工程中使用:
D:\gstreamer\1.0\msvc_x86_64\include\gstreamer-1.0
D:\gstreamer\1.0\msvc_x86_64\include\glib-2.0
D:\gstreamer\1.0\msvc_x86_64\include\libxml2
D:\gstreamer\1.0\msvc_x86_64\include
D:\gstreamer\1.0\msvc_x86_64\lib
gobject-2.0.lib;glib-2.0.lib;gstreamer-1.0.lib
path=%path%;F:\gstreamer\1.0\x86\bin
首先更新系统的软件包
sudo apt-get update
sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 gstreamer1.0-pulseaudio
安装完成后,检查GStreamer是否安装正确。
gst-inspect-1.0 --version
显示版本说明成功安装。
gst-launch-1.0.exe -v playbin uri=file:/C:\\Users\\26366\\Desktop\\宣传片成片.mp4
输出视频即为成功。
// GstreamerHelloWorld.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 // #include #include #include int main(int argc, char* argv[]) { GstElement* pipeline; GstElement* source, * filter, * sink; //init gst_init(&argc, &argv); //creat pipeline pipeline = gst_pipeline_new("my-pipline"); create elements source = gst_element_factory_make("fakesrc", "source"); filter = gst_element_factory_make("identity", "filter"); sink = gst_element_factory_make("fakesink", "sink"); //将元组添加到管道中 gst_bin_add_many(GST_BIN(pipeline), source, filter, sink, NULL); //连接 if (!gst_element_link_many(source, filter, sink, NULL)) { g_warning("failed to link elements\n"); std::cout << "failed to link elements!\n"; } else { std::cout << "Hello GStreamer!\n"; } /*在链接不同的组件之前,你需要确保这些组件都被加在同一个箱柜中, 因为将一个组件加载到一个箱柜中会破坏该组件已存在的一些链接关系。 同时,你不能直接链接不在同一箱柜或管道中的组件。*/ return 0; }
输出Hello GStreamer!
即为配置成功。
编码:
gst-launch-1.0 filesrc location=C:\\Users\\26366\\Desktop\\宣传片成片.mp4 ! qtdemux ! avdec_h264 ! x264enc ! udpsink host=192.168.0.105 port=5600
对应解码:
gst-launch-1.0 udpsrc port=5600 ! h264parse ! avdec_h264 ! videoconvert ! autovideosink
c++解码:
// GstreamerHelloWorld.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 // #include #include #include static GstElement* pipeline = nullptr; static GstBus* bus = nullptr; static GstMessage* msg = nullptr; // 回调函数,用于处理 GStreamer 消息 static gboolean on_message(GstBus* bus, GstMessage* msg, gpointer data) { 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); g_main_loop_quit((GMainLoop*)data); break; default: break; } return TRUE; } int main(int argc, char* argv[]) { gst_init(&argc, &argv); gst_debug_set_active(TRUE); gst_debug_set_default_threshold(GST_LEVEL_DEBUG); GMainLoop* loop = g_main_loop_new(NULL, FALSE); // 创建 GStreamer 管道 pipeline = gst_parse_launch("udpsrc port=5600 ! h264parse ! avdec_h264 ! videoconvert ! autovideosink", NULL); bus = gst_element_get_bus(pipeline); gst_bus_add_watch(bus, on_message, loop); gst_object_unref(bus); // 开始播放 gst_element_set_state(pipeline, GST_STATE_PLAYING); // 运行主循环 g_print("Playing stream...\n"); g_main_loop_run(loop); // 清理 gst_element_set_state(pipeline, GST_STATE_NULL); gst_object_unref(pipeline); g_main_loop_unref(loop); return 0; }
编码
gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! 'video/x-raw,format=(string)NV12,width=640,height=480,framerate=(fraction)30/1' ! queue ! x264enc ! udpsink host=127.0.0.1 port=5000 sync=false
解码:
gst-launch-1.0 udpsrc port=5000 caps='application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264' \ ! rtpjitterbuffer latency=200 \ ! rtspsrc ! avdec_h264 ! videoconvert ! autovideosink
参数解释:
gst-launch-1.0 udpsrc port=14556 caps=“application/x-rtp, media=(string)video, clock-rate=(int)90000, enc
oding-name=(string)H264” ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! autovideosink