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()
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
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()
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.
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.