'How to run a Python script (which records video) by clicking an HTML button

Below is a Python script intended to record video. I would like to have the code below run when I click a button on an HTML page. What code/methods could I use to make this possible?

import cv2
import numpy as np
from cv2 import VideoWriter
from cv2 import VideoWriter_fourcc

# open the webcam video stream
webcam = cv2.VideoCapture(0)
fourcc=cv2.VideoWriter_fourcc(*'mpv4')
out= cv2.VideoWriter('VideoRecord.mp4',fourcc,20.0,(640,480))

while (webcam.isOpened()):
    ret, frame=webcam.read()
    if(ret==True):
        out.write(frame)
        cv2.imshow('output',frame)
        if(cv2.waitKey(1)==ord('q')):
            break
    else:
        break

webcam.release()
cv2.destroyAllWindows


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source