Recorded with Gstreamer videos compression question on Jetson Xavier NX

Hey guys

I am recording videos on Jetson NX in 1280x720 50fps h265. I am doing some postprocessing on the video using OpenCV (4.4.0 Python Contrib) and trying to save in the same format, compression and so on but the produced video’s size is always way way bigger than the original one. Original 20 mins video’s size is about 500MB that becomes about 3GB. Factor x6 is too big. Do you know what pipeline, configuration should be to reduce the size of the post processed files ?

For recording I am using following code (there’s 2 cameras but I gave previously an example with only 1 video file):

gst-launch-1.0 multiqueue max-size-buffers=1 name=mqueue nvarguscamerasrc sensor-id=1 ! 'video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)NV12, framerate=(fraction)50/1' ! mqueue.sink_1 nvarguscamerasrc sensor-id=0 ! 'video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)NV12, framerate=(fraction)50/1' ! mqueue.sink_2 mqueue.src_1 ! nvvidconv flip-method=3 ! omxh265enc ! qtmux ! filesink location =" + str(save_dir_R) + " mqueue.src_2 ! nvvidconv flip-method=1 ! omxh265enc ! qtmux ! filesink location=" + str(save_dir_L) + " -e"

The easiest OpenCV code to just read and save video is here:

import cv2

video_extension = ".mp4"

video_filename = "original.h265"

video_file = cv2.VideoCapture(video_filename)

When we are using X264:
fourcc = cv2.VideoWriter_fourcc(*'X264')

Getting following error:
OpenCV: FFMPEG: tag 0x34363258/'X264' is not supported with codec id 27 and format 'mp4 / MP4 (MPEG-4 Part 14)'
OpenCV: FFMPEG: fallback to use tag 0x31637661/'avc1'

        OpenH264 Video Codec provided by Cisco Systems, Inc.
# fourcc = cv2.VideoWriter_fourcc(*'X264') # even worse, for 500MB produces 6.5GB
fourcc = cv2.VideoWriter_fourcc(*'avc1')
output = cv2.VideoWriter(video_filename + "_post" + video_extension, fourcc, 50, (720, 1280))

while video_file.isOpened():

    ret, frame =

    if ret == None or ret == False:

    cv2.imshow(winname=video_filename, mat=frame)

    key = cv2.waitKey(1)


    if (key & 0xFF) == 27:



Please follow

To configure encoded video bitrate and control-rate CBR/VBR

gst-launch-1.0 nvarguscamerasrc !
‘video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080,
format=(string)NV12, framerate=(fraction)30/1’ ! nvv4l2h265enc
bitrate=8000000 ! h265parse ! qtmux ! filesink
location=<filename_h265.mp4> -e

1 Like

Please try eenav’s suggestion to set bitrate in gst-launch-1.0 command. If your source runs in steady frame rate, the bitrate should be close to the setting.

Looks like it uses software codec in the OpenCV code. For using hardware encoding/decoding, you can refer to this sample: