<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hi All,</p>
<p><br>
</p>
<p>TLDR version:</p>
<p>I am trying to accurately seek to a known frame in a video file
(usually an MP4 with an h264 stream inside captured from an RTSP
camera).<br>
</p>
<p>[1] Is Buffer.pts in Segment time, and need mapping to stream
time with 'Segment.to_stream_time(Buffer.pts)' ?</p>
<p>[2] Should Pipeline.seek( ... buffer_time ... ) mean the next
frame I receive is the Buffer I saw at that stream time?</p>
<p> (using a file src, pipeline does support seeking, details of
'...' in seek function given below if useful)</p>
<p><br>
</p>
<p>Thanks!</p>
<p>Will.<br>
</p>
<p><br>
</p>
<p><u>Verbose context:</u><br>
</p>
<p>
</p>
<p></p>
<p>I am working with some legacy code and have been asked to make it
seek accurately to a specific frame. However things are not
working as I'd expect.</p>
<p>I'd love some feedback on my understanding, pointers to make
things work or knowledgeable person to confirm if this could be an
issue!</p>
<br>
<p>From comments </p>
<p> <a
href="https://gstreamer.freedesktop.org/documentation/application-development/advanced/clocks.html?gi-language=python#buffer-streamtime">here</a>
(The buffer stream-time, ... [is] calculated
from the buffer timestamps and the preceding <code>SEGMENT</code>
event.)<br>
</p>
<p>and</p>
<p> <a
href="https://gstreamer.freedesktop.org/documentation/gstreamer/gstsegment.html?gi-language=python#gst_segment_to_stream_time">here</a>
(Gst.Segment.to_stream_time ... is typically used ... to operate
on
the stream time of the buffers it receives)</p>
<p>I believe Buffer.pts is in Segment time. Is that correct?</p>
<p>(I cannot see where it explicitly stated anywhere what time it's
in, so I could be easily wrong!)</p>
<p><br>
</p>
<p>Building on that understanding, I'm trying to obtain the <b>stream
time</b> of a frame from a video that is provided to an appsink
with 'pull_preroll()' with the following method:<br>
</p>
<p> seg = sample.get_segment()</p>
<p> buf = sample.get_buffer()</p>
<p> stream_time = seg.to_stream_time( buf.pts )<br>
</p>
<p><br>
</p>
<p>I then attempt to seek to a known frame's <b>stream time</b>
I've obtained using the method above with:</p>
<p> pipeline.seek(<br>
1.0, Gst.Format.TIME,</p>
<p> Gst.SeekFlags.ACCURATE | Gst.SeekFlags.FLUSH,</p>
<p> Gst.SeekType.SET, target_time,</p>
<p> Gst.SeekType.NONE, 0<br>
)</p>
<p> await_async_done()<br>
</p>
<p>However, I do not get the frame I started with (sometimes I do,
but generally it's one or two out, usually prior to the frame I
anticipate). I've tried adding an 'epsilon' value to see if it is
a rounding issue, but that doesn't seem to apply either.<br>
</p>
<p>Can anyone make any comments or recommendations?</p>
<p><br>
</p>
<p>Thanks!</p>
<p><br>
</p>
<p>Will.</p>
<p><br>
</p>
<p><br>
</p>
<p>P.S.</p>
<p>I've also tried the following based on seeking by Buffers, but it
doesn't seem to work with my pipeline. From docs I read I think
this is not unexpected...<br>
</p>
<p> pipeline.seek(<br>
1.0, Gst.Format.Buffers,</p>
<p> Gst.SeekFlags.ACCURATE | Gst.SeekFlags.FLUSH,</p>
<p> Gst.SeekType.SET, target_frame_index,</p>
<p> Gst.SeekType.NONE, 0<br>
)</p>
<p></p>
</body>
</html>