<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 20, 2019 at 11:28 AM Alex Lynch <<a href="mailto:lynch.alex@gmail.com">lynch.alex@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">
<p>I have a Python GStreamer application that uses appsrc to record mp4 files. </p>

<p>The issue is that despite specifying <code>tune=zerolatency</code> 
for x264enc, there is latency, and the output video is truncated when an
 eos is sent to the pipeline. Depending on the machine, the latency is 
substantial, resulting in a much shorter than expected output file.</p>

<p>If I change the pipeline to save the video as an AVI file, it is not 
truncated. Unfortunately, the resulting file is approximately 2 GB per 
minute versus 12 MB per minute with H.264.</p>

<p>Here is the x264enc pipeline:</p><p>
</p><pre><code>appsrc name=appsrc format=time is-live=true caps=video/x-raw,format=(string)BGR appsrc. ! videoconvert ! x264enc tune=zerolatency ! qtmux ! filesink location=out.mp4</code></pre>

<div>
When the application is finished, it sends end-of-stream messages to the appsrc and pipeline: <br></div><div></div><div>
<pre><code>if self._appsrc.emit("end-of-stream") == Gst.FlowReturn.OK:
    self._sink_pipeline.send_event(Gst.Event.new_eos())</code></pre>

</div><div>
Is there a way for my application to wait while x264enc processes its 
buffer? A message, perhaps? I don't care how long it takes to finish. 
What's important is that all frames pushed to the <code>appsrc</code> are written to the output video file. <br></div></div></blockquote><div><br></div><div>Alex, I assume you are waiting on the EOS message the bus emits after the full pipeline emits the EOS. That should allow the x264enc to flush all outstanding buffers.<br></div><div><br></div><div>I made a similar mistake in that I wasn't caching the EOS message on the bus which caused me truncation too because I wasn't giving time for all the elements to flush (this seems like.a flush after EOS issue more so than latency).<br></div><div><br></div><div>-aps<br></div></div></div>