How to wait for x264enc to encode buffered frames on end-of-stream

pisymbol . pisymbol at gmail.com
Tue Aug 20 19:25:08 UTC 2019


On Tue, Aug 20, 2019 at 11:28 AM Alex Lynch <lynch.alex at gmail.com> wrote:

> I have a Python GStreamer application that uses appsrc to record mp4
> files.
>
> The issue is that despite specifying tune=zerolatency 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.
>
> 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.
>
> Here is the x264enc pipeline:
>
> 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
>
> When the application is finished, it sends end-of-stream messages to the
> appsrc and pipeline:
>
> if self._appsrc.emit("end-of-stream") == Gst.FlowReturn.OK:
>     self._sink_pipeline.send_event(Gst.Event.new_eos())
>
> 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 appsrc are written to
> the output video file.
>

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.

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).

-aps
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20190820/6d1e0fa5/attachment.html>


More information about the gstreamer-devel mailing list