我想保存运动JPEG (MJPG)格式的摄像机输出。下面的代码,
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
if (cap.isOpened() == False):
print("Unable to read camera feed")
frame_width = int(cap.get(3))
frame_height = int(cap.get(4))
frame_per_sec = int('10')
out = cv2.VideoWriter('output.mjpeg',cv2.VideoWriter_fourcc('M','J','P','G'), (frame_per_sec), (frame_width,frame_height))
while(True):
ret, frame = cap.read()
if ret == True:
# Write the frame into the file 'output.mjpeg'
out.write(frame)
# Display the resulting frame
cv2.imshow('frame',frame)
# Press Q on keyboard to stop recording
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()当它运行时,我将得到以下错误:
[ WARN:0] OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
OpenCV: FFMPEG: tag 0x67706a6d/'mjpg' is not supported with codec id 7 and format 'mjpeg / raw MJPEG video'我能做什么来解决这些问题?我试过改变情况(“M”、“J”、“P”、“G”到“m”、“j”、“p”、“g”),但没有成功。感谢有关解决上述问题以及GStreamer问题的任何建议。提前谢谢。
发布于 2022-11-23 22:14:51
.mjpeg不是任何已知容器格式的有效后缀。
我相信您并不打算在没有容器的情况下编写一个原始的MJPG流。这是非常很少有用的,并需要专家知识。
你有两个选择:
.avi容器中使用MJPG,因为这是内置在OpenCV中的,甚至不需要ffmpeg .mpg容器)、.mov或.mkv或其他任何G 210
https://stackoverflow.com/questions/74553092
复制相似问题