<div dir="ltr"><p dir="auto">I stream and record my video like in the code below. For information, when I start the process, I have to wait between 5 and 10 seconds before having the first frame to appears. The problem is that when I playback the video with VLC for example the video start a 5 or 10s it depends on the time I have waited before having the first frame. It is the same at the end of the video, the video continue during 5 and 10 seconds after the timebar on vlc have reached the end.</p>
<p dir="auto">Does someone have and idea ? How can I be sure that the video start and finish at the right time?</p>
<p dir="auto">void <code>MainWindow::OnStop(wxCommandEvent&)</code> is to Stop the record and void <code>MainWindow::OnSave(wxCommandEvent&)</code> is to start saving the stream</p><pre class="gmail-code gmail-highlight" lang="plaintext"><span id="gmail-LC1" class="gmail-line" lang="plaintext">void MainWindow::OnStop(wxCommandEvent&)</span>
<span id="gmail-LC2" class="gmail-line" lang="plaintext"></span>
<span id="gmail-LC3" class="gmail-line" lang="plaintext"> gst_element_send_event((*ptrstats).pipeline, gst_event_new_eos());</span>
<span id="gmail-LC4" class="gmail-line" lang="plaintext"> gst_bus_timed_pop_filtered((*ptrstats).bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_EOS);</span>
<span id="gmail-LC5" class="gmail-line" lang="plaintext"> GstStateChangeReturn ret = gst_element_set_state((*ptrstats).pipeline, GST_STATE_NULL);</span>
<span id="gmail-LC6" class="gmail-line" lang="plaintext">}</span>
<span id="gmail-LC7" class="gmail-line" lang="plaintext"> </span>
<span id="gmail-LC8" class="gmail-line" lang="plaintext">void MainWindow::OnSave(wxCommandEvent&)</span>
<span id="gmail-LC9" class="gmail-line" lang="plaintext"> {</span>
<span id="gmail-LC10" class="gmail-line" lang="plaintext"> std::string strPathVideo = m_VideoPath + CreateFileName("mkv");</span>
<span id="gmail-LC11" class="gmail-line" lang="plaintext"> </span>
<span id="gmail-LC12" class="gmail-line" lang="plaintext"> GError* error = NULL;</span>
<span id="gmail-LC13" class="gmail-line" lang="plaintext"> GstElement* source;</span>
<span id="gmail-LC14" class="gmail-line" lang="plaintext"> GstElement* filesink;</span>
<span id="gmail-LC15" class="gmail-line" lang="plaintext"> GstElement* matrox;</span>
<span id="gmail-LC16" class="gmail-line" lang="plaintext"> GstElement* clocktime;</span>
<span id="gmail-LC17" class="gmail-line" lang="plaintext"> GstElement* textoverlay;</span>
<span id="gmail-LC18" class="gmail-line" lang="plaintext"> GstCaps* caps = gst_caps_new_simple("application/x-rtp",</span>
<span id="gmail-LC19" class="gmail-line" lang="plaintext"> "media", G_TYPE_STRING, "video",</span>
<span id="gmail-LC20" class="gmail-line" lang="plaintext"> "payload", G_TYPE_INT, 96,</span>
<span id="gmail-LC21" class="gmail-line" lang="plaintext"> "encoding-name", G_TYPE_STRING, "H264",</span>
<span id="gmail-LC22" class="gmail-line" lang="plaintext"> NULL);</span>
<span id="gmail-LC23" class="gmail-line" lang="plaintext"> </span>
<span id="gmail-LC24" class="gmail-line" lang="plaintext"></span>
<span id="gmail-LC25" class="gmail-line" lang="plaintext"> (*ptrstats).pipeline = gst_parse_launch("udpsrc name=source !rtph264depay !h264parse !avdec_h264 ! tee name = t !queue !videoconvert !matroskamux name=matrox !filesink name=myFile t. ! queue ! videoconvert !d3dvideosink name=mysink sync=false", &error);</span>
<span id="gmail-LC26" class="gmail-line" lang="plaintext"></span>
<span id="gmail-LC27" class="gmail-line" lang="plaintext"> if (!(*ptrstats).pipeline) {</span>
<span id="gmail-LC28" class="gmail-line" lang="plaintext"> outfile << "Save : ", error->message ,"\n";</span>
<span id="gmail-LC29" class="gmail-line" lang="plaintext"> exit(1);</span>
<span id="gmail-LC30" class="gmail-line" lang="plaintext"> }</span>
<span id="gmail-LC31" class="gmail-line" lang="plaintext"> </span>
<span id="gmail-LC32" class="gmail-line" lang="plaintext"> filesink = gst_bin_get_by_name(GST_BIN((*ptrstats).pipeline), "myFile");</span>
<span id="gmail-LC33" class="gmail-line" lang="plaintext"> g_object_set(filesink, "location", strPathVideo.c_str(), NULL);</span>
<span id="gmail-LC34" class="gmail-line" lang="plaintext"> </span>
<span id="gmail-LC35" class="gmail-line" lang="plaintext"> matrox = gst_bin_get_by_name(GST_BIN((*ptrstats).pipeline), "matrox");</span>
<span id="gmail-LC36" class="gmail-line" lang="plaintext"> g_object_set(G_OBJECT(matrox), "offset-to-zero", true, NULL);</span>
<span id="gmail-LC37" class="gmail-line" lang="plaintext"> </span>
<span id="gmail-LC38" class="gmail-line" lang="plaintext"> source = gst_bin_get_by_name(GST_BIN((*ptrstats).pipeline), "source");</span>
<span id="gmail-LC39" class="gmail-line" lang="plaintext"> g_object_set(G_OBJECT(source), "caps", caps, NULL);</span>
<span id="gmail-LC40" class="gmail-line" lang="plaintext"> g_object_set(G_OBJECT(source), "port", m_port, NULL);</span>
<span id="gmail-LC41" class="gmail-line" lang="plaintext"></span>
<span id="gmail-LC42" class="gmail-line" lang="plaintext"> </span>
<span id="gmail-LC43" class="gmail-line" lang="plaintext"> (*ptrstats).bus = gst_element_get_bus(GST_ELEMENT((*ptrstats).pipeline));</span>
<span id="gmail-LC44" class="gmail-line" lang="plaintext"> </span>
<span id="gmail-LC45" class="gmail-line" lang="plaintext"> GstStateChangeReturn ret = gst_element_set_state((*ptrstats).pipeline, GST_STATE_PLAYING);</span>
<span id="gmail-LC46" class="gmail-line" lang="plaintext"> </span>
<span id="gmail-LC47" class="gmail-line" lang="plaintext"> }</span>
</pre><p dir="auto"><br></p></div>