首页 > 解决方案 > 可以在 javafx 内的 web 视图中播放 multipart/x-mixed-replace 流吗?

问题描述

我正在使用 Flask 服务器将视频从网络摄像头流式传输到 Java 客户端这是 Flask 实现:

def generate():
    # grab global references to the output frame and lock variables
    global outputFrame, lock

    # loop over frames from the output stream
    while True:
        # wait until the lock is acquired
        with lock:
            # check if the output frame is available, otherwise skip
            # the iteration of the loop
            if outputFrame is None:
                continue

            # encode the frame in JPEG format
            (flag, encodedImage) = cv2.imencode(".jpg", outputFrame)

            # ensure the frame was successfully encoded
            if not flag:
                continue

        # yield the output frame in the byte format
        yield(b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' + 
            bytearray(encodedImage) + b'\r\n')

@app.route("/video_feed")
def video_feed():
    # return the response generated along with the specific media
    # type (mime type)
    return Response(generate(),
        mimetype = "multipart/x-mixed-replace; boundary=frame")

我有一个 javafx webview 屏幕,但它没有显示任何内容。是因为 Webview 不支持 multipart/x-mixed-replace 吗?这有什么解决办法?有没有其他选择可以将 python 视频流放到 JavaFX 应用程序上?

标签: flaskjavafxvideo-streamingjavafx-webview

解决方案


推荐阅读