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

问题描述 投票:0回答:0

因为我需要使用 Gstreamer 通过 IP 流式传输本地存储的视频,并在 VLC 播放器中接收流式视频。

我正在使用 IMX6Q 处理器,其中操作系统是使用 Debian 构建的

代码编译和执行没有任何错误。

代码参考如下

#include <gst/gst.h>

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;
}

庆典

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

请帮助通过 ip 流传输视频

c++ gstreamer imx6
© www.soinside.com 2019 - 2024. All rights reserved.