首页 > 解决方案 > fastest way to stream image over web-socket

问题描述

i'm trying to broadcast a image to any client that connect to websocket, the problem is : something the speed aren't enough to achieve 10FPS+

// img are from ~11ms process
png.Encode(&b, img)
// jpeg.Encode(&b, img, nil)

sEnc := base64.StdEncoding.EncodeToString(b.Bytes())
message := Message{
    Type:   "frame",
    Frame:  sEnc,
    Device: "pap99",
    Width:  320,
    Height: 240,
}

encoded, _ := json.Marshal(message)

err = c.WriteMessage(websocket.BinaryMessage, encoded)
if err != nil {
    log.Println("write:", err)
    return
}

the client :

conn.onmessage = function (evt) {
     var data = JSON.parse(evt.data);
     frame.src = `data:image/png;base64,${data["frame"]}`
}

is there any way to achieve 10FPS+ with current code ? thankyou

标签: websocketgorilla

解决方案


推荐阅读