def debug_pipeline_to_file(self, path): """Saves pipeline graph in .dot file.""" with open(path, "w") as f: f.write( Gst.debug_bin_to_dot_data(self.pipeline, Gst.DebugGraphDetails.ALL))
def draw_pipeline(pipe, filename): #Gst.debug_bin_to_dot_file(pipe, Gst.DebugGraphDetails.ALL, "pipeline-dot") # https://pygraphviz.github.io/documentation/pygraphviz-1.3rc1/reference/agraph.html import pygraphviz as pgv dot_data = Gst.debug_bin_to_dot_data(pipe, Gst.DebugGraphDetails.ALL) G = pgv.AGraph(dot_data) print("now let's print some graph: " + filename + ".png") file_path = '{name}.png'.format(grandparent=os.path.dirname( os.path.dirname(__file__)), name=filename) G.draw(file_path, format="png", prog="dot")
Gst.init() pipeline = Gst.parse_launch(f''' filesrc location=media/in.mp4 num-buffers=256 ! decodebin ! nvvideoconvert ! video/x-raw,format={frame_format} ! fakesink name=s ''') pipeline.get_by_name('s').get_static_pad('sink').add_probe( Gst.PadProbeType.BUFFER, on_frame_probe) pipeline.set_state(Gst.State.PLAYING) try: while True: msg = pipeline.get_bus().timed_pop_filtered( Gst.SECOND, Gst.MessageType.EOS | Gst.MessageType.ERROR) if msg: text = msg.get_structure().to_string() if msg.get_structure( ) else '' msg_type = Gst.message_type_get_name(msg.type) print(f'{msg.src.name}: [{msg_type}] {text}') break finally: finish_time = time.time() open(f'logs/{os.path.splitext(sys.argv[0])[0]}.pipeline.dot', 'w').write( Gst.debug_bin_to_dot_data(pipeline, Gst.DebugGraphDetails.ALL)) pipeline.set_state(Gst.State.NULL) print(f'FPS: {frames_processed / (finish_time - start_time):.2f}')