Root user can't open gstreamer

Hi All,

        setenv("DISPLAY", ":0", 1);  
        std::string pipeline = "nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080,format=(string)NV12, framerate=(fraction)30/1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert !  appsink";

        cv::VideoCapture cap(pipeline, cv::CAP_GSTREAMER);
        if (!cap.isOpened()) {
            std::cerr << "Can't open camera" << std::endl;
            return -1;
        }

There is no problem executing this code using a regular user, but executing it using the root user will result in an error.
Error:

GST_ARGUS: Creating output stream
No protocol specified
No protocol specified
No protocol specified
No protocol specified
(Argus) Error NotSupported: Failed to initialize EGLDisplay (in src/eglutils/EGLUtils.cpp, function getDefaultDisplay(), line 77)
(Argus) Error BadParameter:  (propagating from src/eglstream/FrameConsumerImpl.cpp, function initialize(), line 89)
(Argus) Error BadParameter:  (propagating from src/eglstream/FrameConsumerImpl.cpp, function create(), line 44)
Error generated. /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvarguscamera/gstnvarguscamerasrc.cpp, threadInitialize:315 Failed to create FrameConsumer
Error generated. /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvarguscamera/gstnvarguscamerasrc.cpp, threadFunction:236 (propagating)
Error generated. /dvs/git/dirty/git-master_linux/multimedia/nvgstreamer/gst-nvarguscamera/gstnvarguscamerasrc.cpp, execute:833 (propagating)
[ WARN:0] global /home/ubuntu/build_opencv/opencv/modules/videoio/src/cap_gstreamer.cpp (1100) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1

Device: Jetson Orin Nano 4G. JetPack 5.1.4.
I am using SSH remote because the program requires the background root user to execute.

Hi,
root user does not have permission to display. Please not set DISPLAY.

Hi DaneLLL,

I used OpenCV+Gstreamer to open the camera and encountered an issue. The stack trace results are as follows.

Thread 4 "box_algo" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xffffed0678f0 (LWP 4280)]
0x0000fffff66137e4 in __GI___realpath (name=<optimized out>, resolved=0xffffe402b920 "/proc/4271/exe") at canonicalize.c:166
166	canonicalize.c: No such file or directory.
(gdb) backtrace 
#0  0x0000fffff66137e4 in __GI___realpath (name=<optimized out>, resolved=0xffffe402b920 "/proc/4271/exe") at canonicalize.c:166
#1  0x0000ffffd4556e4c in  () at /usr/lib/aarch64-linux-gnu/tegra/libcuda.so.1
#2  0x0000ffffd455d844 in  () at /usr/lib/aarch64-linux-gnu/tegra/libcuda.so.1
#3  0x0000ffffd43c97dc in  () at /usr/lib/aarch64-linux-gnu/tegra/libcuda.so.1
#4  0x0000ffffdd602ae0 in  () at /usr/lib/aarch64-linux-gnu/tegra/libnvbufsurftransform.so.1.0.0
#5  0x0000fffff6d993b8 in __pthread_once_slow (once_control=0xffffde599ab8, init_routine=0xffffdd602a00) at pthread_once.c:116
#6  0x0000ffffdd647d94 in  () at /usr/lib/aarch64-linux-gnu/tegra/libnvbufsurftransform.so.1.0.0
#7  0x0000ffffdd5f91f8 in  () at /usr/lib/aarch64-linux-gnu/tegra/libnvbufsurftransform.so.1.0.0
#8  0x0000ffffdd61dc54 in  () at /usr/lib/aarch64-linux-gnu/tegra/libnvbufsurftransform.so.1.0.0
#9  0x0000ffffdd40d954 in  () at /usr/lib/aarch64-linux-gnu/tegra/libnvbufsurftransform.so.1.0.0
#10 0x0000fffff7fda8b4 in call_init (l=<optimized out>, argc=argc@entry=1, argv=argv@entry=0xfffffffff378, env=env@entry=0xfffffffff388) at dl-init.c:72
#11 0x0000fffff7fda9b4 in call_init (env=0xfffffffff388, argv=0xfffffffff378, argc=1, l=<optimized out>) at dl-init.c:30
#12 _dl_init (main_map=0xffffe4002f30, argc=1, argv=0xfffffffff378, env=0xfffffffff388) at dl-init.c:119
#13 0x0000fffff66dd20c in __GI__dl_catch_exception (exception=0x0, operate=0xfffff7fddcc8 <call_dl_init>, args=0xffffec86c9c0) at dl-error-skeleton.c:182
#14 0x0000fffff7fdea14 in dl_open_worker (a=a@entry=0xffffec86cc10) at dl-open.c:758
#15 0x0000fffff66dd1ac in __GI__dl_catch_exception (exception=0xffffec86cbf8, operate=0xfffff7fde540 <dl_open_worker>, args=0xffffec86cc10) at dl-error-skeleton.c:208
#16 0x0000fffff7fde1a4 in _dl_open
    (file=0xffffe4002e60 "/usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstnvarguscamerasrc.so", mode=-2147483646, caller_dlopen=0xfffff43de93c <g_module_open+748>, nsid=-2, argc=1, argv=0xfffffffff378, env=0xfffffffff388) at dl-open.c:837
