phoboslab / jsmpeg

MPEG1 Video Decoder in JavaScript
MIT License
6.31k stars 1.43k forks source link

Uncaught RuntimeError: memory access out of bounds #351

Open entrehuihui opened 4 years ago

entrehuihui commented 4 years ago

I keep getting errors when I run : Uncaught RuntimeError: memory access out of bounds, I tried to adjust the ffmpeg command and still can't solve it。I hope everyone can help,thank you very much。

my ffmpeg:

ffmpeg -f dshow -i video="Integrated Webcam" -f mpegts -codec:v mpeg1video -s 960x540 -b:v 300k -r 30 -bf 0 -codec:a mp2 -ar 44100 -ac 1 -b:a 64k "http://127.0.0.1:9200/ffmpeg"

my server:

func main() { g := gin.New() g.Use(Cors())

g.StaticFile("/html/jsmpeg.min.js", "jsmpeg.min.js") ///html/flv.js
g.StaticFile("/html/index", "index.html")
g.POST("/ffmpeg", ffmpeg)
g.GET("/ws", WebsocketListen)

g.Run(":9200")

}

func ffmpeg(c gin.Context) { bufreader := bufio.NewReader(c.Request.Body) buf := make([]byte, 189, 189) count, err := io.ReadFull(bufreader, buf) // 189 -1 = 188 if judgeErrorCountFalse(c, err, count-1, buf[188]) { return } if buf[0] != 0x47 { c.JSON(http.StatusInternalServerError, "not TL steam") return } for { chanTS <- buf[:188] count, err = io.ReadFull(bufreader, buf[1:]) if judgeErrorCountFalse(c, err, count, buf[188]) { return } time.Sleep(1 time.Millisecond) continue } }

func judgeErrorCountFalse(c *gin.Context, err error, count int, by byte) bool { if err != nil { fmt.Println(err) if err == io.EOF { c.JSON(http.StatusOK, nil) } else { c.JSON(http.StatusInternalServerError, err) } return true } if count != 188 { fmt.Println("count", count) c.JSON(http.StatusInternalServerError, "read error") return true } if by != 0x47 { // fmt.Println("0x47", by) c.JSON(http.StatusInternalServerError, "not TL steam") return true } return false }

// WebsocketListen .. func WebsocketListen(c *gin.Context) { // CHECK AUTH HEADER HERE Upgrade := c.GetHeader("Upgrade") Origin := c.GetHeader("Origin") if Upgrade == "" || Origin == "" { c.JSON(http.StatusInternalServerError, 7) return } handler := websocket.Handler(echo) handler.ServeHTTP(c.Writer, c.Request) }

// echo .. func echo(ws websocket.Conn) { fmt.Println("websocker online") defer fmt.Println("websocker close") buf := make([]byte, 188, 188) for { buf = <-chanTS err := websocket.Message.Send(ws, buf) if err != nil { log.Println(err, "---------") return } fmt.Println(buf[0:10]) // time.Sleep(100 time.Millisecond) } }

my clien html:

<!DOCTYPE html>

1
asdasfjaf