在管道中添加 clockoverlay 并正确使用 capsfilter

add clockoverlay in pipeline & correct use of capsfilter

gst-launch-0.10 v4l2src device=/dev/video0 ! video/x-raw-yuv,format=\(fourcc\)YUY2,width=320,height=240,frame=25/1 ! ffmpegcolorspace ! videorate ! video/x-raw-yuv,framerate=10/1 ! clockoverlay ! ffenc_mpeg4 ! udpsink host=127.0.0.1 port=5000

我正在根据上面显示的 gstreamer-0.10 命令使用 gstreamer-0.10 编写程序。

有几件事我完全不知道。

1) 如何使用clockoverlay并将其添加到管道中?我知道它的盖子过滤器,但找不到它的例子?

2) 在何处正确添加视频速率上限。我的意思是,我在 ffmpegcolourspace 元素之后添加并且它工作正常。出于好奇,我将它添加到 ffenc_mpeg4 元素之后,它再次正常工作。在这两种情况下,我都可以看到实时视频。有没有可能我根本没有在管道中添加它。有人可以给我建议吗?下面是我的代码片段。

     source = gst_element_factory_make ("v4l2src", "source");
       // cap filter #1
       GstElement *capsfilter = gst_element_factory_make("capsfilter", "camera_caps");
       GstCaps *caps = gst_caps_from_string ("video/x-raw-yuv,format=(fourcc)YUY2,width=320,height=240,framerate=25/1");
       g_object_set (capsfilter, "caps", caps, NULL);

       conv = gst_element_factory_make("ffmpegcolorspace", "Colorconverter");

// capfilter #2
       GstElement *capsfilterColor = gst_element_factory_make("capsfilter", "video-rate");
       GstCaps *capsColor = gst_caps_from_string ("videorate ! video/x-raw-yuv,framerate=10/1");
       g_object_set ( capsfilterColor, "caps", capsColor, NULL);


       videoenc = gst_element_factory_make("ffenc_mpeg4", "videoenc");

       udpsink = gst_element_factory_make("udpsink", "udpsink");

       // Create the empty pipeline
        pipeline = gst_pipeline_new ("test-pipeline");

      g_object_set(G_OBJECT(udpsink),
                    "host", "127.0.0.1",
                     "port", 5000,
                     NULL);


      g_object_set (G_OBJECT ( source ), "device", "/dev/video0", NULL);

      gst_bin_add_many (GST_BIN (pipeline), source, capsfilter, conv, capsfilterColor,  videoenc, udpsink, NULL);

     // **here AM I adding caps filter correctly??**?
      gst_element_link_many (source, capsfilter, conv, capsfilterColor, videoenc, udpsink, NULL);

1,要添加时钟覆盖,只需将它放在 v4l2src 之后的某个位置(也许它是正确的,你已经有了它)..时钟覆盖只是另一个元素,如 v4l2src 或 videorate..

这也有效(我没有安装 0.10,但它应该有效):

gst-launch-1.0 videotestsrc ! clockoverlay ! autovideosink

2,对于代码 - 它非常混乱,您将大写字母与元素混合在一起。您必须了解 capsfilter 是一个元素,它可以对前一个元素的输出施加某种格式。实际的上限设置为 capsfilter 为 属性(在 v4l2src 上,您正在设置设备等属性。在 capsfilter 上,您正在将 属性 设置为 caps,并使用表示这些功能的字符串)。

您不能以这种方式将视频速率放在上限中...视频速率是元素,上限是属性..

您必须创建 videorate 并在其后添加 capsfilter.. 以便 videorate 将视频流转换为它在其 src pad 上看到的所需速率(videorate 的输出)。

所以代码如下。 对不起,我忍不住整理一下,也将 capsfilterColor 重命名为 capsfilterRate 因为这样更合适。 我也根本没有测试过 - 只是写在我的头上,我希望它能编译 :D

source = gst_element_factory_make ("v4l2src", "source");
GstElement *capsfilter = gst_element_factory_make("capsfilter", "camera_caps");
conv = gst_element_factory_make("ffmpegcolorspace", "Colorconverter");
videorate = gst_element_factory_make("videorate", "videorate-element");
GstElement *capsfilterRate = gst_element_factory_make("capsfilter", "video-rate");
videoenc = gst_element_factory_make("ffenc_mpeg4", "videoenc");
udpsink = gst_element_factory_make("udpsink", "udpsink");

// cap filter #1
GstCaps *caps = gst_caps_from_string ("video/x-raw-yuv,format=(fourcc)YUY2,width=320,height=240,framerate=25/1");
g_object_set (capsfilter, "caps", caps, NULL);
gst_caps_unref(caps);//do not forget to unref - memoryleak!

// capfilter #2
GstCaps *capsRate = gst_caps_from_string ("video/x-raw-yuv,framerate=10/1");
g_object_set ( capsfilterRate, "caps", capsRate, NULL);
gst_caps_unref(capsRate);//again unref!

// Create the empty pipeline
pipeline = gst_pipeline_new ("test-pipeline");

g_object_set(G_OBJECT(udpsink),
             "host", "127.0.0.1",
             "port", 5000,
             NULL);

g_object_set (G_OBJECT ( source ), 
              "device", "/dev/video0", 
              NULL);

//proper adding to pipe
gst_bin_add_many (GST_BIN (pipeline), source, capsfilter, conv, videorate, capsfilterRate,  videoenc, udpsink, NULL);

//proper linking:
gst_element_link_many (source, capsfilter, conv, videorate, capsfilterRate,  videoenc, udpsink, NULL);