VideoWriter.write() very slow

Hi,

I’m using opencv in python on ubuntu to record a couple of IP cameras and save the video in a file but the issue I’m encountering is that the write method is very slow for 1080p 25fps, it can barely handle about 12 fps while looking at a white wall and if I film something with more movement it takes up to 0.15s for a single frame.
Is there a way to accelerate the encoding by using hardware acceleration?
Note: I’m running this on a Jetson Xavier.

def test():
	global threads_running
	global url

	capture = cv2.VideoCapture(url)

	fourcc = cv2.VideoWriter_fourcc(*"mp4v")
	fps = capture.get(cv2.CAP_PROP_FPS)
	width = capture.get(cv2.CAP_PROP_FRAME_WIDTH)
	height = capture.get(cv2.CAP_PROP_FRAME_HEIGHT)
	frameSize = (int(width), int(height))

	if threads_running:
		read = True
		writer = cv2.VideoWriter("test.mp4", fourcc, fps, frameSize)

		if writer.isOpened():
			while read and capture.isOpened() and threads_running:
				
				previousTime = time.time()
				read, frame = capture.read()
				frameTime = time.time() - previousTime
				print(f"read  | max fps: {int(1 / frameTime)} frame time: {frameTime}")

				previousTime = time.time()
				writer.write(frame)
				frameTime = time.time() - previousTime
				print(f"write | max fps: {int(1 / frameTime)} frame time: {frameTime}")

			writer.release()
		else:
			print("failed to open video writer")

		capture.release()