Jetson Tx2 nvargus camera not recording usin LI-TX1-CB

Dear community,

I am using a jetson TX2 together with the LI-TX1-CB carrier that brings three MIPI cooax cameras.
I could succesfully run all the camera to open. But I need to record a video and when I set the fps to 30 the recorded video is too fast, if I set the fps to 15 the recorded video is normal but when I measure with a cronometer the duration of the video it must be 44 but the video is only 36.
My code is below, I am not user if I need to do some other configuration on the jetson.
Thank you so much in advance.

import cv2

# Specify the camera ID to use
camera_id = 1

# Create VideoCapture object for the selected camera
capture_object = cv2.VideoCapture(f'nvarguscamerasrc sensor-id={camera_id} ! '
                                   f'video/x-raw(memory:NVMM), width=1280, height=720 ! '
                                   f'nvvidconv flip-method=0 ! '
                                   f'video/x-raw, format=BGRx ! '
                                   f'videoconvert ! appsink')

# Define output video file name
output_file = f'camera{camera_id}.mp4'

# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'H264')
fps = 15.0
video_writer = cv2.VideoWriter(output_file, fourcc, fps, (1280, 720))
video_writer.set(cv2.CAP_PROP_FPS, fps)
# Main loop to capture frames from the camera and record video
while True:
    ret, frame = capture_object.read()  # Capture frame
    
    if not ret:  # Check if frame capture failed
        print("Error: Frame capture failed")
        break

    # Display the frame
    cv2.imshow(f'Camera {camera_id}', frame)

    # Write frame to video file
    video_writer.write(frame)

    # Press 'q' to exit the loop
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# Release VideoCapture object and VideoWriter object
capture_object.release()
video_writer.release()

# Close all OpenCV windows
cv2.destroyAllWindows()

hello alberto18_90,

let’s give it a try to examine sensor frame-rate with below gst pipeline.
it’s disable camera preview, and shows frame-rate only.
please also update those width/height/fps sensor capability settings accordingly.
for example,
$ gst-launch-1.0 nvarguscamerasrc sensor-id=0 ! 'video/x-raw(memory:NVMM),width=1920, height=1080, framerate=30/1, format=NV12' ! nvvidconv ! 'video/x-raw(memory:NVMM),format=I420' ! fpsdisplaysink text-overlay=0 video-sink=fakesink sync=0 -v

Thnak you @JerryChang Here is the output of the gst pipeline:

/GstPipeline:pipeline0/GstFPSDisplaySink:fpsdisplaysink0: last-message = rendered: 378, dropped: 0, current: 29.62, average: 29.76 /GstPipeline:pipeline0/GstFPSDisplaySink:fpsdisplaysink0: last-message = rendered: 393, dropped: 0, current: 29.75, average: 29.76 /GstPipeline:pipeline0/GstFPSDisplaySink:fpsdisplaysink0: last-message = rendered: 408, dropped: 0, current: 29.60, average: 29.75 /GstPipeline:pipeline0/GstFPSDisplaySink:fpsdisplaysink0: last-message = rendered: 423, dropped: 0, current: 29.75, average: 29.75 /GstPipeline:pipeline0/GstFPSDisplaySink:fpsdisplaysink0: last-message = rendered: 438, dropped: 0, current: 29.67, average: 29.75 /GstPipeline:pipeline0/GstFPSDisplaySink:fpsdisplaysink0: last-message = rendered: 453, dropped: 0, current: 29.43, average: 29.74 /GstPipeline:pipeline0/GstFPSDisplaySink:fpsdisplaysink0: last-message = rendered: 468, dropped: 0, current: 29.93, average: 29.75 /GstPipeline:pipeline0/GstFPSDisplaySink:fpsdisplaysink0: last-message = rendered: 483, dropped: 0, current: 29.62, average: 29.74 /GstPipeline:pipeline0/GstFPSDisplaySink:fpsdisplaysink0: last-message = rendered: 498, dropped: 0, current: 29.73, average: 29.74 /GstPipeline:pipeline0/GstFPSDisplaySink:fpsdisplaysink0: last-message = rendered: 513, dropped: 0, current: 29.66, average: 29.74 /GstPipeline:pipeline0/GstFPSDisplaySink:fpsdisplaysink0: last-message = rendered: 528, dropped: 0, current: 29.52, average: 29.73 /GstPipeline:pipeline0/GstFPSDisplaySink:fpsdisplaysink0: last-message = rendered: 543, dropped: 0, current: 29.73, average: 29.73

