OpenCV can't capture video recording from camera

In short, what we have: Phytec 8M Mini , gcc8.3, opencv 4.5.0. The following code is written to save video from the camera to a file, but it gives an error that it cannot capture the camera (“Can’t open the camera”). What can be changed or added?

I assume that OPENCV is the case, as I execute the gst-launch-1.0 v4l2src device=/dev/video0 command on the board! video/x-bayer,format=grbg,depth=8,width=1920,height=1080 ! bayer2rgbneon ! videoconvert ! jpegenc ! multifilesink location=live.avi and a video stream is created, everything works!

#include <opencv2/opencv.hpp>
#include <iostream>
#include <iostream>
using namespace std;

int main(int ac, char** av) {


	string gst_cmd = "v4l2src device=/dev/video0 ! video/x-bayer,format=grbg,depth=8,width=1920,height=1080 ! bayer2rgbneon ! videoconvert ! jpegenc ! multifilesink location=live.avi";
	cv::VideoCapture cap(gst_cmd,cv::CAP_V4L2);
	

	if (!cap.isOpened())
	{
		std::cout << "Can't open the camera" << std::endl;
		return -1;
	}

	cv::Mat img;

	cout << "Started video..."<<endl;
	while (cap.isOpened())
	{
		try
		{


			cap >> img;
			cvtColor(img,img,cv::COLOR_BayerGB2BGR);
			if (img.empty())
			{
				std::cout << "empty image" << std::endl;
				return 0;
			}

			cv::imshow("camera img", img);

			if (cv::waitKey(25) == 27)
				break;
		}
		catch( cv::Exception& e )
		{
			const char* err_msg = e.what();
			std::cout << "exception caught: " << err_msg << std::endl;
		}
	}

	return 0;
}

use CAP_GSTREAMER for pipelines like that, V4L is used for usb webcams (only)

check build logs or: cout << getBuildInformation(); to see, if what you built supports it !
(again, you have to build the opencv libs with gstreamer dev libs installed)

My logs :

General configuration for OpenCV 4.5.2 =====================================
  Version control:               lf-5.10.72-2.2.0-dirty

  Extra modules:
    Location (extra):            /workdir/contrib/modules
    Version control (extra):     4.5.2-dirty

  Platform:
    Timestamp:                   2021-04-12T02:26:40Z
    Host:                        Linux 5.13.0-51-generic x86_64
    Target:                      Linux aarch64
    CMake:                       3.19.5
    CMake generator:             Ninja
    CMake build tool:            ninja
    Configuration:               Release

  CPU/HW features:
    Baseline:                    NEON FP16
      required:                  NEON
      disabled:                  VFPV3

  C/C++:
    Built as dynamic libs?:      YES
    C++ standard:                11
    C++ Compiler:                /workdir/recipe-sysroot-native/usr/bin/aarch64-phytec-linux/aarch64-phytec-linux-g++  (ver 10.2.0)
    C++ flags (Release):         -mcpu=cortex-a53 -march=armv8-a+crc+crypto -I/workdir/git/include  -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security  --sysroot=/workdir/recipe-sysroot  -O2 -pipe -g -feliminate-unused-debug-types -fmacro-prefix-map=/workdir=/usr/src/debug/opencv/4.5.2.imx-r0                      -fdebug-prefix-map=/workdir=/usr/src/debug/opencv/4.5.2.imx-r0                      -fdebug-prefix-map=/workdir/recipe-sysroot=                      -fdebug-prefix-map=/workdir/recipe-sysroot-native=  -fvisibility-inlines-hidden  -mcpu=cortex-a53 -march=armv8-a+crc+crypto -I/workdir/git/include  -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security  --sysroot=/workdir/recipe-sysroot   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -mcpu=cortex-a53 -march=armv8-a+crc+crypto -I/workdir/git/include  -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security  --sysroot=/workdir/recipe-sysroot  -O2 -pipe -g -feliminate-unused-debug-types -fmacro-prefix-map=/workdir=/usr/src/debug/opencv/4.5.2.imx-r0                      -fdebug-prefix-map=/workdir=/usr/src/debug/opencv/4.5.2.imx-r0                      -fdebug-prefix-map=/workdir/recipe-sysroot=                      -fdebug-prefix-map=/workdir/recipe-sysroot-native=  -fvisibility-inlines-hidden  -mcpu=cortex-a53 -march=armv8-a+crc+crypto -I/workdir/git/include  -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security  --sysroot=/workdir/recipe-sysroot   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -g  -DDEBUG -D_DEBUG
    C Compiler:                  /workdir/recipe-sysroot-native/usr/bin/aarch64-phytec-linux/aarch64-phytec-linux-gcc
    C flags (Release):           -mcpu=cortex-a53 -march=armv8-a+crc+crypto -I/workdir/git/include  -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security  --sysroot=/workdir/recipe-sysroot  -O2 -pipe -g -feliminate-unused-debug-types -fmacro-prefix-map=/workdir=/usr/src/debug/opencv/4.5.2.imx-r0                      -fdebug-prefix-map=/workdir=/usr/src/debug/opencv/4.5.2.imx-r0                      -fdebug-prefix-map=/workdir/recipe-sysroot=                      -fdebug-prefix-map=/workdir/recipe-sysroot-native=   -mcpu=cortex-a53 -march=armv8-a+crc+crypto -I/workdir/git/include  -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security  --sysroot=/workdir/recipe-sysroot   -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -DNDEBUG  -DNDEBUG
    C flags (Debug):             -mcpu=cortex-a53 -march=armv8-a+crc+crypto -I/workdir/git/include  -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security  --sysroot=/workdir/recipe-sysroot  -O2 -pipe -g -feliminate-unused-debug-types -fmacro-prefix-map=/workdir=/usr/src/debug/opencv/4.5.2.imx-r0                      -fdebug-prefix-map=/workdir=/usr/src/debug/opencv/4.5.2.imx-r0                      -fdebug-prefix-map=/workdir/recipe-sysroot=                      -fdebug-prefix-map=/workdir/recipe-sysroot-native=   -mcpu=cortex-a53 -march=armv8-a+crc+crypto -I/workdir/git/include  -fstack-protector-strong  -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security  --sysroot=/workdir/recipe-sysroot   -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -g  -DDEBUG -D_DEBUG
    Linker flags (Release):      -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-z,relro,-z,now  -Wl,--gc-sections -Wl,--as-needed  
    Linker flags (Debug):        -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-z,relro,-z,now  -Wl,--gc-sections -Wl,--as-needed  
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:          dl m pthread rt
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    freetype world
    Disabled by dependency:      -
    Unavailable:                 alphamat cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv hdf java julia matlab ovis python2 sfm viz
    Applications:                perf_tests examples apps
    Documentation:               NO
    Non-free algorithms:         NO

  GUI: 
    GTK+:                        YES (ver 3.24.25)
      GThread :                  YES (ver 2.66.7)
      GtkGlExt:                  NO

  Media I/O: 
    ZLib:                        /workdir/recipe-sysroot/usr/lib/libz.so (ver 1.2.11)
    JPEG:                        /workdir/recipe-sysroot/usr/lib/libjpeg.so (ver 62)
    WEBP:                        /workdir/recipe-sysroot/usr/lib/libwebp.so (ver encoder: 0x020f)
    PNG:                         /workdir/recipe-sysroot/usr/lib/libpng.so (ver 1.6.37)
    TIFF:                        /workdir/recipe-sysroot/usr/lib/libtiff.so (ver 42 / 4.2.0)
    JPEG 2000:                   build (ver 2.4.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    GStreamer:                   YES (1.18.5)
    v4l/v4l2:                    YES (linux/videodev2.h)
    gPhoto2:                     YES

  Parallel framework:            TBB (ver 2021.2 interface 12020)

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Lapack:                      NO
    Custom HAL:                  YES (carotene (ver 0.0.1))
    Protobuf:                    /workdir/recipe-sysroot/usr/lib/libprotobuf.so (3.15.2)

  Python 3:
    Interpreter:                 /workdir/recipe-sysroot-native/usr/bin/python3-native/python3 (ver 3.9.5)
    Libraries:                   /workdir/recipe-sysroot/usr/lib/libpython3.9.so (ver 3.9.5)
    numpy:                       /workdir/recipe-sysroot/usr/lib/python3.9/site-packages/numpy/core/include (ver undefined - cannot be probed because of the cross-compilation)
    install path:                lib/python3.9/site-packages/cv2/python-3.9

  Python (for build):            /workdir/recipe-sysroot-native/usr/bin/python3-native/python3

  Install to:                    /usr
-----------------------------------------------------------------

4.5.2 – IF you already go through all this trouble, why use a 2 yrs old codebase ?