I’m trying to save a video with OpenCV
with this code
import cv2
cap = cv2.VideoCapture('v4l2src device=/dev/video0 io-mode=2 ! image/jpeg, width=(int)1920, height=(int)1080, framerate=30/1 ! nvv4l2decoder mjpeg=1 ! nvvidconv ! video/x-raw,format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink', cv2.CAP_GSTREAMER)
file_name = "abc.avi"
fourcc = cv2.VideoWriter_fourcc(*'MPEG')
width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
fps = cap.get(cv2.CAP_PROP_FPS)
print("fourcc:{} fps:{}@width:{}@height:{}".format(fourcc, fps, width, height))
out = cv2.VideoWriter(file_name, fourcc, fps, (int(width), int(height)))
vounter = 0
while True:
if counter > 100:
break
counter +=1
_, frame = cap.read()
# cv2.imshow('frame', frame)
out.write(frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
I had problems with camera input, but found the Pipeline above and it looks it works nice, when I cv2.imshow()
, but when I’m trying to save the images with videowriter frames are going down…
This is time a time the counter
reach 100 with cv2.imshow()
Opening in BLOCKING MODE
NvMMLiteOpen : Block : BlockType = 277
NVMEDIA: Reading vendor.tegra.display-size : status: 6
NvMMLiteBlockCreate : Block : BlockType = 277
[ WARN:0] global /home/suomi/opencv/modules/videoio/src/cap_gstreamer.cpp (961) open OpenCV | GStreamer warning: Cannot query video position: status=1, value=6, duration=-1
fourcc:1195724877 fps:30.0@width:1920.0@height:1088.0
real 0m6.926s
user 0m3.564s
sys 0m1.248s
And this is how it looks like when I’m using out.write(frame)
.
Opening in BLOCKING MODE
NvMMLiteOpen : Block : BlockType = 277
NVMEDIA: Reading vendor.tegra.display-size : status: 6
NvMMLiteBlockCreate : Block : BlockType = 277
[ WARN:0] global /home/suomi/opencv/modules/videoio/src/cap_gstreamer.cpp (961) open OpenCV | GStreamer warning: Cannot query video position: status=1, value=0, duration=-1
fourcc:1195724877 fps:30.0@width:1920.0@height:1088.0
real 0m27.947s
user 0m26.756s
sys 0m1.360s
till 100 it takes 27 sec, despite the saved video has 4 sec and is real fast…
What is happening here?