I am new to GStreamer and trying to create a simple example where I am getting video from the webcam and saving it using filesink. I have added a watch on bus to get EOS event but it never gets executed. Could somebody tell me what am I doing wrong here and how can I stop pipeline and get EOS Event working?
import gi import time
gi.require_version('Gst', '1.0') gi.require_version('Gtk', '3.0')
from gi.repository import GObject, Gst, Gtk import signal
Gst.init(None)
class Main: def init(self): signal.signal(signal.SIGINT, self.keyboardInterruptHandler)
self._pipeline = Gst.parse_launch("avfvideosrc name=avfvideosrc ! x264enc ! queue ! mp4mux ! filesink name=filesink location=output.mp4")
bus = self._pipeline.get_bus()
bus.add_signal_watch()
bus.connect("message::eos", self._on_eos_from_sink_pipeline)
self._pipeline.set_state(Gst.State.PLAYING)
def _on_eos_from_sink_pipeline(self, _bus, _message):
print("Got EOS from sink pipeline")
def keyboardInterruptHandler(self,signal, frame):
print("KeyboardInterrupt (ID: {}) has been caught. Cleaning up...".format(signal))
self.stopFetching()
time.sleep(5)
exit()
def stopFetching(self):
print("AT THE START OF STOP FETCHING")
self._pipeline.set_state(Gst.State.NULL)
self._pipeline.send_event(Gst.Event.new_eos())
print("AT THE END OF STOP FETCHING")
start = Main() Gtk.main()