Casa > H > How To Play A Video By Python Programming

How to play a video by Python programming

A2A.

You can play videos in any environment using python’s OpenCV library.

This is a great library for image processing.

For playing video in the web-browser you will need django or flask with openCV integration.

Check out these links if interested:

The Web framework for perfectionists with deadlines

Flask (A Python Microframework)

Welcome to Pyramid, a Python Web Framework(for smaller apps)

But if you just wanna play video from your local PC, that’s a 10-liner(provided openCV is installed, you can install it using pip : pip install opencv-python)

here is the sample code.

  1. import cv2 
  2. import numpy as np 
  3.  
  4. cap = cv2.VideoCapture('Your_video.mp4') 
  5. ''' 
  6. Make sure your_video is in the same dir, else mention the full path. 
  7. ''' 
  8. while True: 
  9. ret, frame = cap.read() 
  10. gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) 
  11. cv2.imshow('frame',frame) 
  12. cv2.imshow('grayF',gray) 
  13. if cv2.waitKey(1) & 0xFF == ord('q'): 
  14. break 
  15.  
  16. cap.release() 
  17. cv2.destroyAllWindows() 

De Dymoke

Porque seria estranho ter a sua cara no ecrã do seu telefone? :: Onde posso obter jogos defensivos como construir torres para parar onda após onda de inimigos?