Nvh264enc crashes with nvdec

Hi Folks nvdec and nvh264enc work when used separately. pls see examples below:
gst-launch-1.0 filesrc location=input.mp4 ! qtdemux ! h264parse ! nvdec ! glimagesink sync=false
gst-launch-1.0 videotestsrc num-buffers=10000 ! nvh264enc ! h264parse ! mp4mux ! filesink location=output.mp4

But I get error when I try to use them together:
gst-launch-1.0 filesrc location=input.mp4 ! qtdemux ! h264parse ! nvdec ! nvh264enc ! h264parse ! mp4mux ! filesink location=output.mp4
ERROR:gstnvbaseenc.c:1535:_map_gl_input_buffer: code should not be reached
Aborted (core dumped)

Do I miss something?