cant play video file [closed]

asked 2016-11-12 00:31:53 -0600

aliyesami gravatar image

updated 2016-11-12 00:58:22 -0600

I can display an image file fine after setting the DISPLAY variable but when I try to run the following video code from the opencv site , I get nothing , no video window is opened ? the demo I am following is :

http://opencv-python-tutroals.readthe...

please see the code and the output below :

[root@hadoop1 basic-motion-detection]# more demo1.py
import numpy as np
import cv2

cap = cv2.VideoCapture('/home/admin/example_02.mp4')

print cap.get(5) #to display frame rate of video
#print cap.get(cv2.cv.CV_CAP_PROP_FPS)

while(cap.isOpened()):
    ret, frame = cap.read()

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) #convert to grayscale

    cv2.imshow('frame',gray)
    waitKey(50)
    if cv2.waitKey(25) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()
[root@hadoop1 basic-motion-detection]# python demo1.py
0.0
[root@hadoop1 basic-motion-detection]#

I modified the above code and added the creation of window (as its used in the display image example) , but to no use.

[root@hadoop1 basic-motion-detection]# more demo1.py
import numpy as np
import cv2

cap = cv2.VideoCapture('/home/admin/example_02.mp4')

while(cap.isOpened()):
    ret, frame = cap.read()

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.startWindowThread()
    cv2.namedWindow("preview")
    cv2.imshow('preview',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by aliyesami
close date 2016-11-19 19:05:57.292351

Comments

make sure to have opencv_ffmpeg310.so on the path

berak gravatar imageberak ( 2016-11-13 02:24:20 -0600 )edit