Hi,
So it looks like if you execute kill -SIGINT, it does not send EoS to exit gst-launch-1.0 command gracefully. Maybe you can try to implement like:
GStreamer freeze when using qtmux and NVIDIA-accelerated h264/h265 encoding - #7 by DaneLLL
In the sample there is g_usleep(30usec)*. May replace it with infinite wait and wait for SIGINT signal. Once the signal is issued, send EoS, wait for EoS, switch to NULL state, and unref the pipeline.