Как добавить текстовую переменную на GStreamer? - PullRequest
0 голосов
/ 18 марта 2020

Я очень новичок в GStreamer? GStreamer настолько хорош, что я могу наложить текст на экран. Теперь я просто хочу наложить переменный текст, как случайное число или что-то еще, меняющееся?

Наложить текст:

gst-launch-1.0 imxv4l2src device=/dev/video0 ! 'video/x-raw,format=(string)NV12,width=1280,height=720,framerate=(fraction)30/1' ! textoverlay text="Hi StackOverflow" valignment=top halignment=left font-desc="Sans, 12" ! autovideosink

Как я могу это сделать?

Большое спасибо!

Тоан

Ответы [ 2 ]

1 голос
/ 18 марта 2020

Переменная text является свойством. Вы можете установить это через g_object_set() в C API. Вы можете использовать любой другой язык, для которого существуют привязки Glib / GStreamer. Но обратите внимание, вам нужно написать настоящее приложение GStreamer. Вы не можете сделать это, просто используя gst-lauch-1.0. Это приложение подходит для тестирования, но позволяет вам делать это только в рамках GStreamer.

РЕДАКТИРОВАТЬ:

К добавленному коду:

перед:

 /* Wait until error or EOS */
  bus = gst_element_get_bus (pipeline);

попробуйте что-то вроде этого:

  for (int i = 0; i < 10; i++) {
    snprintf (var_str, sizeof(var_str), "%d",num++);
    g_object_set (text, "text", var_str, NULL);
    g_usleep(1000*1000);
  }
0 голосов
/ 20 марта 2020

Это мой код:

#include <gst/gst.h>
#include <stdio.h> 
#include <stdlib.h> 

char var_str[10];
int num = 0;

int main(int argc, char *argv[]) {
  GstElement *pipeline, *source, *sink;
  GstBus *bus;
  GstMessage *msg;
  GstStateChangeReturn ret;

  /* Initialize GStreamer */
  gst_init (&argc, &argv);

  /* String of num */
  num = num + 1;
  snprintf (var_str, sizeof(var_str), "%d",num);
  /* Create the elements */
  source = gst_element_factory_make ("v4l2src", "device=/dev/video0");
  sink = gst_element_factory_make ("autovideosink", "sink");
  /* Create the empty pipeline */
  pipeline = gst_pipeline_new ("test-pipeline");

  if (!pipeline || !source || !sink) {
    g_printerr ("Not all elements could be created.\n");
    return -1;
  }

  /* Build the pipeline */
  gst_bin_add_many (GST_BIN (pipeline), source, sink, NULL);
  if (gst_element_link_many (source, sink, NULL) != TRUE) {
    g_printerr ("Elements could not be linked.\n");
    gst_object_unref (pipeline);
    return -1;
  }

  /* Modify the source's properties */
  //g_object_set (source, "pattern", 10, NULL);
  /* Start playing */
  ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
  if (ret == GST_STATE_CHANGE_FAILURE) {
    g_printerr ("Unable to set the pipeline to the playing state.\n");
    gst_object_unref (pipeline);
    return -1;
  }

  /* 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);

  /* Parse message */
  if (msg != NULL) {
    GError *err;
    gchar *debug_info;

    switch (GST_MESSAGE_TYPE (msg)) {
      case GST_MESSAGE_ERROR:
        gst_message_parse_error (msg, &err, &debug_info);
        g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message);
        g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none");
        g_clear_error (&err);
        g_free (debug_info);
        break;
      case GST_MESSAGE_EOS:
        g_print ("End-Of-Stream reached.\n");
        break;
      default:
        /* We should not reach here because we only asked for ERRORs and EOS */
        g_printerr ("Unexpected message received.\n");
        break;
    }
    gst_message_unref (msg);
  }

  /* Free resources */
  gst_object_unref (bus);
  gst_element_set_state (pipeline, GST_STATE_NULL);
  gst_object_unref (pipeline);
  return 0;
}
...