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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!