Trying to get GStreamer to work on the TX2, but caps cannot be negotiated

I have a simple program where I am trying to get video out of the camera and run it through a omxh264enc. The element linking is shown below:

gst_element_link (source, cFilter0);
  gst_element_link (cFilter0, encoder);
  gst_element_link (encoder, cFilter1); 
  gst_element_link (cFilter1, autovs);

However I get the errors as shown below:

Framerate set to : 30 at NvxVideoEncoderSetParameter0:00:00.609624260  3087       0x683850 ERROR             omxh264enc gstomxh264enc.c:280:gst_omx_h264_enc_set_format:<264encoder> Empty caps
0:00:00.609644260  3087       0x683850 ERROR            omxvideoenc gstomxvideoenc.c:1815:gst_omx_video_enc_set_format:<264encoder> Subclass failed to set the new format
0:00:00.609656996  3087       0x683850 WARN            videoencoder gstvideoencoder.c:623:gst_video_encoder_setcaps:<264encoder> rejected caps video/x-raw(memory:NVMM), width=(int)640, height=(int)480, format=(string)I420, framerate=(fraction)30/1
0:00:00.609696708  3087       0x683850 INFO                 basesrc gstbasesrc.c:2843:gst_base_src_loop:<camerasrc> marking pending DISCONT
0:00:00.609804004  3087       0x683850 FIXME           videoencoder gstvideoencoder.c:606:gst_video_encoder_setcaps:<264encoder> GstVideoEncoder::reset() is deprecated
Framerate set to : 30 at NvxVideoEncoderSetParameter0:00:00.609876579  3087       0x683850 ERROR             omxh264enc gstomxh264enc.c:280:gst_omx_h264_enc_set_format:<264encoder> Empty caps
0:00:00.609890819  3087       0x683850 ERROR            omxvideoenc gstomxvideoenc.c:1815:gst_omx_video_enc_set_format:<264encoder> Subclass failed to set the new format
0:00:00.609903779  3087       0x683850 WARN            videoencoder gstvideoencoder.c:623:gst_video_encoder_setcaps:<264encoder> rejected caps video/x-raw(memory:NVMM), width=(int)640, height=(int)480, format=(string)I420, framerate=(fraction)30/1
0:00:00.609955843  3087       0x683850 WARN                 basesrc gstbasesrc.c:2948:gst_base_src_loop:<camerasrc> error: Internal data flow error.
0:00:00.609971683  3087       0x683850 WARN                 basesrc gstbasesrc.c:2948:gst_base_src_loop:<camerasrc> error: streaming task paused, reason not-negotiated (-4)
0:00:00.610001219  3087       0x683850 INFO        GST_ERROR_SYSTEM gstelement.c:1879:gst_element_message_full:<camerasrc> posting message: Internal data flow error.
0:00:00.610046498  3087       0x683850 INFO        GST_ERROR_SYSTEM gstelement.c:1902:gst_element_message_full:<camerasrc> posted error message: Internal data flow error.
0:00:00.610141602  3087       0x683850 FIXME           videoencoder gstvideoencoder.c:606:gst_video_encoder_setcaps:<264encoder> GstVideoEncoder::reset() is deprecated
0:00:00.610159906  3087       0x683850 ERROR                    omx gstomx.c:256:gst_omx_component_handle_messages:<264encoder> encoder port 0 was not flushing
0:00:00.610175682  3087       0x683850 ERROR                    omx gstomx.c:256:gst_omx_component_handle_messages:<264encoder> encoder port 1 was not flushing
Framerate set to : 30 at NvxVideoEncoderSetParameter0:00:00.610238113  3087       0x683850 ERROR             omxh264enc gstomxh264enc.c:280:gst_omx_h264_enc_set_format:<264encoder> Empty caps
0:00:00.610250977  3087       0x683850 ERROR            omxvideoenc gstomxvideoenc.c:1815:gst_omx_video_enc_set_format:<264encoder> Subclass failed to set the new format
0:00:00.610262593  3087       0x683850 WARN            videoencoder gstvideoencoder.c:623:gst_video_encoder_setcaps:<264encoder> rejected caps video/x-raw(memory:NVMM), width=(int)640, height=(int)480, format=(string)I420, framerate=(fraction)30/1
0:00:00.610340385  3087       0x683850 FIXME           videoencoder gstvideoencoder.c:606:gst_video_encoder_setcaps:<264encoder> GstVideoEncoder::reset() is deprecated
0:00:00.610353953  3087       0x683850 ERROR                    omx gstomx.c:256:gst_omx_component_handle_messages:<264encoder> encoder port 0 was not flushing
0:00:00.610367521  3087       0x683850 ERROR                    omx gstomx.c:256:gst_omx_component_handle_messages:<264encoder> encoder port 1 was not flushing
Framerate set to : 30 at NvxVideoEncoderSetParameter0:00:00.610422529  3087       0x683850 ERROR             omxh264enc gstomxh264enc.c:280:gst_omx_h264_enc_set_format:<264encoder> Empty caps
0:00:00.610434753  3087       0x683850 ERROR            omxvideoenc gstomxvideoenc.c:1815:gst_omx_video_enc_set_format:<264encoder> Subclass failed to set the new format
0:00:00.610447360  3087       0x683850 WARN            videoencoder gstvideoencoder.c:623:gst_video_encoder_setcaps:<264encoder> rejected caps video/x-raw(memory:NVMM), width=(int)640, height=(int)480, format=(string)I420, framerate=(fraction)30/1
0:00:00.610519680  3087       0x683850 INFO              GST_STATES gstbin.c:3238:bin_handle_async_done:<avs> committing state from READY to PAUSED, old pending PAUSED
0:00:00.610551008  3087       0x683850 INFO              GST_STATES gstbin.c:3258:bin_handle_async_done:<avs> completed state change, pending VOID
0:00:00.610564192  3087       0x683850 INFO              GST_STATES gstelement.c:2277:_priv_gst_element_state_changed:<avs> notifying about state-changed READY to PAUSED (VOID_PENDING pending)
0:00:00.610609216  3087       0x683ed0 INFO                    task gsttask.c:318:gst_task_func:<264encoder:src> Task resume from paused
0:00:00.610625792  3087       0x683ed0 ERROR                    omx gstomx.c:256:gst_omx_component_handle_messages:<264encoder> encoder port 0 was not flushing
0:00:00.610641536  3087       0x683ed0 ERROR                    omx gstomx.c:256:gst_omx_component_handle_messages:<264encoder> encoder port 1 was not flushing

After extensively observing the caps, and using gst-inspect-1.0, it looks like the caps between the source and the encoder should be accepted, especially since I have set up a caps filter too. However, this isn’t happening, and I have no idea as to why this is the case.

Here is another user’s sample for your reference:
https://devtalk.nvidia.com/default/topic/1024356/jetson-tx2/solved-harware-accelerated-video-encoding-from-c-buffer-with-gstreamer-omxh264enc-and-filesink/post/5211704/#5211704