[ERROR:[email protected]] global cap_ffmpeg_impl.hpp:3076 open Could not open codec libopenh264, error: Unspecified error (-22)
[ERROR:[email protected]] global cap_ffmpeg_impl.hpp:3093 open VIDEOIO/FFMPEG: Failed to initialize VideoWriter
下载openh264的dll动态库文件,跟你的执行文件放在同一个路径下,这样就可以顺利保存为h264编码格式的视频了。
下载地址
== 没有实现了,不知道为啥总是不行 ==
import imageio.v2 as iio
import cv2
videoWriter = iio.get_writer('./record_video/out'+str(time.time())+'.mp4', format='ffmpeg',mode='I',fps=25,codec='libx264',pixelformat='yuv420p') # 对于 不能用cv2保存 h264视频的解决方式
while True:
ret,frame = cap.read()
if frame is None:
break
frame = cv2.resize(frame,(635,1080))
img_copy = frame.copy()
videoWriter.append_data(img_copy)
cv2.imshow('demo',img_copy)
if cv2.waitKey(10) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()