我想使用在 Python web 浏览器客户端下开发的这个客户端,所以我想将 python 代码转换为 Javascript/HTML 代码并访问网络摄像头以将实时视频从 web 浏览器流式传输到服务器端......并思考你这么多 在此代码中,客户端正在向服务器发送视频
# In this code client is sending video to server
import socket,cv2, pickle,struct
import pyshine as ps # pip install pyshine
import imutils # pip install imutils
camera = False
if camera == True:
vid = cv2.VideoCapture(0)
else:
vid = cv2.VideoCapture('videos/b.mp4')
client_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host_ip = '192.168.164.91' # Here according to your server ip write the address
port = 5000
client_socket.connect((host_ip,port))
if client_socket:
while (vid.isOpened()):
try:
img, frame = vid.read()
frame = imutils.resize(frame,width=380)
a = pickle.dumps(frame)
message = struct.pack("Q",len(a))+a
client_socket.sendall(message)
cv2.imshow(f"TO: {host_ip}",frame)
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
client_socket.close()
except:
print('VIDEO FINISHED!')
break
我认为这是不可能的,但你可以尝试学习 django,它是 python web 开发的最佳框架