The opencv works fine when doing other things. It can open images and show images. But it can't open a video.
The code I'm using to open a video is as below
import cv2
cap = cv2.VideoCapture("MOV_0006.mp4")
while True:
ret, frame = cap.read()
cv2.imshow('video', frame)
if cv2.waitKey(1) & 0xff == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
But when executing, it outputs error messages like below
[h264 @ 0x1053ba0] AVC: nal size 554779904
[h264 @ 0x1053ba0] AVC: nal size 554779904
[h264 @ 0x1053ba0] no frame!
My vlc
and mplayer
can play this video, but the opencv can't.
I have installed x264
and libx264-142
codec package. (using sudo apt-get install
)
My version of ubuntu is 14.04 trusty
.
I'm not sure is it a codec problem or not?
I have rebuilt opencv either with WITH_UNICAP=ON
or with WITH_UNICAP=OFF
, but it doesn't affect the problem at all. The error messages never change.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…