如何将输入文件表示为实时流?

时间:2019-04-03 09:39:04

标签: gstreamer gstreamer-1.0

我使用gst-rtsp-server进行视频流传输。我需要像实时流一样流mp4文件。然后,我将进行循环并更改输入文件以进行实时流模仿...

现在,如果源是来自摄像机的rtsp流或v4l2流,则GST-RTSP-SERVER会生成实时流(无倒带功能)。 但是,如果源是mp4文件-GST-RTSP-SERVER会生成可以倒带的流。

我的代码(与test-mp4.c示例几乎相同)

#include <gst/gst.h>
#include <gst/rtsp-server/rtsp-server.h>

int main (int argc, char *argv[])
{
  GMainLoop *loop;
  GstRTSPServer *server;
  GstRTSPMountPoints *mounts;
  GstRTSPMediaFactory *factory;
  gchar *str;
  gchar *url;

  char *port = (char *) argv[3];

  GOptionEntry entries[] = {
    {"port", 'p', 0, G_OPTION_ARG_STRING, &port,
        "Port to listen on (default: DEFAULT_RTSP_PORT )", "PORT"},
    {NULL}
  };

  GOptionContext *optctx;
  optctx = g_option_context_new ("<launch line> - Test RTSP Server, Launch\n\n"
    "Example: \"( decodebin name=depay0 ! autovideosink )\"");
  g_option_context_add_main_entries (optctx, entries, NULL);
  g_option_context_free (optctx);

  gst_init (&argc, &argv);

  if (argc < 3) {
    g_message ("usage: %s <filename.mp4> <UUID>", argv[0]);
    return -1;
  }

  loop = g_main_loop_new (NULL, FALSE);
  server = gst_rtsp_server_new ();

  g_object_set (server, "service", port, NULL);

  mounts = gst_rtsp_server_get_mount_points (server);

  str = g_strdup_printf ("( "
      "filesrc location=%s ! qtdemux name=d "
      "d. ! queue ! rtph264pay pt=96 name=pay0 "
      ")", argv[1]);
  factory = gst_rtsp_media_factory_new ();
  gst_rtsp_media_factory_set_launch (factory, str);
  g_free (str);

  url = g_strdup_printf ("/arch/%s", argv[2]);
  g_message ("url: %s", url);

  gst_rtsp_mount_points_add_factory (mounts, url, factory);
  g_object_unref (mounts);
  g_free(url);
  gst_rtsp_server_attach (server, NULL);

  g_main_loop_run (loop);

  return 0;
}

那么,如何像实时流一样表示输入的src文件?

谢谢!

0 个答案:

没有答案