<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2017-12-01 12:20 GMT+01:00 Jesper Taxbøl <span dir="ltr"><<a href="mailto:jesper@taxboel.dk" target="_blank">jesper@taxboel.dk</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div>You guys are right. My solution is not safe.<br></div><div><br></div><div>The signal works but the file is messed up in such a way that when transcoding the file gstreamer often stalls generating much larger files than the input. When running ffprobe against the file duration is strange. <br></div></div><div><br></div><div>I was thinking that the problem was that the pipeline did not have time to close the file properly. <br></div><div><br></div><div>Therefore I found the example from <a href="https://gstreamer.freedesktop.org/documentation/tutorials/basic/time-management.html.I" target="_blank">https://gstreamer.freedesktop.<wbr>org/documentation/tutorials/<wbr>basic/time-management.html.I</a> could insert my configuration and piggyback on the message flow. <br></div><div><br></div><div><b>mpegtsmux ! filesink location=two.ts \<br>  rtspsrc 
location=rtsp://<a href="http://root:hest1234@192.168.130.200/axis-media/media.amp" target="_blank">root:hest1234@<wbr>192.168.130.200/axis-media/<wbr>media.amp</a> 
ntp-sync=true protocols=GST_RTSP_LOWER_<wbr>TRANS_TCP ! \<span class=""><br>  queue ! capsfilter caps=\"application/x-rtp,<wbr>media=video\" ! \<br></span>  rtph264depay ! mpegtsmux0. \<br> 
 rtspsrc 
location=rtsp://<a href="http://root:hest1234@192.168.130.201/axis-media/media.amp" target="_blank">root:hest1234@<wbr>192.168.130.201/axis-media/<wbr>media.amp</a> 
ntp-sync=true protocols=GST_RTSP_LOWER_<wbr>TRANS_TCP ! \<span class=""><br>  queue ! capsfilter caps=\"application/x-rtp,<wbr>media=video\" ! \<br></span>  rtph264depay ! mpegtsmux0.</b></div><div><br></div><div>In the message handler I count timeouts and stop after a given time. Full source added below.<br></div></div><div><br></div><div>The approach works as such, but it still gives me funny readings. ffprobe says:</div><div><br></div><div>Invalid return value 0 for stream protocol<br>Input #0, mpegts, from 'two.ts':<br>  Duration: 00:00:11.95, start: 3600.698056, bitrate: 37229 kb/s<br>  Program 1 <br>    Stream #0:0[0x41]: Video: h264 (High) (HDMV / 0x564D4448), yuvj420p(pc, bt709, progressive), 3840x2160 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc<br>    Stream #0:1[0x42]: Video: h264 (High) (HDMV / 0x564D4448), yuvj420p(pc, bt709, progressive), 3840x2160 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc<br></div><br></div>I notice that duration is somewhat plausible, but start is 3600, which I guess could be part of the problem.</div><div><br></div><div>Any Ideas on how to fix time in my output file.<br></div><div><div><br><div>Kind regards</div><div><br></div><div>Jesper<br></div><div><br></div><div><br></div><div><br><div><br>#include <stdio.h><br>#include <gst/gst.h><br><br>/* Structure to contain all our information, so we can pass it around */<br>typedef struct _CustomData {<br>  GstElement *playbin;  /* Our one and only element */<br>  gboolean playing;      /* Are we in the PLAYING state? */<br>  gboolean terminate;    /* Should we terminate execution? */<br>  gboolean seek_enabled; /* Is seeking enabled for this media? */<br>  gboolean seek_done;    /* Have we performed the seek already? */<br>  gint64 duration;       /* How long does this media last, in nanoseconds */<br>} CustomData;<br><br>/* Forward definition of the message processing function */<br>static void handle_message (CustomData *data, GstMessage *msg);<br><br>int main(int argc, char *argv[]) {<br>  CustomData data;<br>  GstBus *bus;<br>  GstMessage *msg;<br>  GstStateChangeReturn ret;<br><br>  data.playing = FALSE;<br>  data.terminate = FALSE;<br>  data.seek_enabled = FALSE;<br>  data.seek_done = FALSE;<br>  data.duration = GST_CLOCK_TIME_NONE;<br><br>  /* Initialize GStreamer */<br>  gst_init (&argc, &argv);<br><br>  /* Create the elements */<br>  //data.playbin = gst_element_factory_make ("playbin", "playbin");<br><br>  char* cmd = "mpegtsmux ! filesink location=two.ts \<br>  rtspsrc location=rtsp://<a href="http://root:hest1234@192.168.130.200/axis-media/media.amp" target="_blank">root:hest1234@<wbr>192.168.130.200/axis-media/<wbr>media.amp</a> ntp-sync=true protocols=GST_RTSP_LOWER_<wbr>TRANS_TCP ! \<span class=""><br>  queue ! capsfilter caps=\"application/x-rtp,<wbr>media=video\" ! \<br></span>  rtph264depay ! mpegtsmux0. \<br>  rtspsrc location=rtsp://<a href="http://root:hest1234@192.168.130.201/axis-media/media.amp" target="_blank">root:hest1234@<wbr>192.168.130.201/axis-media/<wbr>media.amp</a> ntp-sync=true protocols=GST_RTSP_LOWER_<wbr>TRANS_TCP ! \<span class=""><br>  queue ! capsfilter caps=\"application/x-rtp,<wbr>media=video\" ! \<br></span>  rtph264depay ! mpegtsmux0.";<br>  printf(cmd);<br>  data.playbin = gst_parse_launch (cmd, NULL);<br><br><br>  if (!data.playbin) {<br>    g_printerr ("Not all elements could be created.\n");<br>    return -1;<br>  }<br><br>  /* Set the URI to play */<br>  //g_object_set (data.playbin, "uri", //"<a href="https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm" target="_blank">https://www.freedesktop.<wbr>org/software/gstreamer-sdk/<wbr>data/media/sintel_trailer-<wbr>480p.webm</a>", NULL);<br><br><br><br>  /* Start playing */<br>  ret = gst_element_set_state (data.playbin, GST_STATE_PLAYING);<br>  if (ret == GST_STATE_CHANGE_FAILURE) {<br>    g_printerr ("Unable to set the pipeline to the playing state.\n");<br>    gst_object_unref (data.playbin);<br>    return -1;<br>  }<br><br>  /* Listen to the bus */<br>  bus = gst_element_get_bus (data.playbin);<br><br>  int t = 0;<br><br>  do {<br>    msg = gst_bus_timed_pop_filtered (bus, 100 * GST_MSECOND,<br>        GST_MESSAGE_STATE_CHANGED | GST_MESSAGE_ERROR | GST_MESSAGE_EOS | GST_MESSAGE_DURATION);<br><br>    printf("Tick: \r\n%d\r\n", t++);<br>    if(t == 200)<br>    {<br>      gst_element_send_event (GST_ELEMENT (data.playbin), gst_event_new_eos());<br>    }<br><br>    /* Parse message */<br>    if (msg != NULL) {<br>      handle_message (&data, msg);<br>    } else {<br><br>      /* We got no message, this means the timeout expired */<br>      if (data.playing) {<br>        gint64 current = -1;<br><br>        /* Query the current position of the stream */<br>        if (!gst_element_query_position (data.playbin, GST_FORMAT_TIME, &current)) {<br>          g_printerr ("Could not query current position.\n");<br>        }<br><br>        /* If we didn't know it yet, query the stream duration */<br>        if (!GST_CLOCK_TIME_IS_VALID (data.duration)) {<br>          if (!gst_element_query_duration (data.playbin, GST_FORMAT_TIME, &data.duration)) {<br>            g_printerr ("Could not query current duration.\n");<br>          }<br>        }<br><br>        /* Print current position and total duration */<br>        g_print ("Position %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT "\r",<br>            GST_TIME_ARGS (current), GST_TIME_ARGS (data.duration));<br><br>        /* If seeking is enabled, we have not done it yet, and the time is right, seek */<br>        if (data.seek_enabled && !data.seek_done && current > 10 * GST_SECOND) {<br>          g_print ("\nReached 10s, performing seek...\n");<br>          gst_element_seek_simple (data.playbin, GST_FORMAT_TIME,<br>              GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT, 30 * GST_SECOND);<br>          data.seek_done = TRUE;<br>        }<br>      }<br>    }<br>  } while (!data.terminate);<br><br>  /* Free resources */<br>  gst_object_unref (bus);<br>  gst_element_set_state (data.playbin, GST_STATE_NULL);<br>  gst_object_unref (data.playbin);<br>  return 0;<br>}<br><br>static void handle_message (CustomData *data, GstMessage *msg) {<br>  GError *err;<br>  gchar *debug_info;<br><br>  switch (GST_MESSAGE_TYPE (msg)) {<br>    case GST_MESSAGE_ERROR:<br>      gst_message_parse_error (msg, &err, &debug_info);<br>      g_printerr ("Error received from element %s: %s\n", GST_OBJECT_NAME (msg->src), err->message);<br>      g_printerr ("Debugging information: %s\n", debug_info ? debug_info : "none");<br>      g_clear_error (&err);<br>      g_free (debug_info);<br>      data->terminate = TRUE;<br>      break;<br>    case GST_MESSAGE_EOS:<br>      g_print ("End-Of-Stream reached.\n");<br>      data->terminate = TRUE;<br>      break;<br>    case GST_MESSAGE_DURATION:<br>      /* The duration has changed, mark the current one as invalid */<br>      printf("...\r\n");<br>      data->duration = GST_CLOCK_TIME_NONE;<br>      break;<br>    case GST_MESSAGE_STATE_CHANGED: {<br>      GstState old_state, new_state, pending_state;<br>      gst_message_parse_state_<wbr>changed (msg, &old_state, &new_state, &pending_state);<br>      if (GST_MESSAGE_SRC (msg) == GST_OBJECT (data->playbin)) {<br>        g_print ("Pipeline state changed from %s to %s:\n",<br>            gst_element_state_get_name (old_state), gst_element_state_get_name (new_state));<br><br>        /* Remember whether we are in the PLAYING state or not */<br>        data->playing = (new_state == GST_STATE_PLAYING);<br><br>        if (data->playing) {<br>          /* We just moved to PLAYING. Check if seeking is possible */<br>          GstQuery *query;<br>          gint64 start, end;<br>          query = gst_query_new_seeking (GST_FORMAT_TIME);<br>          if (gst_element_query (data->playbin, query)) {<br>            gst_query_parse_seeking (query, NULL, &data->seek_enabled, &start, &end);<br>            if (data->seek_enabled) {<br>              g_print ("Seeking is ENABLED from %" GST_TIME_FORMAT " to %" GST_TIME_FORMAT "\n",<br>                  GST_TIME_ARGS (start), GST_TIME_ARGS (end));<br>            } else {<br>              g_print ("Seeking is DISABLED for this stream.\n");<br>            }<br>          }<br>          else {<br>            g_printerr ("Seeking query failed.");<br>          }<br>          gst_query_unref (query);<br>        }<br>      }<br>    } break;<br>    default:<br>      /* We should not reach here */<br>      g_printerr ("Unexpected message received.\n");<br>      break;<br>  }<br>  gst_message_unref (msg);<br>}<br><br><div><br><br><br><br><div><div class="gmail_extra"><div><div class="h5"><div class="gmail_quote">2017-11-30 11:40 GMT+01:00 Tim Müller <span dir="ltr"><<a href="mailto:tim@centricular.com" target="_blank">tim@centricular.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="m_5668255136235265183gmail-">On Thu, 2017-11-30 at 10:22 +0100, Jesper Taxbøl wrote:<br>
<br>
> I spent some time today and figured out i can use use the following<br>
> syntax in my makefile. Its actually the terminal sending a signal to<br>
> kill the process.<br>
<br>
</span>That'll work of course, but the file won't be finalised properly, so<br>
the headers won't be updated with the duration and there won't be a<br>
seektable and you might be missing the last few frames/seconds.<br>
<div class="m_5668255136235265183gmail-HOEnZb"><div class="m_5668255136235265183gmail-h5"><br>
Cheers<br>
-Tim<br>
<br>
--<br>
Tim Müller, Centricular Ltd - <a href="http://www.centricular.com" rel="noreferrer" target="_blank">http://www.centricular.com</a><br>
______________________________<wbr>_________________<br>
gstreamer-devel mailing list<br>
<a href="mailto:gstreamer-devel@lists.freedesktop.org" target="_blank">gstreamer-devel@lists.freedesk<wbr>top.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/gstreamer-dev<wbr>el</a><br>
</div></div></blockquote></div><br><br clear="all"><br></div></div><span class="HOEnZb"><font color="#888888">-- <br><div class="m_5668255136235265183gmail_signature">Jesper Taxbøl<br><a href="tel:+45%2061%2062%2075%2001" value="+4561627501" target="_blank">+45 61627501</a><br><br></div>
</font></span></div></div></div></div></div></div></div></div>
</blockquote></div></div><div class="gmail_extra"><br></div><div class="gmail_extra">I ended up taking the recording into a ffmpeg program I have been working on, and I could read PTS on every frame there. I wrote a simple mechanism to repeat frames if the frames are out of sync and that seems to work for now.<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">I am still interrested though if it was possible to offset PTS to start from zero in gstreamer with existing modules.<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Kind regards<br></div><div class="gmail_extra"><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Jesper Taxbøl<br>+45 61627501<br><br></div>
</div></div>