Gstreamer使用筆記

關閉程式前發送EOS事件給pipeline的方法

1
2
3
4
5
6
7
// 發送EOS訊號讓filesink可以正常結束
gst_element_send_event(appCtx[i]->pipeline.pipeline, gst_event_new_eos());
msg = gst_bus_timed_pop_filtered(GST_ELEMENT_BUS (appCtx[i]->pipeline.pipeline),
GST_CLOCK_TIME_NONE,
(GstMessageType) (GST_MESSAGE_ERROR | GST_MESSAGE_EOS));//gst_bus_timed_pop_filtered 是synchronously取得訊號,如果沒有訊號會一直等待並把執行續卡住
gst_element_set_state (appCtx[i]->pipeline.pipeline, GST_STATE_NULL);
g_main_loop_quit (main_loop);

https://gstreamer.freedesktop.org/documentation/gstreamer/gstelement.html#gst_element_get_state

https://gstreamer-devel.narkive.com/g1omJFAj/gst-devel-graceful-exit-shutdown-of-a-pipeline#post3

https://stackoverflow.com/questions/38170733/gstreamer-not-flushing-to-the-filesink

範例

https://gitlab.freedesktop.org/freedesktop/snippets/-/snippets/1760

https://gist.github.com/CaptainOnly/f88cbb6ac5fdeae80200fbb3f7be695c

Ubuntu新增ssh使用者

打開ssh登錄日誌

1
nano /etc/ssh/sshd_config

用systemd製作服務

可以用symble link的方式,將服務檔放到/etc/systemd/system/目錄下,讓systemd管理服務。

更改service檔後,需執行以下指令,讓systemd重新載入設定檔:

1
2
3
sudo systemctl daemon-reload
sudo systemctl enable appname
sudo systemctl start appname

移除服務:

1
2
3
4
5
6
7
systemctl stop [servicename]
systemctl disable [servicename]
rm /your/service/locations/[servicename]
# and symlinks that might be related
rm /your/service/locations/[servicename]
systemctl daemon-reload
systemctl reset-failed

查看服務整的log

1
journalctl -u appname

參考:
製作fastapi服務
設定檔重載
symbolic link
移除服務

Python執行tensorrt-engine

載入Region_TRT plugin

必須要載入libnvinfer_plugin,可以用python的trt.init_libnvinfer_plugins載入,

1
2
TRT_LOGGER = trt.Logger(trt.Logger.ERROR)
trt.init_libnvinfer_plugins(TRT_LOGGER,"")

https://docs.nvidia.com/deeplearning/tensorrt/api/python_api/infer/Plugin/IPluginRegistry.html#tensorrt.init_libnvinfer_plugins

印出目前已經載入的plugin

PLUGIN_CREATORS = trt.get_plugin_registry().plugin_creator_list
for plugin_creator in PLUGIN_CREATORS:
print(plugin_creator.name)

參考並修改:https://developer.nvidia.com/zh-cn/blog/tensorrt-custom-layer-cn/

tensorrt Region layer 說明書

https://docs.nvidia.com/deeplearning/tensorrt/api/c_api/structnvinfer1_1_1plugin_1_1_region_parameters.html#ad2c6bba4f07221add9b6d9abf0a4e312

inference範例參考:
https://leimao.github.io/blog/TensorRT-Python-Inference/