Hello.
I would like to run a l4t-ml docker container on a Jetson TX2 (Jetpack 4.5.1) and save video files from a CSI camera.
Information about the development environment is below.
development environment
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.6 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.6 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
$ cat /etc/nv_tegra_release
# R32 (release), REVISION: 5.1, GCID: 26202423, BOARD: t186ref, EABI: aarch64, DATE: Fri Feb 19 16:50:29 UTC 2021
$ v4l2-ctl -d /dev/video0 --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: 'BG10'
Name : 10-bit Bayer BGBG/GRGR
Size: Discrete 2592x1944
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 2592x1458
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 1280x720
Interval: Discrete 0.008s (120.000 fps)
$ docker -v
Docker version 20.10.21, build 20.10.21-0ubuntu1~18.04.3
I wrote the following python code(captest_csi.py) and ran it on the docker container.
captest_csi.py
# example
# 1280x960 5fps, output file's name 1280_960_5.mp4, record 5sec
# python3 captest_csi.py 1280 960 5 video 1280_960_5.mp4
import cv2
import sys
if __name__ == '__main__':
args = sys.argv
width = args[1]
height = args[2]
fps = args[3]
cap = cv2.VideoCapture(f'nvarguscamerasrc sensor-id=0\
! video/x-raw(memory:NVMM), width={width}, height={height}, format=(string)NV12, framerate=(fraction){fps}/1 \
! nvvidconv ! video/x-raw, width=(int){width}, height=(int){height}, format=(string)BGRx \
! videoconvert \
! appsink', cv2.CAP_GSTREAMER)
if cap.isOpened() is False:
raise IOError("open failed")
if args[4]=='video':
fps = int(cap.get(cv2.CAP_PROP_FPS))
w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
print(str(fps) + "," + str(w) + "," + str(h))
fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
if len(args) == 6:
filename = args[5]
else:
filename = "output.mp4"
out = cv2.VideoWriter(filename, fourcc, fps, (w, h))
fn = 0
while fn<(fps*5):
ret, frame = cap.read()
if ret:
out.write(frame)
else:
raise IOError("read failed")
fn = fn+1
cap.release()
out.release()
elif args[4]=='img':
if len(args) == 6:
filename = args[5]
else:
filename = "output.jpg"
ret, frame = cap.read()
if ret:
cv2.imwrite(filename, frame)
else:
raise IOError("read failed")
cap.release()
else:
print("argument invalid")
exit()
$ docker run --runtime nvidia -it --rm -v $PWD:/capture_test/ -v /tmp/argus_socket:/tmp/argus_socket --privileged --name captest nvcr.io/nvidia/l4t-ml:r32.5.0-py3
allow 10 sec for JupyterLab to start @ http://localhost:8888 (password nvidia)
JupterLab logging location: /var/log/jupyter.log (inside the container)
root@73ea4fe3f6f0:/# cd capture_test/
root@73ea4fe3f6f0:/capture_test# python3 captest_csi.py 1280 960 5 video 1280_960_5.mp4
root@73ea4fe3f6f0:/capture_test# python3 captest_csi.py 640 480 30 video 640_480_30.mp4
root@73ea4fe3f6f0:/capture_test# python3 captest_csi.py 1280 960 30 video 1280_960_30.mp4
At this time, if the resolution and frame rate are too high, a segmentation fault will occur. For example, 1280x960 5fps and 640x480 30fps can output video normally, but 1280x960 30fps causes segmentation fault.
The following is the execution log.
log
root@73ea4fe3f6f0:/capture_test# python3 captest_csi.py 1280 960 5 video 1280_960_5.mp4
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 2592 x 1944 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 16.000000; Exposure Range min 34000, max 550385000;
GST_ARGUS: 2592 x 1458 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 16.000000; Exposure Range min 34000, max 550385000;
GST_ARGUS: 1280 x 720 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 16.000000; Exposure Range min 22000, max 358733000;
GST_ARGUS: Running with following settings:
Camera index = 0
Camera mode = 1
Output Stream W = 2592 H = 1458
seconds to Run = 0
Frame Rate = 29.999999
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (933) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
5,1280,960
GST_ARGUS: Cleaning up
CONSUMER: Done Success
GST_ARGUS: Done Success
root@73ea4fe3f6f0:/capture_test# python3 captest_csi.py 640 480 30 video 640_480_30.mp4
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 2592 x 1944 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 16.000000; Exposure Range min 34000, max 550385000;
GST_ARGUS: 2592 x 1458 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 16.000000; Exposure Range min 34000, max 550385000;
GST_ARGUS: 1280 x 720 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 16.000000; Exposure Range min 22000, max 358733000;
GST_ARGUS: Running with following settings:
Camera index = 0
Camera mode = 2
Output Stream W = 1280 H = 720
seconds to Run = 0
Frame Rate = 120.000005
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (933) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
30,640,480
GST_ARGUS: Cleaning up
CONSUMER: Done Success
GST_ARGUS: Done Success
root@73ea4fe3f6f0:/capture_test# python3 captest_csi.py 1280 960 30 video 1280_960_30.mp4
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 2592 x 1944 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 16.000000; Exposure Range min 34000, max 550385000;
GST_ARGUS: 2592 x 1458 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 16.000000; Exposure Range min 34000, max 550385000;
GST_ARGUS: 1280 x 720 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 16.000000; Exposure Range min 22000, max 358733000;
GST_ARGUS: Running with following settings:
Camera index = 0
Camera mode = 1
Output Stream W = 2592 H = 1458
seconds to Run = 0
Frame Rate = 29.999999
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (933) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
30,1280,960
GST_ARGUS: Cleaning up
Segmentation fault (core dumped)
The 1280x960 30fps setting also outputs an image.
log
root@73ea4fe3f6f0:/capture_test# python3 captest_csi.py 1280 960 30 img 1280_960_30.jpg
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 2592 x 1944 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 16.000000; Exposure Range min 34000, max 550385000;
GST_ARGUS: 2592 x 1458 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 16.000000; Exposure Range min 34000, max 550385000;
GST_ARGUS: 1280 x 720 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 16.000000; Exposure Range min 22000, max 358733000;
GST_ARGUS: Running with following settings:
Camera index = 0
Camera mode = 1
Output Stream W = 2592 H = 1458
seconds to Run = 0
Frame Rate = 29.999999
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (933) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
GST_ARGUS: Cleaning up
CONSUMER: Done Success
GST_ARGUS: Done Success
I checked with a print statement and found that the segmentation fault occurred in “cap.release()”.
How can I output a video file at 1280x960 30fps? Please advise.