OpenCV 3.3 - gstreamer and libva error
Hello, I am trying to use H264 codec using the following initialization for VideoWriter:
VideoWriter writer = VideoWriter("file.mp4", CV_FOURCC('H', '2', '6', '4'), 15, Size(300, 500));
and I run into the following exception:
(myProg:20371): GStreamer-CRITICAL **: gst_element_make_from_uri: assertion 'gst_uri_is_valid (uri)' failed
OpenCV Error: Unspecified error (GStreamer: cannot link elements
) in CvVideoWriter_GStreamer::open, file /path/to/opencv/sources/opencv-3.3/modules/videoio/src/cap_gstreamer.cpp, line 1626
VIDEOIO(cvCreateVideoWriter_GStreamer (filename, fourcc, fps, frameSize, is_color)): raised OpenCV exception:
/path/to/opencv/sources/opencv-3.3/modules/videoio/src/cap_gstreamer.cpp:1626: error: (-2) GStreamer: cannot link elements
in function CvVideoWriter_GStreamer::open
The video file is neither created.
The command line I use to compile OpenCV libraries is the following:
cmake -D CMAKE_TOOLCHAIN_FILE=../platforms/linux/gnu.toolchain.cmake \
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules/ \
-D CMAKE_INSTALL_PREFIX=${OPENCV_DIR} \
-D WITH_JPEG=OFF \
../ && make -j 8
As I understand after googling a while, it could be an error related to the filename, but I cannot understand what's really wrong with my code..
EDIT The gstream error seems to be corrected with the following VideoWriter initialization:
VideoWriter writer = VideoWriter("appsrc ! autovideoconvert ! v4l2video1h264enc extra-controls=\"encode,h264_level=10,h264_profile=4,frame_level_rate_control_enable=1,video_bitrate=2000000\" ! h264parse ! rtph264pay config-interval=1 pt=96 ! filesink location=file.mp4", CV_FOURCC('H', '2', '6', '4'), 15, Size(300, 500));
but now I fall into libva error:
error: XDG_RUNTIME_DIR not set in the environment.
libva info: VA-API version 0.36.0
libva info: va_getDriverName() returns -1
libva error: va_getDriverName() failed with unknown libva error,driver_name=(null)
What is the correct way to initialize VideoWriter object for H264 ?
Looks like you are trying to run X-app on a machine without X-server. And there is no actual VAAPI driver installed (try to run
vainfo
).Hello, actually
vainfo
returns the same error. Looking for vaapi drivers, I can see as these are installed.Did you try to run same gstreamer pipeline using the command line?
No. Sorry but actually I am noob with gstreamer & I don't know how to execute it (complete cmd syntax). What is the cmd I have to try ?
Command line tool is
gst-launch
: https://gstreamer.freedesktop.org/doc... I'm not a gstreamer expert too, but probably you need to change source bin fromappsrc
to something else. And looks like your libva installation is not complete, otherwisevainfo
would show correct information.Why don't you try FFMPEG?
Do you mean to try FFMPEG as an external program ? I tried and it generates the video, but I don't have enough space to store some GB of images to make a video of a bunch of MB. This is not the best solution. Perhaps using libav directly from the code leads to better results..
No I mean using libav/ffmpeg backend in OpenCV. VideoWriter will use it to encode the video if you compile OpenCV with proper development libraries.
Good to know it. I am recompiling it. Do you know if I have to use a pipeline as gstreamer ?