Hi,
For generating a valid mp4, you would need to send EoS signal. For C programming, you may refer to the sample:
GStreamer freeze when using qtmux and NVIDIA-accelerated h264/h265 encoding - #7 by DaneLLL
In gst-launch-1.0 command, please set -e
gst-launch-1.0(1) — gstreamer1.0-tools — Debian unstable — Debian Manpages