opencv_recode1.py 723 B

12345678910111213141516171819202122232425262728293031
  1. import cv2
  2. cap = cv2.VideoCapture('rtsp://192.168.50.181/av0_0')
  3. # 設定擷取影像的尺寸大小
  4. cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
  5. cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 360)
  6. # 使用 XVID 編碼
  7. fourcc = cv2.VideoWriter_fourcc(*'XVID')
  8. # 建立 VideoWriter 物件,輸出影片至 output.avi
  9. # FPS 值為 20.0,解析度為 640x360
  10. out = cv2.VideoWriter('output123.avi', fourcc, 20.0, (640, 360))
  11. while(cap.isOpened()):
  12. ret, frame = cap.read()
  13. if ret == True:
  14. # 寫入影格
  15. out.write(frame)
  16. cv2.imshow('frame',frame)
  17. if cv2.waitKey(1) & 0xFF == ord('q'):
  18. break
  19. else:
  20. break
  21. # 釋放所有資源
  22. cap.release()
  23. out.release()
  24. cv2.destroyAllWindows()