add mp4 file sample

This commit is contained in:
danil_e71
2021-07-22 10:46:08 +03:00
parent 8d800fbbcd
commit 20a759756e
6 changed files with 60 additions and 3 deletions

43
example/file/main.go Normal file
View File

@@ -0,0 +1,43 @@
package main
import (
"net/http"
"github.com/Danile71/go-logger"
"github.com/Danile71/go-rtsp"
"github.com/gorilla/mux"
"github.com/mattn/go-mjpeg"
)
const uri = "./sample.mp4"
func main() {
s := mjpeg.NewStream()
stream, err := rtsp.Open(uri)
if logger.OnError(err) {
return
}
go func() {
for {
pkt, err := stream.ReadPacket()
if logger.OnError(err) {
continue
}
if pkt.IsVideo() {
s.Update(pkt.Data())
}
}
}()
streamHandler := func(w http.ResponseWriter, r *http.Request) {
s.ServeHTTP(w, r)
}
router := mux.NewRouter()
router.HandleFunc("/stream", streamHandler)
http.Handle("/", router)
http.ListenAndServe(":8181", nil)
}