gstreamer中appsrc可以进行填充数据,所以经常用到appsrc原件到各种sink,下面介绍一个从appsrc到rtmpsink的过程
pipeline = gst_pipeline_new ("pipeline");
// g_object_get (pipeline, "flags",GST_ , NULL);
appsrc = gst_element_factory_make ("appsrc", "source");
conv = gst_element_factory_make ("videoconvert", "conv");
h264enc = gst_element_factory_make("x264enc","h264enc");
flvmux = gst_element_factory_make("flvmux","flvmux");
// g_object_set(flvmux,"streamable",true,NULL);
videosink = gst_element_factory_make ("rtmpsink", "videosink");
g_object_set(G_OBJECT(videosink),"location",location.c_str(),NULL);
/* setup */
g_object_set (G_OBJECT (appsrc), "caps",
gst_caps_new_simple ("video/x-raw",
"format", G_TYPE_STRING, "BGR",
"width", G_TYPE_INT,width,
"height", G_TYPE_INT, height,
"framerate", GST_TYPE_FRACTION, 25, 1,
NULL), NULL);
gst_bin_add_many (GST_BIN (pipeline), appsrc,conv,h264enc,flvmux,videosink,NULL);
gst_element_link_many (appsrc,conv,h264enc,flvmux,videosink,NULL);
中间主要经过三个原件,videoconvert 是颜色空间转换,x264enc是编码成h264,flvmux是编码成flv格式,流向其他的sink原件一般都会用到videoconvert原件,后面的编码的原件根据你需要的格式进行变换。