我正在尝试用gstreamer-0.10实际创建以下链。
gst-launch filesrc location=<file>.mkv ! decodebin ! ffenc_mpeg4 bitrate=5000000 ! rtpmp4vpay mtu=1400 pt=96 ssrc=0 timestamp-offset=0 seqnum-offset=0 send-config=true ! udpsink host=127.0.0.1 port=5000
以下是代码:
#include <gst/gst.h>
int
main (int argc,
char *argv[])
{
GstElement* pipeline;
GstElement* source;
GstElement* decodebin;
GstElement* encoder;
GstElement* rtp;
GstElement* udpsink;
/* init */
gst_init (&argc, &argv);
/* create pipeline */
pipeline = gst_pipeline_new ("my-pipeline");
/* create elements */
source = gst_element_factory_make ("filesrc", "source");
g_object_set (G_OBJECT (source), "location", argv[1], NULL);
decodebin = gst_element_factory_make ("decodebin", "decoder");
encoder = gst_element_factory_make ("ffenc_mpeg4", "encoder");
g_object_set (G_OBJECT (encoder), "bitrate", "5000000", NULL);
rtp = gst_element_factory_make ("rtpmp4vpay", "rtp");
g_object_set (G_OBJECT (rtp), "mtu", "1400", NULL);
g_object_set (G_OBJECT (rtp), "pt", 96, NULL);
g_object_set (G_OBJECT (rtp), "ssrc", "0", NULL);
g_object_set (G_OBJECT (rtp), "timestamp-offset", "0", NULL);
g_object_set (G_OBJECT (rtp), "seqnum-offset", 0, NULL);
g_object_set (G_OBJECT (rtp), "send-config", true, NULL);
udpsink = gst_element_factory_make ("udpsink", "udp");
g_object_set (G_OBJECT (udpsink), "host", "127.0.0.1", NULL);
g_object_set (G_OBJECT (udpsink), "port", 5000, NULL);
// /* must add elements to pipeline before linking them */
gst_bin_add_many (GST_BIN (pipeline), source, decodebin, encoder, rtp, udpsink, NULL);
/* link */
if (!gst_element_link_many (source, decodebin, encoder, rtp, udpsink, NULL)) {
g_warning ("Failed to link elements!");
}
}
虽然这与gst-launch链完全匹配,但我在gst_element_link_many调用中遇到以下错误。
0:00:03.025847872 28265 0x611400 INFO GST_PLUGIN_LOADING gstplugin.c:859:gst_plugin_load_file: plugin "/usr/lib64/gstreamer-0.10/libgstudp.so" loaded
0:00:03.025912744 28265 0x611400 INFO GST_ELEMENT_FACTORY gstelementfactory.c:374:gst_element_factory_create: creating element "udpsink" named "udp"
0:00:03.026163748 28265 0x611400 INFO GST_ELEMENT_PADS gstelement.c:728:gst_element_add_pad:<GstBaseSink@0x82b9e0> adding pad 'sink'
0:00:04.824498407 28265 0x611400 INFO GST_ELEMENT_PADS gstutils.c:1698:gst_element_link_pads_full: trying to link element source:(any) to element decoder:(any)
0:00:04.824604374 28265 0x611400 INFO GST_PADS gstutils.c:1032:gst_pad_check_link: trying to link source:src and decoder:sink
0:00:04.824676367 28265 0x611400 INFO GST_PADS gstutils.c:1596:prepare_link_maybe_ghosting: source and decoder in same bin, no need for ghost pads
0:00:04.824725877 28265 0x611400 INFO GST_PADS gstpad.c:1978:gst_pad_link_prepare: trying to link source:src and decoder:sink
0:00:04.824786544 28265 0x611400 INFO GST_PADS gstpad.c:2161:gst_pad_link_full: linked source:src and decoder:sink, successful
0:00:04.824863468 28265 0x611400 INFO GST_ELEMENT_PADS gstutils.c:1698:gst_element_link_pads_full: trying to link element decoder:(any) to element encoder:(any)
0:00:04.824989178 28265 0x611400 INFO GST_ELEMENT_PADS gstelement.c:972:gst_element_get_static_pad: no such pad 'src%d' in element "decoder"
0:00:04.825051308 28265 0x611400 INFO GST_ELEMENT_PADS gstutils.c:1216:gst_element_get_compatible_pad:<decoder> Could not find a compatible pad to link to encoder:sink
我做错了什么?我不能像编程一样使用解码箱吗?
答案 0 :(得分:0)
bin文档,发现解码器的src并不总是pad并且有时是pad。同样可以通过日志存在来观察。