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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Alex Lynch

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.

Thanks,
Alex.


_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

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

pisymbol .


On Tue, Aug 20, 2019 at 11:28 AM Alex Lynch <[hidden email]> 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

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

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

Vinod Kesti
In reply to this post by Alex Lynch
Alex Lynch

Event to flow through all the way till sink and sink fill finally post it on
the bus. You can wait for EOS message on the bus.





--
Sent from: http://gstreamer-devel.966125.n4.nabble.com/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel