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:
python read_save_video_with_compression.py
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 = video_file.read()

    if ret == None or ret == False:
        break

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

    key = cv2.waitKey(1)

    output.write(frame)

    if (key & 0xFF) == 27:
        break

cv2.destroyAllWindows()
video_file.release()
output.release()

Thanks

Please follow https://developer.download.nvidia.com/embedded/L4T/r32_Release_v1.0/Docs/Accelerated_GStreamer_User_Guide.pdf?dMezayzOeP2D-4pUbKKK9kVZiEhovzmrcZEVJ25GIL9kfE059_2judBfVv2biBEsOXh-IpUcpj7N1DYwO2gM4m8rJXo8cWlMhjsKHjmd7zIfOA-oDIDE44FT4pfhAU-0T66soZUBc6bNGyD3PGdsKeHU_0GMWb92aTcQefkmhjWdTuFrX6s

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

e.g.
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

Hi,
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: