在 vlc 上重播视频时,matroskamux 时间栏不起作用

matroskamux timebar does not work when replaying video on vlc

我用 matroskamux 成功地将视频流保存在 .mkv 中,但是当我用 vlc 打开它时,我无法使用时间栏推进视频。 你有什么主意吗?我将偏移量添加为零但没有任何变化。

GError* error = NULL;
GstElement* source;
GstElement* filesink;
GstElement* matrox;

GstCaps* caps = gst_caps_new_simple("application/x-rtp",
           "media", G_TYPE_STRING, "video",
           "payload", G_TYPE_INT, 96,
           "encoding-name", G_TYPE_STRING, "H264",
           NULL);

pipeline = gst_parse_launch("udpsrc name=source ! rtpjitterbuffer !rtph264depay !h264parse !avdec_h264 ! tee name = t !queue !autovideoconvert !matroskamux name=matrox !filesink name=myFile t. ! queue ! videoconvert !d3dvideosink name=mysink", &error);

filesink = gst_bin_get_by_name(GST_BIN(pipeline), "myFile");
g_object_set(filesink, "location", strPathVideo.c_str(), NULL);

matrox = gst_bin_get_by_name(GST_BIN(pipeline), "matrox");
g_object_set(G_OBJECT(matrox), "offset-to-zero", true, NULL);

source = gst_bin_get_by_name(GST_BIN(pipeline), "source");
g_object_set(G_OBJECT(source), "caps", caps, NULL);
g_object_set(G_OBJECT(source), "port", m_port, NULL);

我尝试尽可能真实地模拟您管道的录音分支。

gst-launch-1.0 videotestsrc ! autovideoconvert ! x264enc ! h264parse ! avdec_h264 ! matroskamux name=matrox ! filesink location=matroska_video.mkv

我无法在该视频中使用 vlc 的时间栏。

当我在结尾处添加 EOS 参数 (-e) 时,视频会随着时间栏滚动。

gst-launch-1.0 videotestsrc ! autovideoconvert ! x264enc ! h264parse ! avdec_h264 ! matroskamux name=matrox ! filesink location=myFile.mkv -e

这是因为包含时间信息的视频头写在流的末尾。

因此,您需要向您的管道添加一个eos 处理程序。我在给出示例的文档中找到 this page

示例总结: 您向管道添加了一个信号处理程序

g_signal_connect (bus, "message", (GCallback) cb_message,
  pipeline);

信号处理程序将如下所示:

static void
cb_message (GstBus     *bus,
            GstMessage *message,
            gpointer    user_data)
{
  GstElement *pipeline = GST_ELEMENT (user_data);

  switch (GST_MESSAGE_TYPE (message)) {
    case GST_MESSAGE_ERROR:
      g_print ("we received an error!\n");
      g_main_loop_quit (loop);
      break;
    case GST_MESSAGE_EOS:
      g_print ("we reached EOS\n");
      g_main_loop_quit (loop);
      break;
    case GST_MESSAGE_APPLICATION:
    {
      if (gst_message_has_name (message, "ExPrerolled")) {
        /* it's our message */
        g_print ("we are all prerolled, do seek\n");
        gst_element_seek (pipeline,
            1.0, GST_FORMAT_TIME,
            GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE,
            GST_SEEK_TYPE_SET, 2 * GST_SECOND,
            GST_SEEK_TYPE_SET, 5 * GST_SECOND);

        gst_element_set_state (pipeline, GST_STATE_PLAYING);
      }
      break;
    }
    default:
      break;
  }
}