c++gstreamerimx6

Gstreamer to stream local video over IP streaming on imx6q not displaying any video out


As i need to stream the local stored video through IP streaming using Gstreamer and to receive the streamed video in VLC player.

I am using IMX6Q Processor in which the OS is build using Debian

Code Compiling & executing without any error.

Code reference given below

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

bash

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

Kindly help to stream the video over ip streaming


Solution

  • Not sure this is an answer, but the following may help

    1. You may try setting x264enc properties insert-vui to true and key-int-max to 15 (half a second for 30fps).
    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. Note that for receiving RTPH264 with VLC, you would need a SDP file. If you don't know how to write that, an easy workaround would be using RTPMP2T that has a static payload and can be easily opened by VLC without 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. Be sure that no firewall blocks UDP/554. You may also try a higher port number such as 5004. You may first try streaming to localhost and when ok move to real ethernet.

    2. Once you get working streaming, you can change your video input such as, for a mp4 container file source:

    # Adding explicit MP4 demuxer
    gst-launch-1.0 filesrc location=/media/DELOPT1.mp4 ! qtdemux ! decodebin ! videoconvert ! queue ! x264enc key-int-max=15 ! h264parse ! mpegtsmux ! rtpmp2tpay ! udpsink host=192.168.100.232 port=5004 auto-multicast=0
    
    # Try adding buffering to decodebin
    gst-launch-1.0 filesrc location=/media/DELOPT1.mp4 ! qtdemux ! decodebin use-buffering=1 ! videoconvert ! queue ! x264enc key-int-max=15 ! h264parse ! mpegtsmux ! rtpmp2tpay ! udpsink host=192.168.100.232 port=5004 auto-multicast=0