#17 0x0000fffff6d7609c in dlopen_doit (a=a@entry=0xffffec86ced8) at dlopen.c:66
#18 0x0000fffff66dd1ac in __GI__dl_catch_exception (exception=exception@entry=0xffffec86ce50, operate=0xfffff6d76038 <dlopen_doit>, args=0xffffec86ced8) at dl-error-skeleton.c:208
#19 0x0000fffff66dd278 in __GI__dl_catch_error (objname=0xffffe4002ec0, errstring=0xffffe4002ec8, mallocedp=0xffffe4002eb8, operate=<optimized out>, args=<optimized out>) at dl-error-skeleton.c:227
#20 0x0000fffff6d76838 in _dlerror_run (operate=operate@entry=0xfffff6d76038 <dlopen_doit>, args=args@entry=0xffffec86ced8) at dlerror.c:170
#21 0x0000fffff6d76140 in __dlopen (file=<optimized out>, mode=<optimized out>) at dlopen.c:87
#22 0x0000fffff43de93c in g_module_open () at /lib/aarch64-linux-gnu/libgmodule-2.0.so.0
#23 0x0000fffff6c38660 in _priv_gst_plugin_load_file_for_registry (filename=0xffffe004c810 "/usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstnvarguscamerasrc.so", registry=0xffffe0009130 [GstRegistry|registry0], 
    registry@entry=0x0 [GstRegistry], error=error@entry=0xffffec86d1b0) at gstplugin.c:790
#24 0x0000fffff6c3906c in gst_plugin_load_file (filename=<optimized out>, error=error@entry=0xffffec86d1b0) at gstplugin.c:682
#25 0x0000fffff6c39510 in gst_plugin_load_by_name (name=0xffffe0047ea4 "nvarguscamerasrc") at gstplugin.c:1326
#26 0x0000fffff6c3a078 in gst_plugin_feature_load (feature=feature@entry=0xffffe0049520 [GstPluginFeature|nvarguscamerasrc]) at gstpluginfeature.c:112
#27 0x0000fffff6c0c354 in gst_element_factory_create (factory=factory@entry=0xffffe0049520 [GstElementFactory|nvarguscamerasrc], name=name@entry=0x0) at gstelementfactory.c:350
#28 0x0000fffff6c0c698 in gst_element_factory_make (factoryname=0xffffe4001950 "nvarguscamerasrc", name=name@entry=0x0) at gstelementfactory.c:447
#29 0x0000fffff6c8aca4 in priv_gst_parse_yyparse (scanner=<optimized out>, graph=graph@entry=0xffffec86e8f0) at ./grammar.y:813
#30 0x0000fffff6c8ba2c in priv_gst_parse_launch
    (str=str@entry=0xffffe4001230 "nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080,format=(string)NV12, framerate=(fraction)15/1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! appsink", error=error@entry=0xffffec86e960, ctx=ctx@entry=0x0, flags=flags@entry=GST_PARSE_FLAG_NONE) at ./grammar.y:1176
