如何在GStreamer流水线中检测funnel插件的其中一个源已结束?
解决方案
- 通过pad探针监听filesrc的EOS事件
最直接的实现方式是给filesrc的src pad挂载下行事件探针,捕获到EOS事件时即为文件读取完成。C语言实现示例如下:// 给filesrc的src pad添加事件探针 GstPad *filesrc_src = gst_element_get_static_pad(filesrc_elem, "src"); gst_pad_add_probe(filesrc_src, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, filesrc_eos_handler, NULL, NULL); gst_object_unref(filesrc_src); // 探针回调函数 static GstPadProbeReturn filesrc_eos_handler(GstPad *pad, GstPadProbeInfo *info, gpointer data) { if (GST_EVENT_TYPE(gst_pad_probe_info_get_event(info)) == GST_EVENT_EOS) { g_print("filesrc已读取到文件末尾\n"); // 此处可执行自定义逻辑,比如主动给appsrc发送EOS让流水线正常退出 GstElement *appsrc = gst_bin_get_by_name(GST_BIN(pipeline), "appsrc-h264-sei"); gst_app_src_end_of_stream(GST_APP_SRC(appsrc)); gst_object_unref(appsrc); } return GST_PAD_PROBE_OK; } - 借助identity元素简化监听逻辑
不想直接操作pad探针的话,可以在filesrc的输出链路插入identity元素,监听它的eos信号即可,修改后的流水线结构如下:
代码中绑定gst-launch-1.0 funnel name=f \ appsrc name=appsrc-h264-sei do-timestamp=true block=true is-live=true ! video/x-h264, stream-format=byte-stream, alignment=au ! queue ! f. \ filesrc location=input.h264 ! identity name=filesrc_monitor ! queue ! f. \ f. ! queue ! h264parse ! video/x-h264, stream-format=byte-stream, alignment=au ! mp4mux ! filesink location=file.mp4filesrc_monitor的eos信号,触发时就代表filesrc已经读完所有数据。
你当前流水线卡住是
funnel的默认逻辑:它要求所有输入sink pad都收到EOS后,才会向下游发送EOS。你的appsrc配置了is-live=true,默认不会主动生成EOS,所以funnel会一直等待,appsrc也会持续触发need-data信号。拿到filesrc的EOS通知后主动给appsrc发送EOS,就能让整个流水线正常终止。
内容的提问来源于stack exchange,提问作者Da Tong
相关产品推荐
相关产品推荐

