<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Hi,
<div class=""><br class="">
</div>
<div class="">Thanks for answering!</div>
<div class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On 5 Aug 2022, at 02:09, Tim-Philipp Müller <<a href="mailto:t.i.m@zen.co.uk" class="">t.i.m@zen.co.uk</a>> wrote:</div>
<div class="">
<div class=""><br class="">
The mechanism is usually to only state change of the new elements once<br class="">
they're inside the pipeline, but set sink elements to async=false so<br class="">
they don't do the usual asynchronous state change / preroll dance.</div>
</div>
</blockquote>
<div><br class="">
</div>
<div>By adding I meant "linking". I believe what you described is what I've been doing: add,</div>
<div>set state, link?</div>
<div><br class="">
</div>
<div>`async=false` indeed solves the issue of having the pipeline change its state when linking. That leaves</div>
<div>me with two questions though:</div>
<div>- Is there no way to achieve an insertion without putting back the pipeline in preroll mode with `async=true`?</div>
<div>- If that doesn't change the overall behaviour, on what occasions would I even want to keep `async=true`?</div>
<div><br class="">
</div>
<div>Adding to my initial example, I'm starting with the following pipeline:</div>
<div><br class="">
</div>
</div>
</div>
<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class="">
<div class="">
<div>
<div>
<div>videotestsrc is-live=true \</div>
</div>
</div>
</div>
<div class="">
<div>
<div>
<div>        ! tee name=tee allow-not-linked=true</div>
</div>
</div>
</div>
</blockquote>
<div class="">
<div>
<div><br class="">
</div>
<div>Once the pipeline is started, I add/set state/link the following bin:</div>
<div><br class="">
</div>
</div>
</div>
<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class="">
<div class="">
<div>
<div>bin. ( videoconvert ! \</div>
</div>
</div>
<div class="">
<div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>pngenc snapshot=true ! \</div>
</div>
</div>
<div class="">
<div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>filesink async=false location=/tmp/snapshot.png )</div>
</div>
</div>
</blockquote>
<div class="">
<div>
<div><br class="">
</div>
<div>That works well. EOS is reached and I can catch it from the filesink. However if I add a queue before</div>
<div>the videoconvert element, filesink seems to never posts EOS:</div>
<div>- pngenc has the same behaviour (GST_FLOW_EOS after the first buffer)</div>
<div>- file is created but empty</div>
<div>- only if I politely terminate the pipeline by setting it to null, the file will be written and contain the snapshot</div>
<div><br class="">
</div>
<div>I've tried various combinations of properties for the queue without success (flush-on-eos, max-size of 1 buffer, leaky, ...).</div>
<div>It still works if I link before starting the pipeline...</div>
<div><br class="">
</div>
<div>What's going on?</div>
<div><br class="">
</div>
<div>(I need the queue because the real use case is a bit more complex and I have various snapshots happening in</div>
<div>different formats.)</div>
<div><br class="">
</div>
<blockquote type="cite" class="">
<div class="">
<div class="">My suggestion would be this:<br class="">
<br class="">
1. Have a branch with a fakesink (or fakesink async=false if buffer<br class="">
flow is not assured) that's always in the pipeline and receives the<br class="">
latest raw video buffers on a regular basis.<br class="">
<br class="">
2. When you want to take a snapshot, you retrieve the last video frame<br class="">
from the fakesink via the "last-sample" property. This gives you a<br class="">
GstSample with the last raw video buffers plus the caps etc.<br class="">
<br class="">
3. You can then pass that GstSample to gst_video_convert_sample() or<br class="">
gst_video_convert_sample_async() to encode it to png or jpeg<br class="">
(optionally also scale or adjust the aspect ratio).<br class="">
<br class="">
4. You then get back a new GstSample with the encoded image. Just map<br class="">
the buffer and write it to file yourself or with g_file_set_contents().<br class="">
<br class="">
Not as fancy, but should work just fine and should be fairly robust.<br class="">
<br class="">
</div>
</div>
</blockquote>
<br class="">
</div>
<div>Looks good, thanks for suggesting that! However we also have the same process for recording</div>
<div>samples instead of snapshots so I'll run into problems there as well if I can't find a solution that works</div>
<div>for both.</div>
<div><br class="">
</div>
<div>Simon</div>
<br class="">
</div>
</body>
</html>