#31 0x0000fffff6c8253c in gst_parse_launch_full
    (pipeline_description=0xffffe4001230 "nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080,format=(string)NV12, framerate=(fraction)15/1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! appsink", context=0x0, flags=GST_PARSE_FLAG_NONE, error=0xffffec86ea20) at gstparse.c:339
#32 0x0000fffff7f6113c in cv::GStreamerCapture::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::VideoCaptureParameters const&) () at /lib/aarch64-linux-gnu/libopencv_videoio.so.4.5
#33 0x0000fffff7f63ae4 in cv::createGStreamerCapture_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::VideoCaptureParameters const&) () at /lib/aarch64-linux-gnu/libopencv_videoio.so.4.5
#34 0x0000fffff7f4e4bc in cv::StaticBackendWithParams::createCapture(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::VideoCaptureParameters const&) const ()
    at /lib/aarch64-linux-gnu/libopencv_videoio.so.4.5
#35 0x0000fffff7f30778 in cv::VideoCapture::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, std::vector<int, std::allocator<int> > const&) ()
    at /lib/aarch64-linux-gnu/libopencv_videoio.so.4.5
#36 0x0000fffff7f2e864 in cv::VideoCapture::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) () at /lib/aarch64-linux-gnu/libopencv_videoio.so.4.5
#37 0x0000aaaaaaaff648 in BoxDecoder::InitCapture(cv::VideoCapture&) (this=this@entry=0xffffff806378, capp=...) at box_decoder.cpp:1075
#38 0x0000aaaaaab05c08 in BoxDecoder::decoderThread() (this=0xffffff806378) at box_decoder.cpp:1113
#39 0x0000fffff68e1f9c in  () at /lib/aarch64-linux-gnu/libstdc++.so.6
#40 0x0000fffff6d90624 in start_thread (arg=0xfffff68e1f80) at pthread_create.c:477
#41 0x0000fffff66a462c in thread_start () at ../sysdeps/unix/sysv/linux/aarch64/clone.S:78

May I ask if there is any solution?

code:

bool BoxDecoder::InitCapture(cv::VideoCapture &capp)
{
    printf("InitCapture 001\n");  
    printf("InitCapture 002\n");
    std::string pipeline = "nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080,format=(string)NV12, framerate=(fraction)15/1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! appsink";
    
    printf("InitCapture 003\n");
    std::cout << "InitCapture 003: " << pipeline << std::endl;
    bool cap_ret = capp.open(pipeline, cv::CAP_GSTREAMER);
    // bool cap_ret = m_cap.open(pipeline, cv::CAP_GSTREAMER);
    
    printf("InitCapture 004\n");
    if (!cap_ret)
    {
        printf("Can't open video\n");
        return false;
    }
    return true;
}

Hi,
Does the OpenCV code work if you don’t run as root user?

Running with regular users.
Now I have increased the stack size of the process. There is approximately a 70% chance of error. Then it can run normally.

I am currently stuck using Gstreamer. Display is required to obtain it. Can we avoid using the DISPLAY environment. The camera image can be obtained normally.

Hi,
Please try the sample test.py:

import sys
import cv2

def read_cam():
    cap = cv2.VideoCapture("nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080,format=(string)NV12, framerate=(fraction)30/1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert !  appsink")
    if cap.isOpened():
        frameNum = 0
        while True:
            ret_val, img = cap.read();
            frameNum = frameNum + 1
            if frameNum == 150:
                print("received 150 frame")
                frameNum = 0
    else:
     print("camera open failed")

if __name__ == '__main__':
    read_cam()

$ python3 test.py

We can run it on Orin Nano developer kit with clean system. If you fail to run it in your setup, would suggest re-flash the device and try again.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.