hello alberto18_90,

it looks frame-rate is outputting at 29-fps consistently. (I would not say 30 since its average is 29.7-fps)
so, what did you meant video is too fast, please double check you’re given correct encode parameter settings.

BTW,
here’s another pipeline to setup preview stream and also video recording.
$ gst-launch-1.0 -e nvarguscamerasrc num-buffers=300 ! 'video/x-raw(memory:NVMM), width=2952, height=1944, format=NV12, framerate=30/1' ! tee name=streams streams. ! queue ! nvv4l2h265enc bitrate=8000000 ! h265parse ! qtmux ! filesink location=video0.mp4 streams. ! queue ! nvoverlaysink -e

@JerryChang Thank you for your reply.
When running the code below, it is supposed to record a video. I recorded a video showing a chronometer, and the chronometer displays 50 seconds, but the video is only 11 seconds in total. Shouldn’t it be around 50 seconds, or at least similar?

import cv2

# Specify the camera ID to use
camera_id = 1

# Create VideoCapture object for the selected camera
capture_object = cv2.VideoCapture(f'nvarguscamerasrc sensor-id={camera_id} ! '
                                   f'video/x-raw(memory:NVMM), width=1280, height=720 ! '
                                   f'nvvidconv flip-method=0 ! '
                                   f'video/x-raw, format=BGRx ! '
                                   f'videoconvert ! appsink')

# Define output video file name
output_file = f'camera{camera_id}.mp4'

# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'H264')
fps = 30.0
video_writer = cv2.VideoWriter(output_file, fourcc, fps, (1280, 720))
video_writer.set(cv2.CAP_PROP_FPS, fps)
# Main loop to capture frames from the camera and record video
while True:
    ret, frame = capture_object.read()  # Capture frame
    
    if not ret:  # Check if frame capture failed
        print("Error: Frame capture failed")
        break

    # Display the frame
    cv2.imshow(f'Camera {camera_id}', frame)

    # Write frame to video file
    video_writer.write(frame)

    # Press 'q' to exit the loop
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# Release VideoCapture object and VideoWriter object
capture_object.release()
video_writer.release()

# Close all OpenCV windows
cv2.destroyAllWindows()

hello alberto18_90,

what’s all your sensor modes, please check $ v4l2-ctl -d /dev/video0 --list-formats-ext
besides, can you reproduce the same with the sample gst pipeline provide above?

@JerryChang ,
I run the pipeline you gave me above on the terminal and it run and record a video pretty good.
I am trying to adapt it to a python code because I need to run 3 cameras that are connected to the jetson tx2, and I need to do some operation with the frames.

$ v4l2-ctl -d /dev/video0 --list-formats-ext

v4l2-ctl is not installed. I will try to install it.

you may running below for installation, $ sudo apt-get install v4l-utils

i after running v4l2-ctl -d /dev/video0 --list-formats-ext I got:

diego@diego-jetsontx2:~/Documents$ v4l2-ctl -d /dev/video0 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
	Index       : 0
	Type        : Video Capture
	Pixel Format: 'RG10'
	Name        : 10-bit Bayer RGRG/GBGB
		Size: Discrete 3840x2160
			Interval: Discrete 0.017s (60.000 fps)
		Size: Discrete 1920x1080
			Interval: Discrete 0.017s (60.000 fps)
		Size: Discrete 3856x4448
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1936x2264
			Interval: Discrete 0.017s (60.000 fps)

hello alberto18_90,

according to sensor format dumps, please revise your app to use the sensor supported formats.

Thank you for your reply.
I am sorry but I am not sure how to write or modify my code to use the supported format.

hello alberto18_90,

according to below, you’ve confirm the sensor basic functionality.

so, the problem is from the app side.
first of all, please try updating the width/height property settings as same as sensor capability.
i.e. width=1920, height=1080 and fps = 60.0.