duanniesui6391 2017-07-28 14:56
浏览 621

使用golang服务器接收ffmpeg实时流媒体,并回显到websocket conn

I'm writing a server in go and need to get a cam video in a ffmpeg client and passes the streaming to websocket users.

But in my code, the http body received from the ffmpeg client is loaded by a ioutil.ReadAll and cannot make a live broadcast because the body is receiving new values with the video capture. How i can take the last frame of the video, send to the websockets, clean the variable and receive the new frame correctly (or i'm doing in the wrong way)?

Here is my code to this function:

//StartClientStream needs a email$clientName$streamName
func StartClientStream(w http.ResponseWriter, r *http.Request) {

    values := strings.Split(string(mux.Vars(r)["rest"]), "$")

    if len(values) != 3 {
        w.Write([]byte(`{"err":"the passed value does not match with necessary fields"}`))
        return
    }
    //Get user ID
    id, _ := getID(values[0])
    //Take the streaming ClientName
    clientName := id + " - " + values[1]
    //Take the passed Body
    body, _ := ioutil.ReadAll(r.Body)
    //Watch for websockets requests for this video
    for user := range Streaming.User[clientName] {
        conexoes := strings.Split(Streaming.User[clientName][user], "-")
        for c := range conexoes {
            if strings.EqualFold(conexoes[c], values[2]) {
                //Send the video
                user.send <- body
            }
        }
    }

}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 vue3加ant-design-vue无法渲染出页面
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 路易威登官网 里边的参数逆向
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
    • ¥50 需求一个up主付费课程
    • ¥20 模型在y分布之外的数据上预测能力不好如何解决
    • ¥15 processing提取音乐节奏
    • ¥15 gg加速器加速游戏时,提示不是x86架构
    • ¥15 python按要求编写程序