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

5vf7fwbs  于 2023-03-14  发布在  其他
关注(0)|答案(1)|浏览(176)

因为我需要使用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流传输视频

emeijp43

emeijp431#

不确定这是否是答案,但以下内容可能会有所帮助
1.您可以尝试将x264 enc属性insert-vui设置为true,将key-int-max设置为15(30 fps时为半秒)。

gst-launch-1.0 videotestsrc ! video/x-raw,width=640,height=480,framerate=30/1 ! x264enc insert-vui=1 key-int-max=15 ! h264parse ! rtph264pay ! udpsink host=192.168.100.232 port=554 auto-multicast=0

1.请注意,要使用VLC接收RTPH 264,您需要一个SDP文件。如果您不知道如何编写该文件,一个简单的解决方案是使用RTPMP 2 T,它具有静态有效载荷,可以轻松地通过VLC打开,而无需SDP:

gst-launch-1.0 videotestsrc ! video/x-raw,width=640,height=480,framerate=30/1 ! x264enc insert-vui=1 key-int-max=15 ! h264parse ! mpegtsmux ! rtpmp2tpay ! udpsink host=192.168.100.232 port=554 auto-multicast=0

1.确保没有防火墙阻止UDP/554。您也可以尝试更高的端口号,如5004。您可以首先尝试流到本地主机,当确定移动到真实的的以太网。

相关问题