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:

Hi, i ran that example and it gave me the next error:

Failed to query video capabilities: Inappropriate ioctl for device
libv4l2: error getting capabilities: Inappropriate ioctl for device
[ WARN:0] global /home/jebi/jebios/tools/wiracocha/libraries/opencv/modules/videoio/src/cap_gstreamer.cpp (1759) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module nvv4l2h264enc0 reported: Error getting capabilities for device ‘/dev/nvhost-msenc’: It isn’t a v4l2 driver. Check if it is a v4l1 driver.
[ WARN:0] global /home/jebi/jebios/tools/wiracocha/libraries/opencv/modules/videoio/src/cap_gstreamer.cpp (1759) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module nvv4l2h264enc0 reported: Could not initialize supporting library.
[ WARN:0] global /home/jebi/jebios/tools/wiracocha/libraries/opencv/modules/videoio/src/cap_gstreamer.cpp (1592) open OpenCV | GStreamer warning: GStreamer: cannot put pipeline to play

I am working on Jetson AGX Xavier, Jetpack 4.4 DP, I compiled Opencv 4.3 with ffmpeg support, this is my script of compilation:

-DBUILD_opencv_python2=false -DBUILD_opencv_python3=true
Finally, it grabs video files with size 0. How could I resolve this issue?

Jetpack 4.4 DP(r32.4.2) is not a stable version. Suggest you move to JP4.4 GA(r32.4.3) or JP 4.4.1(r32.4.3).

You may try with default OpenCV 4.3 package to ensure it works, and then try the self-built one. We have verified it with the default package.