This is the code I use to create video writer:
write_pipe = (
'appsrc'
+ ' ! video/x-raw, format=BGR'
+ ' ! queue'
+ ' ! videoconvert'
+ ' ! video/x-raw,format=BGRx'
+ ' ! nvvidconv'
+ ' ! nvv4l2h264enc bitrate=14000000'
+ ' ! h264parse'
+ ' ! qtmux'
+ f' ! filesink location={path}'
)
return cv2.VideoWriter(
write_pipe,
cv2.CAP_GSTREAMER,
fourcc=0,
fps=fps,
frameSize=resolution,
)
As you can see it uses BGR format which is wrong, because the numpy arrays I have contain data represented as RGB. So the resulting video has blue and red channels swapped. I tried modifying the definition to be:
write_pipe = (
'appsrc'
+ ' ! video/x-raw, format=RGB'
+ ' ! queue'
+ ' ! videoconvert'
+ ' ! video/x-raw,format=RGBA'
+ ' ! nvvidconv'
+ ' ! nvv4l2h264enc bitrate=14000000'
+ ' ! h264parse'
+ ' ! qtmux'
+ f' ! filesink location={path}'
)
but this does not work and I get error:
[ WARN:0@2.973] global /mnt/system/opencv/opencv-4.6.0/modules/videoio/src/cap_gstreamer.cpp (2293) writeFrame OpenCV | GStreamer warning: Error pushing buffer to GStreamer pipeline
How to solve this?