NXP MCU 技术论坛
直播中

恩可口

8年用户 753经验值
私信 关注
[问答]

Gstreamer如何在不显示任何视频输出的imx6q上通过IP流传输本地视频?

因为我需要使用 Gstreamer 通过 IP 流式传输本地存储的视频,并在 VLC 播放器中接收流式视频。
我正在使用 IMX6Q-SL EVK 板
代码编译和执行没有任何错误。但没有显示任何输出,也没有传输任何数据包。
请帮助我解决问题。代码参考如下。
由于我是处理器的新手,请耐心等待我的知识。


#include

int main(int argc, char *argv[]) {
  GstElement *pipeline, *source, *decode, *convert, *scale, *encoder, *pay, *sink;
  GstCaps *filtercaps;
  GstBus *bus;
  GstMessage *msg;
  GMainLoop *loop;

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

  gst_debug_set_threshold_for_name("x264enc", GST_LEVEL_LOG);

  // Create the pipeline
  pipeline = gst_pipeline_new("my-pipeline");

  // Create the source element for reading the video frames from a local file
  source = gst_element_factory_make("filesrc", "source");
  g_object_set(G_OBJECT(source), "location", "Video.mp4", NULL); // set the path to the video file as needed

  // Create the decode element for decoding the video
  decode = gst_element_factory_make("decodebin", "decode");

  // Create the convert element for converting the video format
  convert = gst_element_factory_make("videoconvert", "convert");

  // Create the scale element for resizing the video
  scale = gst_element_factory_make("videoscale", "scale");
  g_object_set(G_OBJECT(scale), "method", 0, NULL);
  g_object_set(G_OBJECT(scale), "add-borders", FALSE, NULL);
  g_object_set(G_OBJECT(scale), "skip-canvas", TRUE, NULL);

  // Create the encoder element for encoding the video with H.264
  encoder = gst_element_factory_make("x264enc", "encoder");
  g_object_set(G_OBJECT(encoder), "tune", 5, NULL); // set encoding parameters as needed

  // Create the pay element for packaging the encoded video into RTP packets
  pay = gst_element_factory_make("rtph264pay", "pay");

  // Create the sink element for sending the RTP packets over UDP
  sink = gst_element_factory_make("udpsink", "sink");
  g_object_set(G_OBJECT(sink), "host", "192.168.100.232", NULL); // set receiver IP address
  g_object_set(G_OBJECT(sink), "port", 554, NULL); // set receiver port number

  // Add all elements to the pipeline
  gst_bin_add_many(GST_BIN(pipeline), source, decode, convert, scale, encoder, pay, sink, NULL);

  // Link the elements together
  gst_element_link(source, decode);
  gst_element_link_many(convert, scale, encoder, pay, sink, NULL);

  // Set the caps filter for the decode element
  filtercaps = gst_caps_new_simple("video/x-h264",
      "stream-format", G_TYPE_STRING, "byte-stream",
      NULL);
  gst_element_link_filtered(decode, convert, filtercaps);
  gst_caps_unref(filtercaps);

  // Start playing the pipeline
  gst_element_set_state(pipeline, GST_STATE_PLAYING);

  // Wait for completion or error
  loop = g_main_loop_new(NULL, FALSE);
  bus = gst_element_get_bus(pipeline);
  msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR);
# if (msg != NULL) {
      gst_message_unref(msg);
  }
  gst_object_unref(bus);
  gst_element_set_state(pipeline, GST_STATE_NULL);
  gst_object_unref(pipeline);
  g_main_loop_unref(loop);

  return 0;
}
使用下面的 bash 编译程序

g++ -o Stream Stream_Local.cpp `pkg-config --cflags --libs gstreamer-1.0 gstreamer-app-1.0`

更多回帖

发帖
×
20
完善资料,
赚取积分