GST启动和多行文字

时间:2019-04-03 19:59:30

标签: gstreamer gst-launch

如何在gst启动时在textoverlay管道中设置多行文本?

我想建立一个管道,并希望垂直和水平居中放置多行文本。我可以做1行。

我不确定如何指定换行符。

gst-launch-1.0 videotestsrc pattern=0 horizontal-speed=0 is-live=1 \
    ! textoverlay text="PLEASE <b>STAND</b> <span foreground=\"blue\" size=\"x-large\">\nBY</span>Next <u>under-line</u>" valignment=center halignment=center font-desc="Sans, 24" \ ... other pipes ...

我希望基本上有2条以上的线。两者相对彼此以及整个屏幕都在垂直和水平方向对齐。

1 个答案:

答案 0 :(得分:0)

我不知道如何在gst-launch的参数内传递换行符,但是您可以使用C代码实现相同的目的。下面是示例:

#include <glib.h>
#include <gst/gst.h>

int main(int argc, char* argv[])
{
  GMainLoop* loop;

  GstElement *pipeline, *source, *overlay, *sink;

  gst_init(&argc, &argv);

  loop = g_main_loop_new(NULL, FALSE);

  // initialize elements
  pipeline = gst_pipeline_new("audio-player");
  source = gst_element_factory_make("videotestsrc", "source");
  overlay = gst_element_factory_make("textoverlay", "overlay");
  sink = gst_element_factory_make("autovideosink", "sink");

  if (!pipeline || !source || !overlay || !sink) {
    g_printerr("One element could not be created. Exiting.\n");
    return -1;
  }

  g_object_set(G_OBJECT(overlay), "text", "blebleble\nble", NULL);
  g_object_set(G_OBJECT(overlay), "font-desc", "Sans, 24", NULL);
  g_object_set(G_OBJECT(overlay), "halignment", 1, NULL);
  g_object_set(G_OBJECT(overlay), "valignment", 1, NULL);

  // add elements to pipeline
  gst_bin_add_many(GST_BIN(pipeline), source, overlay, sink, NULL);

  // link elements
  gst_element_link(source, overlay);
  gst_element_link_many(overlay, sink, NULL);

  gst_element_set_state(pipeline, GST_STATE_PLAYING);

  g_main_loop_run(loop);

  // cleanup
  gst_element_set_state(pipeline, GST_STATE_NULL);
  gst_object_unref(GST_OBJECT(pipeline));
  g_main_loop_unref(loop);

  return 0;
}