cv2.VideoWriter[Gstreamer + Opencv] using Hardware Encoder with python code

For 1.:
You would use a gstreamer pipeline in a cv2.VideoWriter, specifying cv2.CAP_GSTREAMER api:

... # assuming your gstreamer input defines caps for width, height and fps
cap = cv2.VideoCapture(gstream_elements, cv2.CAP_GSTREAMER)
if not cap.isOpened() :
    print("capture failed")
    exit()
w = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
h = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
fps = cap.get(cv2.CAP_PROP_FPS)
print('Src opened, %dx%d @ %d fps' % (w, h, fps))


gst_out = "appsrc ! video/x-raw, format=BGR ! queue ! nvvidconv ! omxh264enc ! h264parse ! qtmux ! filesink location=test.mov "
out= cv2.VideoWriter(gst_out, cv2.CAP_GSTREAMER, 0, float(fps), (int(w), int(h)))
if not out.isOpened():
    print("Failed to open output")
    exit()


while True:
    _, frame = cap.read()
    out.write(frame)
    cv2.waitKey(1)

For 2: use a gstreamer pipeline starting with filesrc (here displaying into X):

gst-launch-1.0 filesrc location=test.mov ! qtdemux ! video/x-h264 ! omxh264dec ! nvvidconv ! videoconvert ! xvimagesink