gobot.io/x/gobot@v1.16.0/examples/tello_video.go (about) 1 // +build example 2 // 3 // Do not build by default. 4 5 /* 6 You must have MPlayer (https://mplayerhq.hu) installed in order to run this code. it will connect to the Tello 7 and then open a window using MPlayer showing the streaming video. 8 9 How to run 10 11 go run examples/tello_video.go 12 */ 13 14 package main 15 16 import ( 17 "fmt" 18 "os/exec" 19 "time" 20 21 "gobot.io/x/gobot" 22 "gobot.io/x/gobot/platforms/dji/tello" 23 ) 24 25 func main() { 26 drone := tello.NewDriver("8890") 27 28 mplayer := exec.Command("mplayer", "-fps", "60", "-") 29 mplayerIn, _ := mplayer.StdinPipe() 30 if err := mplayer.Start(); err != nil { 31 fmt.Println(err) 32 return 33 } 34 35 work := func() { 36 drone.On(tello.ConnectedEvent, func(data interface{}) { 37 fmt.Println("Connected") 38 drone.StartVideo() 39 drone.SetVideoEncoderRate(tello.VideoBitRateAuto) 40 gobot.Every(100*time.Millisecond, func() { 41 drone.StartVideo() 42 }) 43 }) 44 45 drone.On(tello.VideoFrameEvent, func(data interface{}) { 46 pkt := data.([]byte) 47 if _, err := mplayerIn.Write(pkt); err != nil { 48 fmt.Println(err) 49 } 50 }) 51 } 52 53 robot := gobot.NewRobot("tello", 54 []gobot.Connection{}, 55 []gobot.Device{drone}, 56 work, 57 ) 58 59 robot.Start() 60 }