我已多次运行此代码,试图弄清楚它为什么不起作用。我从IP摄像头获取信息。该程序遍历每个程序,但它无法播放。最初的开始是
gst-launch-1.0 udpsrc address = [ip] port = [port]! application / x-rtp,clock-rate = 10,media = video! rtpmp4vdepay! decodebin! d3dvideosink
我使用了gst_parse_launch()并且可以工作,但由于某种原因不能玩。我一直在想弄清楚我做错了什么。
convertString.h只是将Char *端口抛出到将字符串转换为int的方法。我不想使用gst_parse_launch()因为我想用它来覆盖应用程序。
有人知道我错过了什么吗?
#include <gst/gst.h>
#include <gst/video/videooverlay.h>
#include <stdio.h>
#include <string.h>
#include "convertString.h"
#include <Windows.h>
#include <direct.h>
void nullvalues(GstElement*,GstBus*,GstMessage*);
int main(int argc, char *argv[])
{
GstElement *pipeline,*sink,*source, *rtppay,*filter1,*decodebin;
GstCaps *filtercaps;
GstBus *bus;
GstMessage *msg;
gboolean link_ok = FALSE;
GstStateChangeReturn ret;
char *ip_address = [ip];
char *port = [port];
char *window_handle = "";
char *title = "";
int wid;
char *sourcestring = "";
#define url_size 28
char url[url_size];
strcpy_s(url,url_size,"");
while ((argc > 1) && (argv[1][0] == '-'))
{
switch (argv[1][1])
{
case 'i':
ip_address = &argv[1][2];
break;
case 'p':
port = &argv[1][2];
break;
case 'w':
window_handle = &argv[1][2];
break;
case 't':
title = &argv[1][2];
break;
}
++argv;
--argc;
}
strcat_s(url,url_size,"udp://");
strcat_s(url,url_size,ip_address);
strcat_s(url,url_size,":");
strcat_s(url,url_size,port);
/* Initialize GStreamer */
gst_init(&argc,&argv);
/* Build Pipeline */
if(title != "")
pipeline = gst_pipeline_new (title);
else
pipeline = gst_pipeline_new("My pipeline");
source = gst_element_factory_make ("udpsrc","source");
filter1 = gst_element_factory_make("capsfilter","filter");
rtppay = gst_element_factory_make( "rtpmp4vdepay", "depayl");
decodebin = gst_element_factory_make ("decodebin","decode");
sink = gst_element_factory_make ("d3dvideosink", "sink");
gst_bin_add_many (GST_BIN (pipeline),source,filter1,rtppay,decodebin,sink, NULL);
filtercaps = gst_caps_new_simple("application/x-rtp","clock-rate",G_TYPE_INT,10,"media",G_TYPE_STRING,"video",NULL);
g_object_set(GST_OBJECT(source),"address",ip_address,NULL);
g_object_set(GST_OBJECT(source),"port",StringToInt(port),NULL);
g_object_set (G_OBJECT (filter1), "caps",filtercaps,NULL);
gst_caps_unref(filtercaps);
link_ok = gst_element_link_many(source,filter1,rtppay,decodebin,sink);
if(!link_ok)
printf("%s\nNOPE\n");
/* Start playing */
ret = gst_element_set_state (pipeline, GST_STATE_READY);
if(ret == GST_STATE_CHANGE_FAILURE)
printf("\nFailed\n");
else if(ret == GST_STATE_CHANGE_SUCCESS)
printf("\nSuccess\n");
/* 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);
printf("\nDone\n");
return 0;
}
答案 0 :(得分:0)
如果gst_parse_launch()正在为你工作,我建议你使用它。您仍然可以在应用程序中覆盖d3dvideosink。
只需在管道定义中为d3dvideosink元素使用唯一名称(例如“d3dvideosink name = myvideosink”)。
通过gst_bin_get_by_name()从管道获取d3dvideosink的句柄。此句柄也应支持GstVideoOverlay界面,您可以通过gst_video_overlay_set_window_handle()设置叠加。
答案 1 :(得分:0)
使用它将解决问题 Gstreamer Decodebin