c - 使用带有 c API 的 gstreamer 显示图像

标签 c gstreamer

我尝试使用 c API 做一个 gstreamer 管道来为此显示图像我使用这个 gst-launch 命令

gst-launch filesrc location="pluto.jpg" ! jpegdec ! ffmpegcolorspace ! videobalance saturation=0 ! freeze ! ximagesink

当我尝试它时它工作正常但是当我尝试将它转换为 C 代码时它不起作用有人可以帮助我吗?

#include <gst/gst.h>

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

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

  /* Create the elements */
  source = gst_element_factory_make ("filesrc", "source");
  sink = gst_element_factory_make ("ximagesink", "sink");
 jpdec = gst_element_factory_make ("jpegdec", "jdec");
 imgf = gst_element_factory_make ("imagefreeze", "freeze");
 cod = gst_element_factory_make ("ffmpegcolorspace", "ffmdec");

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

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

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

  /* Modify the source's properties */
   g_object_set (G_OBJECT (source), "location","pluto.jpg", 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;
}

有我用来播放图像的c代码
当我编译代码时我没有错误但是当我运行它时我有这个错误:

(test:5355): GStreamer-CRITICAL **: gst_caps_get_structure: assertion `GST_IS_CAPS (caps)' failed

(test:5355): GStreamer-CRITICAL **: gst_structure_get_int: assertion `structure != NULL' failed
Error received from element sink: Failed to create output image buffer of 0x0 pixels
Debugging information: ximagesink.c(472): gst_ximagesink_ximage_new (): /GstPipeline:test-pipeline/GstXImageSink:sink:
could not get shared memory of 0 bytes

最佳答案

您的 gst_element_link 有误。像这样的东西:

if (gst_element_link_many (source, jpdec, cod, imgf, sink, NULL) != TRUE)

应该可以。

这些错误很可能是 xvimagesink 中的一个错误,但你错误地使用了它。请随时在 bugzilla.gnome.org 上报告有关这些断言的错误,以防它们在 1.0 中发生。

关于c - 使用带有 c API 的 gstreamer 显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19685022/

相关文章:

c++ - 如何诊断加载 gstreamer 插件时出现的问题?

python - gstreamer 帮助消息覆盖我的 argparse 消息

c - 将图像推送到 Gstreamer 管道中

c++ - 错误 : request for member ‘stor_begin’ in ‘v’ , 属于非类类型 ‘igraph_vector_t*’

c - 段错误解决方案

c - 获取我的输入并在 while 循环中比较它,fgets?

c - scanf 可选匹配

udp - 无法显示通过 UDP 使用 GStreamer 流式传输的 h.264 网络摄像头图像

audio - 在不同情况下播放多声道音频时出错?

c - 原子操作-C