Dynamically record video

intervideosink/intervideosrc are to be used in the same process such as:

gst-launch-1.0 -ev rtspsrc location=rtsp://XXXX ! rtph265depay ! h265parse ! avdec_h265 ! queue ! intervideosink channel=test      intervideosrc channel=test ! queue ! x264enc ! h264parse ! queue ! qtmux ! filesink location=record.mp4

If your use case is using 2 different processes, then you may use shmsink/shmsrc or better use RTP stream through local loopback interface.
Note that depending on your resolution, you may have to adjust max kernel socket buffer size and MTU, see this post for RTP/VRAW suggestions.